Example #1
0
        //display string of text in columns specified by user..can display cipher and plain text
        static public void DisplayPartialColumns(this string value, int keylength)
        {
            char[] chars = value.ToCharArray();
            int    i = 0, j = 0, width = 0, chunk = 0;

            //Console.Write("Would you like to use the assumed keylength(1), give your own keylength(2): ");
            //int choice = Int32.Parse(Console.ReadLine());

            //if (choice == 1)
            //    width = keylength;
            //else if (choice == 2)
            //{
            Console.WriteLine("What is your specified keylength: ");
            width = Int32.Parse(Console.ReadLine());
            //}
            char[] key = new char[width];

            while (i < width)
            {
                Console.Write("What is the specified key for column {0} (if you do not know, enter a space): ", i + 1);
                key[i] = Convert.ToChar(Console.ReadLine());
                i++;
            }

            try
            {
                while (j < value.Length)
                {
                    while (chunk < width && j + chunk < value.Length)
                    {
                        if (key[chunk].CompareTo(' ') == 0)
                        {
                            Console.Write("{0}->{1, -3} | ", chars[j + chunk], '_');
                        }
                        else
                        {
                            Console.Write("{0}->{1, -3} | ", chars[j + chunk], Crypt.Decrypt(chars[j + chunk].ToString(), key[chunk].ToString()));
                        }
                        chunk++;
                    }
                    j    += width;
                    chunk = 0;
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was an error: " + ex.Message);
            }
        }
Example #2
0
        private void HandleDecrypt(string [] line)
        {
            string message, key, flag = "d";

            if (line.Length == 2)
            {
                message = GetMessage(flag);
                key     = GetKey(flag);
            }
            else if (line.Length == 3)
            {
                message = FileHandler.FileRead(line[2]);
                key     = GetKey(flag);
            }
            else
            {
                message = FileHandler.FileRead(line[2]);
                key     = FileHandler.FileRead(line[3]);
            }
            Crypt.Decrypt(message, key).DisplayBlock();
        }