private void Shift_Click(object sender, EventArgs e) { CaesarCipher plainToCipher = new CaesarCipher(); if (mode == true) { try { cipherText.Text = plainToCipher.CipherAllCharacter(Convert.ToInt16(shiftText.Text), plainText.Text); } catch (Exception execeptionOne) { MessageBox.Show("Please fill in all blanks.\n-----------------------\n" + execeptionOne.ToString()); } } else { try { cipherText.Text = plainToCipher.CipherAlphabetOnly(Convert.ToInt16(shiftText.Text), plainText.Text); } catch (Exception execeptionTwo) { MessageBox.Show("Please fill in all blanks.\n-----------------------\n" + execeptionTwo.ToString()); } } }
// "Onayla" butonuna basılınca program çalışıyor private void buton1_Click(object sender, EventArgs e) { // Eğer textbox'lar boş değilse program başlıyor if (txtAnahtarSayi.Text != "" && txtYaziSifre.Text != "") { // Anahtar sayı olarak byte girilmediğinde program hata vereceği için, programın geri kalanını try içine yazdım try { // Yazdığım sınıftan bir nesne oluşturuyorum. Eğer anahtar sayı byte'a çevrilirken hata verirse program catch'e atlıyor CaesarCipher sezar = new CaesarCipher(byte.Parse(txtAnahtarSayi.Text), txtYaziSifre.Text); // Nesnenin "Sifrele" metodunu kullanarak yazıyı şifreliyorum ve textbox'a yazdırıyorum. txtSifrelenenYazi.Text = sezar.Sifrele(); } // Eğer girilen değer byte değilse ekrana uyarı mesajı yazdırıyorum catch { MessageBox.Show("Lütfen anahtar sayıya 0 ile 255 arasında bir değer giriniz."); } } // Eğer kutular boşsa ekrana uyarı mesajı yazdırıyorum else { MessageBox.Show("Lütfen kutuları boş bırakmayınız."); } }
static void Main(string[] args) { var cc = new CaesarCipher(); Console.WriteLine(cc.Encode("Hello, World!", 4)); Console.ReadLine(); }
static void Main(string[] args) { string input = "SampleInput"; int shift = 12; string encode = CaesarCipher.Encode(input, shift); string decode = CaesarCipher.Decode(encode, shift); Console.WriteLine($"Input: {input}"); Console.WriteLine($"Encoded Input: {encode}"); Console.WriteLine($"Decoded Input: {decode}"); }
private static void Main(string[] args) { string plainText = "Attack at night with all forces"; string cipherText = "dwwdfn dw qljkw zlwk doo irufhv"; char[] cipher; Console.WriteLine("Cipher text : "); foreach (var item in cipherText) { Console.Write(item); } Console.WriteLine(); Console.WriteLine("Plain text : "); //cipher = CaesarCipher.Encrypt(plainText, 3); foreach (var item in CaesarCipher.Decrypt(cipherText, 3)) { Console.Write(item); } Console.WriteLine(); }
static void Main(string[] args) { string continueResp = "yes"; string filepath; while (continueResp.Equals("yes", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Select an operation:\n1)Encypt\n2)Decrypt\n3)Quit"); int op = Convert.ToInt32(Console.ReadLine()); switch (op) { case (int)Operations.Encrypt: Console.WriteLine("Enter the filepath of the file: "); filepath = Console.ReadLine(); try { if (File.Exists(filepath)) { Console.WriteLine("Encrypting file..."); var msgToEncrypt = File.ReadAllText(filepath); var encryptedMsg = CaesarCipher.Encrypt(msgToEncrypt); var encryptedFile = filepath.Replace(".txt", "Encrypted.txt"); File.WriteAllText(encryptedFile, encryptedMsg); Console.WriteLine(encryptedMsg); } else { Console.WriteLine("File does not exist. Try again"); } } catch (Exception e) { Console.WriteLine(e.Message); continue; } break; case (int)Operations.Decrypt: Console.WriteLine("Enter the filepath of the file: "); filepath = Console.ReadLine(); try { if (File.Exists(filepath)) { Console.WriteLine("Decrypting file..."); var msgToDecrypt = File.ReadAllText(filepath); var decryptedMsg = CaesarCipher.Decrypt(msgToDecrypt); var decryptedFile = filepath.Replace(".txt", "Decrypted.txt"); File.WriteAllText(decryptedFile, decryptedMsg); Console.WriteLine(decryptedMsg); } else { Console.WriteLine("File does not exist. Try again"); } } catch (Exception e) { Console.WriteLine(e.Message); continue; } break; case (int)Operations.Quit: Environment.Exit(1); break; default: Console.WriteLine("Invalid operation. Try again.\n"); continue; } Console.WriteLine("Continue operations (yes/no)?"); continueResp = Console.ReadLine(); } }