private static void ShowCaesarEncryption() { Console.WriteLine("--*-- Caesar Cipher example --*--"); Console.WriteLine("Type a string to encrypt (or hit Enter to continue with default): "); string inputText = Console.ReadLine(); if (inputText == "") { inputText = plainText; } Console.WriteLine("Enter the key value (numberic)"); string key = Console.ReadLine(); int intKey = 0; if (!Int32.TryParse(key, out intKey)) { intKey = -1; } Console.WriteLine("Encrypted text input with Caesar Cipher by {0} spaces:", intKey); string cipherText = CaesarCipher.Encipher(inputText, intKey); Console.WriteLine(cipherText); Console.Write("\n"); Console.WriteLine("Decrypted Data:"); string t = CaesarCipher.Decipher(cipherText, intKey); Console.WriteLine(t); }
public ActionResult Index() { string password = "******"; int key = Convert.ToInt32(-2); string cipherText = CaesarCipher.Encipher(password, key); string t = CaesarCipher.Decipher(cipherText, key); string burak = ""; return(View()); }
private void decipherButton_Click(object sender, EventArgs e) { // This text is added only once to the file. if (!File.Exists(cipherTextPath)) { return; } string cipherText = File.ReadAllText(cipherTextPath); string vigenereKey = vigenereKeyTextBox.Text; if (!cipherText.All(c => Char.IsLetterOrDigit(c) || c == ' ')) { MessageBox.Show("The text must contains only alphanumeric characters in order to be encrypted!", "Invalid input!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!vigenereKey.All(c => Char.IsLetterOrDigit(c) || c == ' ')) { MessageBox.Show("The key must contains only alphanumeric characters in order to be encrypted!", "Invalid key!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var vigenereDecryptionText = VigenereCipher.Decipher(cipherText, vigenereKey); vigenereCipherRichTextBox.Text = vigenereDecryptionText; int caesarKey = Convert.ToInt32(caesarKeyNumericUpDown.Value); var plainText = CaesarCipher.Decipher(vigenereDecryptionText, caesarKey); plainTextRichTextBox.Text = plainText; File.WriteAllText(plainTextPath, plainText); }
public void CaesarDecipherTest(string expected, string ciphered, int rot, bool squash = false) { Assert.AreEqual(expected, CaesarCipher.Decipher(ciphered, rot, squash)); }