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 cipherButton_Click(object sender, EventArgs e) { // This text is added only once to the file. if (!File.Exists(plainTextPath)) { return; } string plainText = File.ReadAllText(plainTextPath); if (!plainText.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; } string vigenereKey = vigenereKeyTextBox.Text; 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 vigenereEncryptionText = VigenereCipher.Encipher(plainText, vigenereKey); vigenereCipherRichTextBox.Text = vigenereEncryptionText; int caesarKey = Convert.ToInt32(caesarKeyNumericUpDown.Value); var cipherText = CaesarCipher.Encipher(vigenereEncryptionText, caesarKey); cipherTextRichTextBox.Text = cipherText; File.WriteAllText(cipherTextPath, cipherText); }
public void CaesarCipherTest(string expected, string plaintext, int rot, bool squash = false) { Assert.AreEqual(expected, CaesarCipher.Encipher(plaintext, rot, squash)); }