public CipherForm() { InitializeComponent(); caesarCipher = new CaesarCipher(); trithemiusCipher = new TrithemiusCipher(); xorEncryptionCipher = new XOREncryptionCipher(); bookCipher = new BookCipher(); theKnapsackProblemCipher = new TheKnapsackProblemCipher(); }
void Cipher_Click(object sender, RoutedEventArgs e) { if (Message.Foreground == Brushes.Gray || string.IsNullOrWhiteSpace(Message.Text)) { MessageBoxError("Message can`t be empty!"); GetAllDefault(key: false); } else if (Key.Foreground == Brushes.Gray || string.IsNullOrWhiteSpace(Key.Text)) { MessageBoxError("Key can`t be empty!"); GetAllDefault(message: false); } else { if (ComboBox.SelectedIndex == 0) { bool isNumber = int.TryParse(Key.Text, out int KeyNumber); if (isNumber) { Result.Foreground = Brushes.Black; if (KeyNumber >= 0 && KeyNumber <= 26) { Result.Text = (bool)CheckBoxDecrypt.IsChecked ? CaesarCipher.Decrypt(Message.Text, KeyNumber) : CaesarCipher.Encrypt(Message.Text, KeyNumber); } else { MessageBoxError("Rotation can`t be longer than 26 or shorter than 0!"); GetAllDefault(message: false); } } else { MessageBoxError("Key must be number!"); GetAllDefault(message: false); } } else { if (Key.Text.Any(x => char.IsWhiteSpace(x) || char.IsNumber(x))) { MessageBoxError("Key should not contain spaces or numbers!"); GetAllDefault(message: false); } else { Result.Foreground = Brushes.Black; Result.Text = (bool)CheckBoxDecrypt.IsChecked ? VigenereCipher.Decrypt(Message.Text, Key.Text) : VigenereCipher.Encrypt(Message.Text, Key.Text); } } } }
private void tryXOREncryptDecrypt(Operation op) { string textToEncrypt = textBox1.Text; if (CaesarCipher.CheckInput(textToEncrypt, out MatchCollection matches)) { textBox1.BackColor = Color.White; CaesarPswForm showPsw = new CaesarPswForm(); if (DialogResult.Cancel == showPsw.ShowDialog(this)) { return; } textBox1.Text = xorEncryptionCipher.XOR(matches[0].Value, Int32.Parse(showPsw.key), op); } else { textBox1.BackColor = Color.LightGoldenrodYellow; MessageBox.Show("Text contain illegal character!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox1.BackColor = Color.White; } }
private void tryThrithemiusEncryptDecrypt(Operation op) { string textToEncrypt = textBox1.Text; if (CaesarCipher.CheckInput(textToEncrypt, out MatchCollection matches)) { textBox1.BackColor = Color.White; TrithemiusPswForm showPsw = new TrithemiusPswForm(); do { if (DialogResult.Cancel == showPsw.ShowDialog(this)) { return; } } while(showPsw.retry); textBox1.Text = trithemiusCipher.Trithemius(matches[0].Value, op, showPsw.TrithemiusKeyArgs); } else { textBox1.BackColor = Color.LightGoldenrodYellow; MessageBox.Show("Text contain illegal character!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox1.BackColor = Color.White; } }