Esempio n. 1
0
        public static void Test()
        {
            SaltyRandomGenerator srg = new SaltyRandomGenerator();

            srg.getsalt += srg_getsalt;
            BitCollector collector = new BitCollector(512);
            int          bits;
            int          n;

            for (bits = 1; bits < 28; bits++)
            {
                srg.Reset();
                collector.Clear();
                for (n = 0; n < (512 - bits); n += bits)
                {
                    int value = srg.GetEntropy(bits, false);
                    collector.AddBits((uint)value, bits);
                }
                {
                    int final_value = srg.GetEntropy(512 - n, false);
                    collector.AddBits((uint)final_value, 512 - n);
                }
                byte[] one = srg.entropy;
                byte[] two = collector.buffer;
                for (n = 0; n < 512 / 8; n++)
                {
                    if (one[n] != two[n])
                    {
                        Console.WriteLine("Byte " + n + " differed " + one[n].ToString("x") + " " + two[n].ToString("x"));
                    }
                }
            }

            for (bits = 1; bits < 28; bits++)
            {
                srg.Reset();
                collector.Clear();
                for (n = 0; n < (512 - bits); n += bits)
                {
                    int value = srg.GetEntropy(bits, true);
                    collector.AddBits((uint)value, bits);
                    //Console.WriteLine( "data is : " + value );
                }
                {
                    int final_value = srg.GetEntropy(512 - n, false);
                    collector.AddBits((uint)final_value, 512 - n);
                }
                byte[] one = srg.entropy;
                byte[] two = collector.buffer;
                for (n = 0; n < 512 / 8; n++)
                {
                    if (one[n] != two[n])
                    {
                        Console.WriteLine("Byte " + n + " differed " + one[n].ToString("x") + " " + two[n].ToString("x"));
                    }
                }
            }
        }
Esempio n. 2
0
        public void Test_BitCollectorAndBitStream()
        {
            byte[]       initialBuffer = new byte[] { 0xAA, 0x54 };
            BitStream    bitStream     = new BitStream(initialBuffer);
            BitCollector bitCollector  = new BitCollector();
            byte         nextBit       = 0;

            while ((nextBit = bitStream.NextBit()) != 255)
            {
                bitCollector.PushBit(nextBit);
            }
            Assert.AreEqual(initialBuffer[0], bitCollector.GetBuffer()[0]);
            Assert.AreEqual(initialBuffer[1], bitCollector.GetBuffer()[1]);
        }
Esempio n. 3
0
		public static void Test()
		{
			SaltyRandomGenerator srg = new SaltyRandomGenerator();
			srg.getsalt += srg_getsalt;
			BitCollector collector = new BitCollector( 512 );
			int bits;
			int n;
			for( bits = 1; bits < 28; bits++ )
			{
				srg.Reset();
				collector.Clear();
				for( n = 0; n < ( 512 - bits ); n += bits )
				{
					int value = srg.GetEntropy( bits, false );
					collector.AddBits( (uint)value, bits );
				}
				{
					int final_value = srg.GetEntropy( 512 - n, false );
					collector.AddBits( (uint)final_value, 512 - n );
				}
				byte[] one = srg.entropy;
				byte[] two = collector.buffer;
				for( n = 0; n < 512 / 8; n++ )
				{
					if( one[n] != two[n] )
						Console.WriteLine( "Byte " + n + " differed " + one[n].ToString( "x" ) + " " + two[n].ToString( "x" ) );
				}
			}

			for( bits = 1; bits < 28; bits++ )
			{
				srg.Reset();
				collector.Clear();
				for( n = 0; n < ( 512 - bits ); n += bits )
				{
					int value = srg.GetEntropy( bits, true );
					collector.AddBits( (uint)value, bits );
					//Console.WriteLine( "data is : " + value );
				}
				{
					int final_value = srg.GetEntropy( 512 - n, false );
					collector.AddBits( (uint)final_value, 512 - n );
				}
				byte[] one = srg.entropy;
				byte[] two = collector.buffer;
				for( n = 0; n < 512 / 8; n++ )
				{
					if( one[n] != two[n] )
						Console.WriteLine( "Byte " + n + " differed " + one[n].ToString( "x" ) + " " + two[n].ToString( "x" ) );
				}
			}
		}