Beispiel #1
0
        public Bitmap TestBytes(AvalancheTestDataSourceRow a_row, int a_value_length)
        {
            double[,] output = CalculateAvalancheArrayBytes(a_row, a_value_length);
            Bitmap bmp = PrepareBitapFromAvalancheArray(output);

            return(ScaleBitmap(bmp));
        }
Beispiel #2
0
        private double[,] CalculateAvalancheArrayBytes(AvalancheTestDataSourceRow a_row, int a_value_length)
        {
            double[,] output = new double[a_value_length * 8, a_row.HashFunction.HashSize * 8];

            byte[] value       = new byte[a_value_length];
            byte[] value_alter = new byte[a_value_length];

            const int    TRIES = 10000;
            const double STEP  = 1.0 / TRIES;

            IHash hb = a_row.HashFunction;

            for (int tries = 0; tries < TRIES; tries++)
            {
                m_random.NextBytes(value);
                Array.Copy(value, value_alter, value.Length);

                byte[] hash = hb.ComputeBytes(value).GetBytes();

                int input_bit_index_in_array = 0;

                for (int input_byte_index_in_array = 0; input_byte_index_in_array < value.Length; input_byte_index_in_array++)
                {
                    uint input_bit_value_in_byte = 1;

                    for (int input_bit_index_in_byte = 0; input_bit_index_in_byte < 8; input_bit_index_in_byte++)
                    {
                        value_alter[input_byte_index_in_array] = (byte)(value[input_byte_index_in_array] ^ input_bit_value_in_byte);

                        byte[] hash_alter = hb.ComputeBytes(value_alter).GetBytes();

                        int output_bit_index_in_array = 0;

                        for (int output_byte_index_in_array = 0; output_byte_index_in_array < hash.Length; output_byte_index_in_array++)
                        {
                            uint output_bit_value_in_byte = 1;

                            for (int output_bit_index_in_byte = 0; output_bit_index_in_byte < 8; output_bit_index_in_byte++)
                            {
                                if ((hash[output_byte_index_in_array] & output_bit_value_in_byte) !=
                                    (hash_alter[output_byte_index_in_array] & output_bit_value_in_byte))
                                {
                                    output[input_bit_index_in_array, output_bit_index_in_array] += STEP;
                                }

                                output_bit_value_in_byte <<= 1;
                                output_bit_index_in_array++;
                            }
                        }

                        input_bit_index_in_array++;
                        input_bit_value_in_byte <<= 1;
                    }

                    value_alter[input_byte_index_in_array] = value[input_byte_index_in_array];
                }
            }

            return(output);
        }
Beispiel #3
0
        public void Test(AvalancheTestDataSourceRow a_row)
        {
            if (!(a_row.HashFunction is HashLib.ICrypto))
            {
                a_row.BmpByte   = TestBytes(a_row, 1);
                a_row.BmpUShort = TestBytes(a_row, 2);
                a_row.BmpUInt   = TestBytes(a_row, 4);
                a_row.BmpULong  = TestBytes(a_row, 8);
                a_row.BmpDouble = TestBytes(a_row, 8);
            }

            a_row.BmpString = TestBytes(a_row, 32);
            a_row.Bmp128    = TestBytes(a_row, 16);
            a_row.Bmp256    = TestBytes(a_row, 32);
        }