Example #1
0
        public void IncTest()
        {
            SpecialVariableBaseNumber num = new SpecialVariableBaseNumber();

            Assert.AreEqual("0", num.ToString());

            for (int i = 0; i < 12; ++i)
            {
                num.Inc();
            }
            Assert.AreEqual("2,0,0,0", num.ToString());
        }
Example #2
0
        public void ToBigIntTest()
        {
            SpecialVariableBaseNumber num = new SpecialVariableBaseNumber();

            Assert.AreEqual(0, (int)num.ToBigInt());

            for (int i = 1; i < 100; ++i)
            {
                num.Inc();
                Assert.AreEqual(i, (int)num.ToBigInt());
            }

            num = new SpecialVariableBaseNumber();
            Assert.AreEqual(0, (int)num.ToBigInt());
            for (int i = 1; i < 1000; ++i)
            {
                num.IncBy(17);
                Assert.AreEqual(17 * i, (int)num.ToBigInt());
            }
        }
Example #3
0
        public void EncodeDecodePairs()
        {
            SpecialVariableBaseNumber seed = new SpecialVariableBaseNumber(26);

            seed.Inc();
            for (int i = 0; i < 100000; ++i)
            {
                string             originalString = "abcdefghijklmnopqrstuvwxyz";
                SubstitutionCypher original       = new SubstitutionCypher(originalString, alphabet);
                if (i == 0)
                {
                    Console.WriteLine($"{original.NumSeeds} possible combinations");
                }
                string codedString = original.Encode(seed);
                Assert.AreNotEqual(originalString, codedString);
                SubstitutionCypher coded = new SubstitutionCypher(codedString, alphabet);
                Assert.AreEqual(originalString, coded.Decode(seed));
                seed.IncBy(732);
            }

            SubstitutionCypher usesLargeSeed = new SubstitutionCypher("hello", alphabet);

            seed = new SpecialVariableBaseNumber(26);
            seed.IncBy(usesLargeSeed.NumSeeds - 1);

            string borderEncoded = usesLargeSeed.Encode(seed);

            Console.WriteLine($"Using seed {seed}");

            Console.WriteLine($"Coded: {borderEncoded}");


            SubstitutionCypher reverseWithLargeSeed = new SubstitutionCypher(borderEncoded, alphabet);
            string             decoded = reverseWithLargeSeed.Decode(seed);

            Console.WriteLine($"Decoded: {decoded}");

            Assert.AreEqual("hello", decoded);
        }