예제 #1
0
        public void RNG_Sequence_Ending_Numbers_Test()
        {
            var array1 = new int[10];
            var array2 = new int[10];

            using (var prng1 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Aes, ReseedEntropySourceGroup.Local))
            {
                for (int i = 0; i < 10; i++)
                {
                    int num = prng1.Next(1, 10);
                    array1[i] = num;
                }
            }

            using (var prng2 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Aes, ReseedEntropySourceGroup.Local))
            {
                for (int i = 0; i < 10; i++)
                {
                    int num = prng2.Next(1, 10);
                    array2[i] = num;
                }
            }

            Assert.AreNotEqual(array1[new Range(5, 10)], array2[new Range(5, 10)]);
        }
예제 #2
0
        private static void DrawImage(int width, int height, string path)
        {
            using (var prng = RNGVenturaProviderFactory.CreateSeeded())
            {
                int length = width * height;

                var data = new byte[length];
                prng.GetBytes(data);

                Color colour;
                int   temp = 0;

                using (Bitmap map = new Bitmap(width, height))
                {
                    for (int i = 0; i < map.Width; i++)
                    {
                        for (int j = 0; j < map.Height; j++)
                        {
                            int rn = data[temp];
                            colour = Color.FromArgb(rn, rn, rn);
                            map.SetPixel(i, j, colour);

                            temp++;
                        }
                    }

                    map.Save(path, ImageFormat.Png);
                }
            }
        }
예제 #3
0
        public void RNG_Sequence_Ending_Bytes_Test()
        {
            byte[] array1 = new byte[12];
            byte[] array2 = new byte[12];

            using var prng1 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Aes, ReseedEntropySourceGroup.Full);
            prng1.GetBytes(array1);

            foreach (var b in array1)
            {
                System.Diagnostics.Debug.Write(b + " ");
            }

            System.Diagnostics.Debug.WriteLine("");

            using var prng2 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Aes, ReseedEntropySourceGroup.Full);
            prng2.GetBytes(array2);

            foreach (var b in array2)
            {
                System.Diagnostics.Debug.Write(b + " ");
            }

            System.Diagnostics.Debug.WriteLine("");

            Assert.AreNotEqual(array1[new Range(7, 12)], array2[new Range(7, 12)]);
        }
예제 #4
0
        static void Main(string[] args)
        {
            var output = new byte[16];

            // memory stream, RNG will be seeded automatically and seeds discarded at the end of the operation
            // Cipher by default is AES with full entropy reseed sources
            using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());
            prng.GetBytes(output);

            // uses a file stream to read the seed from file. will write seed to same file at the end of scope
            using var prng2 = RNGVenturaProviderFactory.Create(new FileStream("seed.bin", FileMode.OpenOrCreate));
            prng2.GetBytes(output);

            // support for additional ciphers and reseed entropy sources can be either local, remote or both
            using var prng3 =
                      RNGVenturaProviderFactory.Create(new FileStream("seed.bin", FileMode.OpenOrCreate), Cipher.BlowFish, ReseedEntropySourceGroup.Local);
            prng3.GetBytes(output);

            // seeds the RNG with a combination seed from remote entropy sources - slower than the above options.
            using var prng4 = RNGVenturaProviderFactory.CreateSeeded();
            prng4.GetBytes(output);

            // additional initialisation options
            using var prng5 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Serpent, ReseedEntropySourceGroup.Local);
            prng5.GetBytes(output);

            // special initialisation, creates an instance of RandomNumberGenerator so Ventura can be used as drop-in replacement
            // in solutions that already use RandomNumberGenerator in a source compatible change
            using var prng6 =
                      RNGVenturaProviderFactory.CreateRng(new MemoryStream(), Cipher.Aes, ReseedEntropySourceGroup.Full);
            prng6.GetBytes(output);

            using var prng7 = RNGVenturaProviderFactory.CreateSeeded();
            var num = prng7.Next(1, 10);                // get a 32-bit integer between 1 and 10 both values inclusive

            var numArray = prng7.NextArray(1, 10, 100); // get an array of 100 32-bit integers between 1 and 10 both values inclusive
        }