private void Decrypt_Click(object sender, RoutedEventArgs e) { var cipher = new CaesarCipher(); textbox.Text = cipher.Decrypt(Encrypted_text.Text, key, alfabet); TextLabel.Content = "Decrypted text"; }
static void Main(string[] args) { IKeyProvider<int> keyProvider = new ConsoleNumberKeyProvider(); ICryptoProvider<string> cryptoProvider = new CaesarCipher(keyProvider, false); Console.WriteLine("Caesar cipher demonsration"); Console.WriteLine(); try { while (true) { keyProvider.ResetKey(); Console.WriteLine("Enter any text:"); var input = Console.ReadLine(); var encryptedInput = cryptoProvider.Encrypt(input); var decryptedIput = cryptoProvider.Decrypt(encryptedInput); Console.WriteLine(); Console.Write("Ecrypted:"); Console.WriteLine(encryptedInput); Console.Write("Decrypted:"); Console.WriteLine(decryptedIput); Console.WriteLine(); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
public void ShouldDecryptCorrectly(string expected, string[] parts) { var cipher = new CaesarCipher(); var result = cipher.Decrypt(parts, 1); result.Should().Be(expected); }
public override DecodedMessage Create() { ICipher caesar = new CaesarCipher(); string decoded = caesar.Decrypt(text, key); return(new CaesarDecodedMessage(decoded)); }
/// <summary> /// Шифр Цезаря /// </summary> public static void CaesarCipherTest() { Console.WriteLine("6. Шифр Цезаря"); Console.WriteLine("Пример работы программы"); cryptogram = "I study at DNU!"; Console.WriteLine("Текст: " + cryptogram); int shift = 2; Console.WriteLine("Длина сдвига алфавита: " + shift); caesarCipher = new CaesarCipher(shift); encryptText = caesarCipher.Encrypt(cryptogram); Console.WriteLine("Зашифрованый текст: " + encryptText); decryptText = caesarCipher.Decrypt(encryptText); Console.WriteLine("Расшифрованый текст: " + decryptText); // Расшифруйте криптограмму (n = 2) Console.WriteLine("\nРасшифруйте криптограмму (n = 2)"); shift = 2; cryptogram = "YGBPGGFBOQTGBUPQYBHQTBDCVVGTBUMKKPI"; Console.WriteLine("Текст: " + cryptogram); Console.WriteLine("Длина сдвига алфавита: " + shift); caesarCipher = new CaesarCipher(shift); decryptText = caesarCipher.Decrypt(cryptogram); Console.WriteLine("Расшифрованый текст: " + decryptText); Console.WriteLine("\n"); }
/* * By : Mecit SARIGÜZEL * [email protected] */ static void Main(string[] args) { /* * Uncomment one line which contains the algorithm you need to use */ string input = "merhaba"; IEncryptionAlgorithm algorithm; algorithm = new CaesarCipher(input); // algorithm = new ShiftAlgorithm(input, 5); // algorithm = new DisplacementAlgorithm(input); // algorithm = new PermutationAlgorithm(input, 5, new[] { 4, 1, 5, 2, 3 }); /* * input = "bilgisayarmuhendisligi"; * algorithm = new RouteAlgorithm(input, 5); */ /* * input = "bilgisayarmuhendisligi"; * algorithm = new ZigzagAlgorithm(input, 5); */ /* * input = "afyonkarahisar"; * algorithm = new VigenereCipher(input, "araba"); */ Console.WriteLine($"\n\t\t=> Algorithm Name : {algorithm.Name} <="); Console.WriteLine($"\n\t\t[ Input : {input} ]"); Console.WriteLine($"\n\t\t-> Encryption result : {algorithm.Encrypt()}"); Console.WriteLine($"\t\t-> Decryption result : {algorithm.Decrypt()}\n"); }
public void Scenario_Decrypt_ShiftMoreThan26() { String text = "LwnkwuEcguctYcuCuucuukpcvgf"; int s = 28; String decryptedText = CaesarCipher.Decrypt(text, s); Assert.AreEqual(decryptedText, "JuliusCaesarWasAssassinated"); }
public void Scenario_Decrypt_ShiftLessThan26() { String text = "OzqnzxHfjxfwBfxFxxfxxnsfyji"; int s = 5; String decryptedText = CaesarCipher.Decrypt(text, s); Assert.AreEqual(decryptedText, "JuliusCaesarWasAssassinated"); }
public void Scenario_EncryptDecrypt_SameString() { String text = "InputStringToBeCheckedAfterDecryption"; int s = 5; String encryptedText = CaesarCipher.Encrypt(text, s); String decryptedText = CaesarCipher.Decrypt(encryptedText, s); Assert.AreEqual("InputStringToBeCheckedAfterDecryption", decryptedText); }
static void Main(string[] args) { CaesarCipher caesarCipher = new CaesarCipher(); string s = caesarCipher.Encrypt("Привет, меня зовут Кирилл2432423.", 6); Console.WriteLine(s); Console.WriteLine(caesarCipher.Decrypt(s, 6)); Console.ReadKey(); }
public void DecryptTest() { const string text = "abcdefg"; const string expected = "xyzabcd"; const int shift = 3; string result = caesar.Decrypt(text, shift); Assert.AreEqual(expected, result); }
public void CaesarDecryptValidInput() { // Arrange CaesarCipher cipher = new CaesarCipher(); string input = "UZXEJP"; string expected = "PUSZEK"; // Act string actual = cipher.Decrypt(input); // Assert Assert.AreEqual(expected, actual); }
public void CaesarDecryptValidInputWithSpace() { // Arrange CaesarCipher cipher = new CaesarCipher(); string input = "ASDF TEST"; string expected = "VNYA OZNO"; // Act string actual = cipher.Decrypt(input); // Assert Assert.AreEqual(expected, actual); }
private void Decrypt_Click(object sender, RoutedEventArgs e) { var cipher = new CaesarCipher(); a = Int32.Parse(ATextBox.Text); b = Int32.Parse(BTextBox.Text); if (buttin1Clicked == true) { MessageBox.Show("Decrypted Text: ", cipher.Decrypt(Encrypted_text.Text, a, b, alfabet)); textbox.Text = cipher.Decrypt(Encrypted_text.Text, a, b, alfabet); } else if (button2Clicked == true) { c = Int32.Parse(CTextBox.Text); MessageBox.Show("Decrypted Text: ", cipher.Decrypt3d(Encrypted_text.Text, a, b, c, alfabet)); textbox.Text = cipher.Decrypt3d(Encrypted_text.Text, a, b, c, alfabet); } }
static void Main(string[] args) { var cipher = new CaesarCipher(); Console.Write("Введите текст: "); var message = Console.ReadLine(); Console.Write("Введите ключ: "); var secretKey = Convert.ToInt32(Console.ReadLine()); var encryptedText = cipher.Encrypt(message, secretKey); Console.WriteLine("Зашифрованное сообщение: {0}", encryptedText); Console.WriteLine("Расшифрованное сообщение: {0}", cipher.Decrypt(encryptedText, secretKey)); Console.ReadLine(); }
public static string CaesarCipher(string text, int shiftLength, CryptType cryptType) { string result = string.Empty; caesarCipher = new CaesarCipher(shiftLength); switch (cryptType) { case CryptType.Encrypt: result = caesarCipher.Encrypt(text); break; case CryptType.Decrypt: result = caesarCipher.Decrypt(text); break; } return result; }
private void DecryptButton_Click(object sender, RoutedEventArgs e) { if (Regex.IsMatch(ShiftStepBox.Text, "^\\d+$")) { DecryptedText.Content = ""; CaesarCipher caesarCipher = new CaesarCipher(); string temp = caesarCipher.Decrypt(EncryptedText.Content.ToString().Replace("Encrypted string: ", ""), Convert.ToInt32(ShiftStepBox.Text)); if (temp == null) { MessageBox.Show("Строка для дешифорвания отсутствует.", "Ошибка"); } else { DecryptedText.Content = "Decrypted string: " + temp; } } }
public IActionResult CaesarDecrypt([FromBody] CaesarCipherViewModel viewModel) { CaesarCipher cipher = new CaesarCipher(viewModel.Key) { Alphabet = Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType) }; string decrypted = ""; try { decrypted = cipher.Decrypt(viewModel.Message); } catch (Exception) { return(BadRequest(new { Result = false, Message = Text.InvalidCharacter })); } return(Json(decrypted)); }
static void Main(string[] args) { string plainText = "attack at night with all forces"; string cipherText = "dwwdfn dw qljkw zlwk doo irufhv"; string plainText2 = "the wind blows where the pines are"; string cipherText2 = "wkh zlqg eorzv zkhuh wkh slqhv duh"; //char[] cipher; //creates an array called cipher. not sure why he added this. //char[] cipher2; Console.WriteLine("Cipher Text : "); foreach (var item in cipherText) { Console.Write(item); } Console.WriteLine(); Console.WriteLine("Plain text: "); //cipher = CaesarCipher.Encrypt(plainText, 3); //this line can be omitted cos its just to get out the cipher text. foreach (var item in CaesarCipher.Decrypt(cipherText, 3))//number of places moved up or down the array. { Console.Write(item); } Console.WriteLine(); Console.WriteLine("part2"); Console.WriteLine("plain Text 2: "); foreach (var item in plainText2) { Console.Write(item); } Console.WriteLine(); Console.WriteLine("Cipher text 2: "); //cipher2 = CaesarCipher.Encrypt(plainText2, 3); foreach (var item in CaesarCipher.Encrypt(cipherText2, 3)) { Console.Write(item); } Console.WriteLine(); }
public string Decrypt(string cipherText) { string plainText = cipherText; SimpleSubstitutionCipher simpleSubstitutionCipher = new SimpleSubstitutionCipher(); simpleSubstitutionCipher.SetKey(SIMPLE_SUBSTITUTION_CIPHER_KEY); plainText = simpleSubstitutionCipher.Decrypt(plainText); AffineCipher affineCipher = new AffineCipher(); affineCipher.SetKeys(new int[] { AFFINE_CIPHER_KEY_A, AFFINE_CIPHER_KEY_B }); plainText = affineCipher.Decrypt(plainText); CaesarCipher caesarCipher = new CaesarCipher(); caesarCipher.SetKey(CAESAR_CIPHER_KEY); plainText = caesarCipher.Decrypt(plainText); return(plainText); }
static void Main(string[] args) { Console.WriteLine("Choose alghorithm\n" + "1. RailFence\n" + "2. Transposition A\n" + "3. Transposition B\n" + "4. Transposition C\n" + "5. Caesar\n" + "6. Vigenere\n" + "7. Exit\n"); Console.WriteLine("Choose: "); int option = ReadInt(); string wordToEncrypt = ""; string encryptedWord = ""; string decryptedWord = ""; Console.WriteLine("Enter your word: "); wordToEncrypt = Console.ReadLine(); ICipher cs = new RailFenceCipher(0); switch (option) { case 1: // RailFence { Console.WriteLine("Give key [Integer]: "); int key = ReadInt(); cs = new RailFenceCipher(key); Console.WriteLine("Using RailFence Cipher"); Console.WriteLine("\nWord given: " + wordToEncrypt); encryptedWord = cs.Encrypt(wordToEncrypt); Console.WriteLine("Encrypted word: " + encryptedWord); Console.WriteLine("Give word to decrypt: "); wordToEncrypt = Console.ReadLine(); Console.WriteLine("Give key [Integer]: "); key = ReadInt(); cs = new RailFenceCipher(key); decryptedWord = cs.Decrypt(wordToEncrypt); Console.WriteLine("Decrypted word: " + decryptedWord); } break; case 2: // Transposition A { cs = new TranspositionCipherA(); Console.WriteLine("Using Transposition A Cipher"); Console.WriteLine("\nWord given: " + wordToEncrypt); encryptedWord = cs.Encrypt(wordToEncrypt); Console.WriteLine("Encrypted word: " + encryptedWord); Console.WriteLine("Give word to decrypt: "); wordToEncrypt = Console.ReadLine(); decryptedWord = cs.Decrypt(wordToEncrypt); Console.WriteLine("Decrypted word: " + decryptedWord); } break; case 3: // Transposition B { Console.WriteLine("Give key [String, Letters only]: "); string key = Console.ReadLine(); cs = new TranspositionCipherB(key); Console.WriteLine("Using Transposition B Cipher"); Console.WriteLine("\nWord given: " + wordToEncrypt); encryptedWord = cs.Encrypt(wordToEncrypt); Console.WriteLine("Encrypted word: " + encryptedWord); Console.WriteLine("Give word to decrypt: "); wordToEncrypt = Console.ReadLine(); Console.WriteLine("Give key [String, Letters only]: "); key = Console.ReadLine(); cs = new TranspositionCipherB(key); decryptedWord = cs.Decrypt(wordToEncrypt); Console.WriteLine("Decrypted word: " + decryptedWord); } break; case 4: // Transposition C { Console.WriteLine("Give key [String, Letters only]: "); string key = Console.ReadLine(); cs = new TranspositionCipherC(key); Console.WriteLine("Using Transposition C Cipher"); Console.WriteLine("\nWord given: " + wordToEncrypt); encryptedWord = cs.Encrypt(wordToEncrypt); Console.WriteLine("Encrypted word: " + encryptedWord); Console.WriteLine("Give word to decrypt: "); wordToEncrypt = Console.ReadLine(); Console.WriteLine("Give key [String, Letters only]: "); key = Console.ReadLine(); cs = new TranspositionCipherC(key); decryptedWord = cs.Decrypt(wordToEncrypt); Console.WriteLine("Decrypted word: " + decryptedWord); } break; case 5: // Caesar { Console.WriteLine("Give key 1 [Integer]: "); int key0 = ReadInt(); Console.WriteLine("Give key 2 [Integer]: "); int key1 = ReadInt(); cs = new CaesarCipher(key0, key1); Console.WriteLine("Using Caesar Cipher"); Console.WriteLine("\nWord given: " + wordToEncrypt); encryptedWord = cs.Encrypt(wordToEncrypt); Console.WriteLine("Encrypted word: " + encryptedWord); Console.WriteLine("Give word to decrypt: "); wordToEncrypt = Console.ReadLine(); Console.WriteLine("Give key 1 [Integer]: "); key0 = ReadInt(); Console.WriteLine("Give key 2 [Integer]: "); key1 = ReadInt(); cs = new CaesarCipher(key0, key1); decryptedWord = cs.Decrypt(wordToEncrypt); Console.WriteLine("Decrypted word: " + decryptedWord); } break; case 6: // Vigenere { Console.WriteLine("Give key [String, Letters only]: "); string key = Console.ReadLine(); cs = new VigenereCipher(key); Console.WriteLine("Using Vigenere Cipher"); Console.WriteLine("\nWord given: " + wordToEncrypt); encryptedWord = cs.Encrypt(wordToEncrypt); Console.WriteLine("Encrypted word: " + encryptedWord); Console.WriteLine("Give word to decrypt: "); wordToEncrypt = Console.ReadLine(); Console.WriteLine("Give key [String, Letters only]: "); key = Console.ReadLine(); cs = new VigenereCipher(key); decryptedWord = cs.Decrypt(wordToEncrypt); Console.WriteLine("Decrypted word: " + decryptedWord); } break; case 7: Console.WriteLine("Bye!"); Console.ReadKey(); return; default: Console.WriteLine("Wrong input!"); Console.ReadKey(); return; } Console.ReadKey(); return; }