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));
                    }
                }
            }
        }
Exemplo n.º 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 RetrieveSerialNumber()
        {
            var generator = new PartialKeyGenerator(new Adler16(), new Jenkins96(), new uint[] { 1, 2, 3, 4 })
            {
                Spacing = 6
            };
            const string stringSeed   = "*****@*****.**";
            var          key          = generator.Generate(stringSeed);
            var          serialNumber = PartialKeyValidator.GetSerialNumberFromKey(key);

            Assert.AreEqual(serialNumber, PartialKeyValidator.GetSerialNumberFromSeed(stringSeed));
        }
        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;
                }
            }
        }