Пример #1
0
        private static void TestStep13()
        {
            Byte[] result;
            result = Step13.Encrypt(Encoding.ASCII.GetBytes("abcdef"));
            Console.WriteLine("Step 13 Encrypt: >>>" + ToString(result) + "<<<");

            result = Step13.Decrypt(result);
            Console.WriteLine("Step 13 Decrypt: >>>" + ToString(result) + "<<<");
        }
Пример #2
0
        /// <summary>
        /// Run a test case, evaluate the result, and print the evaulation to the console
        /// </summary>
        /// <param name="testString">The string to be encrypted</param>
        /// <param name="testTitle">The name of the test case</param>
        /// <returns>True if the testString encrypted then decrypted and ended up equal to testString, false otherwise </returns>
        private static Boolean Test(String testString, String testTitle)
        {
            String text = testString;

            Console.WriteLine(testTitle + ": Starting with " + text);
            Byte[] encryptedText;
            encryptedText = (new Step01()).Encrypt(Encoding.ASCII.GetBytes(text));
            encryptedText = Step02.Encrypt(encryptedText, 'q', 2);
            encryptedText = Step03.Encrypt(encryptedText);
            encryptedText = Step04.Encrypt(encryptedText);
            encryptedText = Step05.Encrypt(encryptedText);
            encryptedText = Step06.Encrypt(encryptedText);
            encryptedText = Step07.Encrypt(encryptedText);
            encryptedText = Step08.Encrypt(encryptedText);
            encryptedText = Step09.Encrypt(encryptedText);
            byte[] mapping = BuildRandomMapping2();
            encryptedText = Step10.Encrypt(encryptedText, mapping);
            // Skip Step 11 because it's a one-way encryption
            encryptedText = Step12.Encrypt(encryptedText);
            encryptedText = Step13.Encrypt(encryptedText);
            encryptedText = Step14.Encrypt(encryptedText);
            encryptedText = (new Step15()).Encrypt(encryptedText);

            //            Console.WriteLine("Decrypting " + ToString(encryptedText));

            Byte[] decryptedText;
            decryptedText = (new Step15()).Decrypt(encryptedText);
            decryptedText = Step14.Decrypt(decryptedText);
            decryptedText = Step13.Decrypt(decryptedText);
            decryptedText = Step12.Decrypt(decryptedText);
            // Skip Step 11 because it's a one-way encryption
            decryptedText = Step10.Decrypt(decryptedText, mapping);
            decryptedText = Step09.Decrypt(decryptedText);
            decryptedText = Step08.Decrypt(decryptedText);
            decryptedText = Step07.Decrypt(decryptedText);
            decryptedText = Step06.Decrypt(decryptedText);
            decryptedText = Step05.Decrypt(decryptedText);
            decryptedText = Step04.Decrypt(decryptedText);
            decryptedText = Step03.Decrypt(decryptedText);
            decryptedText = Step02.Decrypt(decryptedText, 2);
            decryptedText = (new Step01()).Decrypt(decryptedText);

//            Console.WriteLine("Result = " + ToString(decryptedText));
            if (Encoding.ASCII.GetBytes(text).ToString().Equals(decryptedText.ToString()))
            {
                Console.WriteLine(testTitle + " Passed");
                return(true);
            }
            else
            {
                Console.WriteLine(testTitle + " FAILED");
                return(false);
            }
        }