private static void PerformEncryptOperation(out string plainText, out string cipherText, out int shift) { AppMessage("Welcome to encryption mode \nEnter message to encrypt"); plainText = Console.ReadLine(); shift = 0; cipherText = string.Empty; if (plainText != "") { try { AppMessage("Enter the shift"); shift = int.Parse(Console.ReadLine()); if (shift <= 26 && shift > 0) { AppMessage("Cipher is"); cipherText = new string(CaesarCipher.Encrypt(plainText, shift)); Console.WriteLine(cipherText); } else { ErrorMessage("Enter a number between 1 to 26"); } } catch (Exception e) { ErrorMessage(e.Message); } } else { ErrorMessage("Invalid input"); } }
private static void PerformDecryptOperation(out string filePath, out string fileName, ref string cipherText, out int shift, ref StreamReader sr) { shift = 0; fileName = string.Empty; AppMessage("Welcome to decryption mode \nEnter the path of file to decrypt"); filePath = Console.ReadLine(); if (filePath != "") { AppMessage("Enter file name"); fileName = Console.ReadLine(); if (fileName != "") { filePath = filePath + "\\" + fileName; AppMessage("Enter the shift"); try { shift = int.Parse(Console.ReadLine()); if (shift <= 26 && shift > 0) { sr = new System.IO.StreamReader(filePath); cipherText = sr.ReadToEnd(); cipherText = new string(CaesarCipher.Decrypt(cipherText, shift)); AppMessage("Cipher is"); Console.WriteLine(cipherText); sr.Close(); } else { ErrorMessage("Enter a number between 1 to 26"); } } catch (Exception e) { ErrorMessage(e.Message); } } else { ErrorMessage("File name cannot be empty"); } } else { ErrorMessage("Path is invalid"); } }