public void EncryptTest() { const string text = "abcxyz"; const string expected = "efgbcd"; const int shift = 4; string result = caesar.Encrypt(text, shift); Assert.AreEqual(expected, result); }
public override EncodedMessage Create() { ICipher caesar = new CaesarCipher(); string encoded = caesar.Encrypt(text, key); return(new CaesarEncodedMessage(encoded)); }
public void ShouldEncryptCorrectly(string input, string[] expected) { var cipher = new CaesarCipher(); var result = cipher.Encrypt(input, 1); result.Should().BeEquivalentTo(expected, opt => opt.WithStrictOrdering()); }
/// <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"); }
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(); } }
/* * 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_Encrypt_ShiftLessThan26() { String text = "JuliusCaesarWasAssassinated"; int s = 5; String encryptedText = CaesarCipher.Encrypt(text, s); Assert.AreEqual(encryptedText, "OzqnzxHfjxfwBfxFxxfxxnsfyji"); }
public void Scenario_Encrypt_ShiftMoreThan26() { String text = "JuliusCaesarWasAssassinated"; int s = 28; String encryptedText = CaesarCipher.Encrypt(text, s); Assert.AreEqual(encryptedText, "LwnkwuEcguctYcuCuucuukpcvgf"); }
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 CaesarEncryptValidInput() { // Arrange CaesarCipher cipher = new CaesarCipher(); string input = "PUSZEK"; string expected = "UZXEJP"; // Act string actual = cipher.Encrypt(input); // Assert Assert.AreEqual(expected, actual); }
public void CaesarEncryptValidInputWithSpace() { // Arrange CaesarCipher cipher = new CaesarCipher(); string input = "asdf test"; string expected = "fxik yjxy"; // Act string actual = cipher.Encrypt(input); // Assert Assert.AreEqual(expected, actual); }
public IActionResult CaesarVisualization([FromBody] CaesarCipherViewModel viewModel) { CaesarCipher cipher = new CaesarCipher(viewModel.Key) { Alphabet = Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType) }; cipher.Alphabet = Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType); string[] results = new string[4] { "alphabet", "newalphabet", "output", "input" }; string encrypted = ""; string input = viewModel.Message; input = StringHelper.ReplaceWhitespace(input, ""); input = input.ToUpper(); int alphabetLength = cipher.Alphabet.Length; int newKey = (viewModel.Key) % alphabetLength; string cipherAlphabet = ""; for (int i = 0; i < alphabetLength; i++) { if ((i + newKey) >= alphabetLength) { cipherAlphabet += cipher.Alphabet[i + newKey - alphabetLength]; } else { cipherAlphabet += cipher.Alphabet[i + newKey]; } } results[0] = cipher.Alphabet; results[1] = cipherAlphabet; results[3] = input; try { encrypted = cipher.Encrypt(viewModel.Message); results[2] = encrypted; } catch (NullReferenceException) { } catch (Exception) { return(BadRequest(new { Result = false, Message = Text.InvalidCharacter })); } return(Json(results)); }
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 Encrypt_Click(object sender, RoutedEventArgs e) { key = Int32.Parse(Key_Box.Text); var cipher = new CaesarCipher(); Encrypted_text.Text = cipher.Encrypt(textbox.Text, key, alfabet); if ((key >= 1) && (key < int.Parse(To_TextBox.Text))) { Validation_Label.Content = "Valid"; Validation_Label.Background = new SolidColorBrush(Colors.Green); } else { Validation_Label.Content = "Not Valid"; Validation_Label.Background = new SolidColorBrush(Colors.Red); } }
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(); }
private void EncryptButton_Click(object sender, RoutedEventArgs e) { if (Regex.IsMatch(ShiftStepBox.Text, "^\\d+$")) { EncryptedText.Content = ""; DecryptedText.Content = ""; CaesarCipher caesarCipher = new CaesarCipher(); string temp = caesarCipher.Encrypt(InputStringToEncodeBox.Text, Convert.ToInt32(ShiftStepBox.Text)); if (temp == null) { MessageBox.Show("Неверный ввод строки для шифрования.", "Ошибка"); } else { EncryptedText.Content = "Encrypted string: " + temp; } } }
public string Encrypt(string plainText) { string cipherText = plainText; CaesarCipher caesarCipher = new CaesarCipher(); caesarCipher.SetKey(CAESAR_CIPHER_KEY); cipherText = caesarCipher.Encrypt(cipherText); AffineCipher affineCipher = new AffineCipher(); affineCipher.SetKeys(new int[] { AFFINE_CIPHER_KEY_A, AFFINE_CIPHER_KEY_B }); cipherText = affineCipher.Encrypt(cipherText); SimpleSubstitutionCipher simpleSubstitutionCipher = new SimpleSubstitutionCipher(); simpleSubstitutionCipher.SetKey(SIMPLE_SUBSTITUTION_CIPHER_KEY); cipherText = simpleSubstitutionCipher.Encrypt(cipherText); return(cipherText); }
public IActionResult CaesarEncrypt([FromBody] CaesarCipherViewModel viewModel) { CaesarCipher cipher = new CaesarCipher(viewModel.Key) { Alphabet = Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType) }; cipher.Alphabet = Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType); string encrypted = ""; try { encrypted = cipher.Encrypt(viewModel.Message); } catch (NullReferenceException) { } catch (Exception) { return(BadRequest(new { Result = false, Message = Text.InvalidCharacter })); } return(Json(encrypted)); }
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; }
public static string CaesarDecrypt(this string value, int key) { var caesarCipher = new CaesarCipher(); return(caesarCipher.Encrypt(value, -key)); }
private void Encrypt_Click(object sender, RoutedEventArgs e) { a = Int32.Parse(ATextBox.Text); b = Int32.Parse(BTextBox.Text); var fullAlfabet = alfabet + alfabet.ToLower(); var cipher = new CaesarCipher(); //[А-ЩЬЮЯҐЄІЇа-щьюяґєії] if ((a >= 0) && (a < int.Parse(To_TextBox.Text)) && (b >= 0) && (b < int.Parse(To_TextBox.Text))) { Validation_Label.Content = "Valid"; Validation_Label.Background = new SolidColorBrush(Colors.Green); } else { Validation_Label.Content = "Not Valid"; Validation_Label.Background = new SolidColorBrush(Colors.Red); } if (Language_Box.Text == "Ukrainian") { if (Regex.IsMatch(textbox.Text, "[А-ЩЬЮЯҐЄІЇа-щьюяґєії]")) { Validation_Label_Message.Content = "Valid"; Validation_Label_Message.Background = new SolidColorBrush(Colors.Green); } else { Validation_Label_Message.Content = "Not Valid"; Validation_Label_Message.Background = new SolidColorBrush(Colors.Red); } } else if (Language_Box.Text == "English") { if (Regex.IsMatch(textbox.Text, "[a-zA-Z]")) { Validation_Label_Message.Content = "Valid"; Validation_Label_Message.Background = new SolidColorBrush(Colors.Green); } else { Validation_Label_Message.Content = "Not Valid"; Validation_Label_Message.Background = new SolidColorBrush(Colors.Red); } } else { Validation_Label_Message.Content = "Not Valid"; Validation_Label_Message.Background = new SolidColorBrush(Colors.Red); } if (Validation_Label.Content == "Not Valid" || Validation_Label_Message.Content == "Not Valid") { MessageBox.Show("Check your input again!"); } else if (Validation_Label.Content == "Valid" || Validation_Label_Message.Content == "Valid") { if (buttin1Clicked == true) { Encrypted_text.Text = cipher.Encrypt(textbox.Text, a, b, alfabet); } else if (button2Clicked == true) { c = Int32.Parse(CTextBox.Text); Encrypted_text.Text = cipher.Encrypt3d(textbox.Text, a, b, c, alfabet); } } }
public string Encrypt(string plainText, ProductionCipherKey productionCipherKey) { return(xorCipher.Encrypt(rotateCipher.Encrypt(caesarCipher.Encrypt(plainText, productionCipherKey.ReplaceKey), productionCipherKey.RotateKey), productionCipherKey.Password)); }