viernes, 28 de octubre de 2022

Ruido Blanco mejorado



Como no me gustaba del todo la otra versión (pues parece que lleva información en forma de patrones raros...) pues le he añadido cifrado en tiempo real con clave aleatoria :)

public byte TestByte(

        {

            Stopwatch watch = new Stopwatch();

            watch.Start();

            double nuevoRandom;

            byte[] rawrandom = new byte[255];

            hash = mySHA.ComputeHash(rawrandom);

            watch.Stop();

            nuevoRandom = watch.Elapsed.Ticks;

            nuevoRandom = Math.Round(nuevoRandom %255);

            return (byte)((nuevoRandom));

        }    

    //CIFRADO


        private byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV)

        {

            MemoryStream ms = new MemoryStream();

            Rijndael alg = Rijndael.Create();

            alg.Key = Key;

            alg.IV = IV;

            CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(), CryptoStreamMode.Write);

            cs.Write(clearData, 0, clearData.Length);

            cs.Close();

            byte[] encryptedData = ms.ToArray();

            return encryptedData;

        }

    

    public byte[] TestBytesArrayCifrado(int number,string clave)

        {

            char[] cadenabytes = new char[number];

            String operador = cadenabytes.ToString();

            foreach (byte bite in cadenabytes)

            {

                operador += (char)TestByte();

            }

            byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(operador);

            PasswordDeriveBytes pdb = new PasswordDeriveBytes(clave, new byte[] { 0x0, 0x1, 0x2, 0x1C, 0x1D, 0x1E, 0x3, 0x4, 0x5, 0xF, 0x20, 0x21, 0xAD, 0xAF, 0xA4 });

            byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(16), pdb.GetBytes(16));

            return encryptedData;

        })

Se usaría así en un timer con NAudio en C# en visual estudio.


 private void timer4_Tick(object sender, EventArgs e

        {

            bytes = psi.TestBytesArrayCifrado(10000, psi.TestByte().ToString());

            try

            {

                provider.AddSamples(bytes, 1, 10000);

            }

            catch

            {

                provider.ClearBuffer();

                provider.AddSamples(bytes, 1, 10000);

            }

        })

Voy a probarlo a ver que tal medito con esto.

si no os aclaráis igual leer también el otro artículo.

No hay comentarios:

Publicar un comentario