Example #1
0
        private static void TestStep10()
        {
            Byte[] result;
            Byte[] randomMapping = BuildRandomMapping3();
            result = Step10.Encrypt(Encoding.ASCII.GetBytes("abcdef"), randomMapping);
            Console.WriteLine("Step 10 Encrypt: >>>" + ToString(result) + "<<<");

            result = Step10.Decrypt(result, randomMapping);
            Console.WriteLine("Step 10 Decrypt: >>>" + ToString(result) + "<<<");
        }
Example #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);
            }
        }
Example #3
0
        /// <summary> Run a single test case and print every intermediate step for debugging.
        /// The results of each step are printed but not evaluated. </summary>
        private static void PerformStepByStepTest()
        {
            String clearText = "abcde";

            Console.WriteLine("Starting with " + clearText);
            Console.WriteLine("Encrypting...");
            // Step 01
            Byte[] encryptedTextStep01 = (new Step01()).Encrypt(Encoding.ASCII.GetBytes(clearText));
            Console.WriteLine("Step 01: " + ToString(encryptedTextStep01));
            Byte[] decryptedTextStep01 = (new Step01()).Decrypt(encryptedTextStep01);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep01));
            // Step 02
            Byte[] encryptedTextStep02 = Step02.Encrypt(encryptedTextStep01, 'q', 2);
            Console.WriteLine("Step 02: " + ToString(encryptedTextStep02));
            Byte[] decryptedTextStep02 = Step02.Decrypt(encryptedTextStep02, 2);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep02));
            //Step 03
            Byte[] encryptedTextStep03 = Step03.Encrypt(encryptedTextStep02);
            Console.WriteLine("Step 03: " + ToString(encryptedTextStep03));
            Byte[] decryptedTextStep03 = Step03.Decrypt(encryptedTextStep03);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep03));
            //Step 04
            Byte[] encryptedTextStep04 = Step04.Encrypt(encryptedTextStep03);
            Console.WriteLine("Step 04: " + ToString(encryptedTextStep04));
            Byte[] decryptedTextStep04 = Step04.Decrypt(encryptedTextStep04);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep04));
            //Step 05
            Byte[] encryptedTextStep05 = Step05.Encrypt(encryptedTextStep04);
            Console.WriteLine("Step 05: " + ToString(encryptedTextStep05));
            Byte[] decryptedTextStep05 = Step05.Decrypt(encryptedTextStep05);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep05));
            //Step 06
            Byte[] encryptedTextStep06 = Step06.Encrypt(encryptedTextStep05);
            Console.WriteLine("Step 06: " + ToString(encryptedTextStep06));
            Byte[] decryptedTextStep06 = Step06.Decrypt(encryptedTextStep06);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep06));
            //Step 07
            Byte[] encryptedTextStep07 = Step07.Encrypt(encryptedTextStep06);
            Console.WriteLine("Step 07: " + ToString(encryptedTextStep07));
            Byte[] decryptedTextStep07 = Step07.Decrypt(encryptedTextStep07);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep07));
            //Step 08
            Byte[] encryptedTextStep08 = Step08.Encrypt(encryptedTextStep07);
            Console.WriteLine("Step 08: " + ToString(encryptedTextStep08));
            Byte[] decryptedTextStep08 = Step08.Decrypt(encryptedTextStep08);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep08));
            //Step 09
            Byte[] encryptedTextStep09 = Step09.Encrypt(encryptedTextStep08);
            Console.WriteLine("Step 09: " + ToString(encryptedTextStep09));
            Byte[] decryptedTextStep09 = Step09.Decrypt(encryptedTextStep09);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep09));
            //Step 10
            Byte[] mapping             = BuildRandomMapping3();
            Byte[] encryptedTextStep10 = Step10.Encrypt(encryptedTextStep09, mapping);
            Console.WriteLine("Step 10: " + ToString(encryptedTextStep10));
            Byte[] decryptedTextStep10 = Step10.Decrypt(encryptedTextStep10, mapping);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep10));
            // We skip Step 11 because it uses one-way encryption
            // Step 12
            Byte[] encryptedTextStep12 = Step12.Encrypt(encryptedTextStep10);
            Console.WriteLine("Step 12: " + ToString(encryptedTextStep12));
            Byte[] decryptedTextStep12 = Step12.Decrypt(encryptedTextStep12);
            Console.WriteLine("         Decrypts to " + ToString(decryptedTextStep12));
        }