public void GenerateListOfKeys()
        {
            foreach (var hash in TestHashes)
            {
                IChecksum16 checksum = new Adler16();
                var         baseKeys = new[]
                {
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next()
                };
                var gen = new PartialKeyGenerator(checksum, hash, baseKeys)
                {
                    Spacing = 6
                };

                var keys = gen.Generate(100, Random);
                foreach (var key in keys)
                {
                    for (var j = 0; j < baseKeys.Length; j++)
                    {
                        Assert.IsTrue(PartialKeyValidator.ValidateKey(checksum, hash, key.Value, j, baseKeys[j]));
                    }
                }
            }
        }
        public void SingleHashWithStringSeed()
        {
            foreach (var hash in TestHashes)
            {
                IChecksum16 checksum = new Adler16();

                for (uint i = 0; i < 100; i++)
                {
                    var baseKeys = new[]
                    {
                        (uint)Random.Next(),
                        (uint)Random.Next(),
                        (uint)Random.Next(),
                        (uint)Random.Next(),
                        (uint)Random.Next()
                    };
                    var gen = new PartialKeyGenerator(checksum, hash, baseKeys)
                    {
                        Spacing = 6
                    };

                    const string seed = "Bob Smith - [email protected]";
                    var          key  = gen.Generate(seed);

                    for (var j = 0; j < baseKeys.Length; j++)
                    {
                        Assert.IsTrue(PartialKeyValidator.ValidateKey(checksum, hash, key, j, baseKeys[j], seed));
                    }
                }
            }
        }
示例#3
0
        public void SingleHash(IHash hash)
        {
            IChecksum16 checksum = new Adler16();

            for (uint i = 0; i < 100; i++)
            {
                var baseKeys = new[]
                {
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next()
                };
                var gen = new PartialKeyGenerator(checksum, hash, baseKeys)
                {
                    Spacing = 6
                };

                var seed = (uint)Random.Next();
                var key  = gen.Generate(seed);

                for (var j = 0; j < baseKeys.Length; j++)
                {
                    Assert.IsTrue(PartialKeyValidator.ValidateKey(checksum, hash, key, j, baseKeys[j]));
                }
            }
        }
        public void MultipleHashes()
        {
            IChecksum16 checksum = new Adler16();

            for (uint i = 0; i < 100; i++)
            {
                var baseKeys = new[]
                {
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next(),
                    (uint)Random.Next()
                };

                var gen = new PartialKeyGenerator(checksum, TestHashes, baseKeys)
                {
                    Spacing = 6
                };

                var seed = (uint)Random.Next();
                var key  = gen.Generate(seed);

                var hashIndex = 0;
                for (var j = 0; j < baseKeys.Length; j++)
                {
                    Assert.IsTrue(PartialKeyValidator.ValidateKey(checksum, TestHashes[hashIndex++], key, j, baseKeys[j]));
                    hashIndex %= TestHashes.Length;
                }
            }
        }
示例#5
0
        public static byte[] GenerateChecksum(string checksum, int offset, byte[] buffer, int eof = -1)
        {
            byte[] returnValue = null;
            switch (checksum)
            {
            case "Adler8 - {1Bytes}":
                returnValue = eof == -1 ? Adler8.Compute(offset, buffer) : Adler8.Compute(offset, buffer, eof);
                break;

            case "Adler16 - {2Bytes}":
                returnValue = eof == -1 ? Adler16.Compute(offset, buffer) : Adler16.Compute(offset, buffer, eof);
                break;

            case "Adler32 - {4Bytes}":
                returnValue = eof == -1 ? Adler32.Compute(offset, buffer) : Adler32.Compute(offset, buffer, eof);
                break;

            case "Checksum8 - {1Bytes}":
                returnValue = eof == -1 ? Checksum8.Compute(offset, buffer) : Checksum8.Compute(offset, buffer, eof);
                break;

            case "Checksum16 - {2Bytes}":
                returnValue = eof == -1 ? Checksum16.Compute(offset, buffer) : Checksum16.Compute(offset, buffer, eof);
                break;

            case "Checksum24 - {3Bytes}":
                returnValue = eof == -1 ? Checksum24.Compute(offset, buffer) : Checksum24.Compute(offset, buffer, eof);
                break;

            case "Checksum32 - {4Bytes}":
                returnValue = eof == -1 ? Checksum32.Compute(offset, buffer) : Checksum32.Compute(offset, buffer, eof);
                break;

            case "Checksum40 - {5Bytes}":
                returnValue = eof == -1 ? Checksum40.Compute(offset, buffer) : Checksum40.Compute(offset, buffer, eof);
                break;

            case "Checksum48 - {6Bytes}":
                returnValue = eof == -1 ? Checksum48.Compute(offset, buffer) : Checksum48.Compute(offset, buffer, eof);
                break;

            case "Checksum56 - {7Bytes}":
                returnValue = eof == -1 ? Checksum56.Compute(offset, buffer) : Checksum56.Compute(offset, buffer, eof);
                break;

            case "Checksum64 - {8Bytes}":
                returnValue = eof == -1 ? Checksum64.Compute(offset, buffer) : Checksum64.Compute(offset, buffer, eof);
                break;

            case "CRC16 - {2Bytes}":
                Crc16 crc16 = new Crc16();
                returnValue = eof == -1 ? crc16.Compute(offset, buffer) : crc16.Compute(offset, buffer, eof);
                break;

            case "CRC16 CCITT - {2Bytes}":
                Crc16ccitt crc16Ccitt = new Crc16ccitt();
                returnValue = eof == -1 ? crc16Ccitt.Compute(offset, buffer) : crc16Ccitt.Compute(offset, buffer, eof);
                break;

            case "CRC32 - {4Bytes}":
                returnValue = eof == -1 ? Crc32.Compute(offset, buffer) : Crc32.Compute(offset, buffer, eof);
                break;

            case "HMAC SHA 1 (128)  - {16Bytes}":
                returnValue = eof == -1 ? HmacSha1.Compute(offset, buffer) : HmacSha1.Compute(offset, buffer, eof);
                break;

            case "HMAC SHA 256 - {32Bytes}":
                returnValue = eof == -1 ? HmacSha256.Compute(offset, buffer) : HmacSha256.Compute(offset, buffer, eof);
                break;

            case "HMAC SHA 384 - {48Bytes}":
                returnValue = eof == -1 ? HmacSha384.Compute(offset, buffer) : HmacSha384.Compute(offset, buffer, eof);
                break;

            case "HMAC SHA 512 - {64Bytes}":
                returnValue = eof == -1 ? HmacSha512.Compute(offset, buffer) : HmacSha512.Compute(offset, buffer, eof);
                break;

            case "MD5 - {16Bytes}":
                returnValue = eof == -1 ? Md5.Compute(offset, buffer) : Md5.Compute(offset, buffer, eof);
                break;

            case "MD5 CNG - {16Bytes}":
                returnValue = eof == -1 ? Md5Cng.Compute(offset, buffer) : Md5Cng.Compute(offset, buffer, eof);
                break;
            }
            return(returnValue);
        }