private void RunMultilayer()
        {
            PrintHeader();

            string selection = EncryptOrDecrypt();
            string message   = GetMessage(selection);
            string key       = GetKey();
            string altKey    = TableFunctions.AltKeyGen(key);
            string output    = "";

            if (selection == "2")
            {
                PrintHeader();
                output = multilayer.Decipher(message, altKey);
                output = railroad.Decipher(output);
                output = multilayer.Decipher(output, key);
                Console.WriteLine(output);
            }
            else
            {
                PrintHeader();
                output = multilayer.Encipher(message, key);
                output = railroad.Encipher(output);
                output = multilayer.Encipher(output, altKey);
                Console.WriteLine(output);
            }
            RetToCon();
        }
Exemple #2
0
        public bool Decipher(string fullPath, string key)
        {
            bool   fileCreated = false;
            string altKey      = TableFunctions.AltKeyGen(key);

            try
            {
                string fileName      = Path.GetFileName(fullPath);
                string fileNameNoExt = Path.GetFileNameWithoutExtension(fileName);
                string fileExt       = Path.GetExtension(fileName);

                string fileDir    = fullPath.Substring(0, fullPath.Length - fileName.Length);
                string createFile = fileNameNoExt + "MLC" + fileExt;
                string createFull = Path.Combine(fileDir, createFile);

                using (StreamReader sr = new StreamReader(fullPath))
                {
                    while (!sr.EndOfStream)
                    {
                        using (StreamWriter sw = new StreamWriter(createFull, true))
                        {
                            string output = "";
                            output = mlc.Decipher(sr.ReadLine(), altKey);
                            output = rrc.Decipher(output);
                            sw.WriteLine(mlc.Decipher(output, key));
                        }
                    }
                }
                if (Path.IsPathFullyQualified(createFull))
                {
                    fileCreated = true;
                }
                File.Move(createFull, fullPath, true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid input for file path...");
            }
            return(fileCreated);
        }
        private void RunDocument()
        {
            PrintHeader();

            string selection = EncryptOrDecrypt();
            string fullPath  = GetFilePath();
            string key       = GetKey();
            string altKey    = TableFunctions.AltKeyGen(key);

            if (selection == "2")
            {
                PrintHeader();
                bool decipherSuccessful = documentIO.Decipher(fullPath, key);
                if (decipherSuccessful)
                {
                    Console.WriteLine("File decipher successful!");
                }
                else
                {
                    Console.WriteLine("File decipher was not successful, please try again!");
                }
            }
            else
            {
                PrintHeader();
                bool encipherSuccessful = documentIO.Encipher(fullPath, key);
                if (encipherSuccessful)
                {
                    Console.WriteLine("File encipher successful!");
                }
                else
                {
                    Console.WriteLine("File encipher was not successful, please try again!");
                }
            }
            RetToCon();
        }