Exemple #1
0
        public void Unigraph_FourSquareTest()
        {
            char[] ab = Utility.EnglishAlphabet();
            Array.Resize(ref ab, ab.Length - 1);
            FourSquare foursquare = new FourSquare(ab);// KeyedEnglishAlphabet("KRYPTOS"));

            cipher    = "";
            clear     = "";
            generated = "";
            for (int i = 0; i < 25; i++)
            {
                foursquare.KeySquare1 = new string(foursquare.ScrambledAlphabet());
                foursquare.KeySquare2 = new string(foursquare.ScrambledAlphabet());

                generated = foursquare.GenerateRandomString();

                cipher = foursquare.Encrypt(generated);
                clear  = foursquare.Decrypt(cipher);

                if (cipher.Length - 1 == generated.Length)
                {
                    clear = clear.Substring(0, clear.Length - 1);
                }

                Assert.AreEqual(generated, clear);
            }
        }
Exemple #2
0
        public void DecryptBasicTest()
        {
            FourSquare fs = new FourSquare(
                new Alphabet("ZGPTFOGHMUWDRCNYKEQAXVSBL"),
                new Alphabet("MFNBDCRHSAXYOGVITUEWLQZKP"));
            var encrypted = fs.Decrypt("TIYBFHTIZBSY");

            Assert.AreEqual("ATTACKATDAWN", encrypted);
        }