public static void AutoKeyCipherTest() { Console.WriteLine("6. Шифр с автоключом"); // Использование текста в качестве ключа Console.WriteLine("\nИспользование текста в качестве ключа"); Console.WriteLine("Пример работы программы"); cryptogram = "SENDSUPPLIES"; Console.WriteLine("Текст: " + cryptogram); string key = "COMET"; autoKeyCipher = new AutoKeyCipher(key, AutoKeyCipherType.UseText); encryptText = autoKeyCipher.Encrypt(cryptogram); Console.WriteLine("Ключ: " + key); Console.WriteLine("Зашифрованый текст: " + encryptText); decryptText = autoKeyCipher.Decrypt(encryptText); Console.WriteLine("Расшифрованый текст: " + decryptText); // Использование криптограмы текста в качестве ключа Console.WriteLine("\nИспользование криптограмы текста в качестве ключа"); Console.WriteLine("Пример работы программы"); cryptogram = "SENDSUPPLIES"; Console.WriteLine("Текст: " + cryptogram); key = "COMET"; autoKeyCipher = new AutoKeyCipher(key, AutoKeyCipherType.UseCryptogram); encryptText = autoKeyCipher.Encrypt(cryptogram); Console.WriteLine("Ключ: " + key); Console.WriteLine("Зашифрованый текст: " + encryptText); decryptText = autoKeyCipher.Decrypt(encryptText); Console.WriteLine("Расшифрованый текст: " + decryptText); Console.WriteLine("\n"); }
public static string AutoKeyCipher(string text, string key, ref string generateKey, ref AutoKeyCipher autoKeyCipher, AutoKeyCipherType autoKeyCipherType, CryptType cryptType) { string result = string.Empty; if (autoKeyCipher == null) autoKeyCipher = new AutoKeyCipher(key, autoKeyCipherType); switch (cryptType) { case CryptType.Encrypt: result = autoKeyCipher.Encrypt(text); generateKey = autoKeyCipher.PrimaryKey; break; case CryptType.Decrypt: result = autoKeyCipher.Decrypt(text); generateKey = autoKeyCipher.PrimaryKey; break; } return result; }
private void EncryptButton_Click(object sender, System.EventArgs e) { switch ((CipherType)this.CipherTypeComboBox.SelectedIndex) { case CipherType.SubstitutionCipher: this.OutputTextRichTextBox.Text = LogicCipher.SubstitutionCipher( this.InputTextRichTextBox.Text, int.Parse(this.CountSubstitutionNumericUpDown.Value.ToString(CultureInfo.InvariantCulture)), CryptType.Encrypt); break; case CipherType.TranspositionCipher: this.OutputTextRichTextBox.Text = LogicCipher.TranspositionCipher( this.InputTextRichTextBox.Text, this.KeyTextBox.Text, CryptType.Encrypt); break; case CipherType.VigenereCipher: var vigenereCipherType = VigenereCipherType.None; if (this.StraightCheckBox.Checked) { vigenereCipherType = VigenereCipherType.Straight; } if (this.ReverseCheckBox.Checked) { vigenereCipherType = VigenereCipherType.Reverse; } this.OutputTextRichTextBox.Text = LogicCipher.VigenereCipher( this.InputTextRichTextBox.Text, this.KeyTextBox.Text, vigenereCipherType, CryptType.Encrypt); break; case CipherType.VermanCipher: this.vermanCipher = new VermanCipher(int.Parse(this.CountSubstitutionNumericUpDown.Value.ToString(CultureInfo.InvariantCulture))); this.OutputTextRichTextBox.Text = LogicCipher.VermanCipher( this.InputTextRichTextBox.Text, int.Parse(this.CountSubstitutionNumericUpDown.Value.ToString(CultureInfo.InvariantCulture)), out this.showText, ref this.vermanCipher, CryptType.Encrypt); this.ShowDialogButton.Enabled = true; break; case CipherType.RunningKeyCipher: this.OutputTextRichTextBox.Text = LogicCipher.RunningKeyCipher( this.InputTextRichTextBox.Text, this.KeyTextBox.Text, CryptType.Encrypt); break; case CipherType.CaesarCipher: this.OutputTextRichTextBox.Text = LogicCipher.CaesarCipher( this.InputTextRichTextBox.Text, int.Parse(this.CountSubstitutionNumericUpDown.Value.ToString(CultureInfo.InvariantCulture)), CryptType.Encrypt); break; case CipherType.NGrammarSubstitutionCipher: this.grammarSubstitutionCipher = new NGrammarSubstitutionCipher(); this.OutputTextRichTextBox.Text = LogicCipher.NGrammarSubstitutionCipher( this.InputTextRichTextBox.Text, out this.showText, ref this.grammarSubstitutionCipher, CryptType.Encrypt); this.ShowDialogButton.Enabled = true; break; case CipherType.PlayFairCipher: this.OutputTextRichTextBox.Text = LogicCipher.PlayFairCipher( this.InputTextRichTextBox.Text, CryptType.Encrypt); break; case CipherType.AutoKeyCipher: var keyCipherType = AutoKeyCipherType.UseText; if (this.StraightCheckBox.Checked) { keyCipherType = AutoKeyCipherType.UseText; } if (this.ReverseCheckBox.Checked) { keyCipherType = AutoKeyCipherType.UseCryptogram; } this.autoKeyCipher = new AutoKeyCipher(this.KeyTextBox.Text, keyCipherType); this.OutputTextRichTextBox.Text = LogicCipher.AutoKeyCipher( this.InputTextRichTextBox.Text, this.KeyTextBox.Text, ref this.showText, ref this.autoKeyCipher, keyCipherType, CryptType.Encrypt); this.ShowDialogButton.Enabled = true; break; case CipherType.FractionalCipher: this.OutputTextRichTextBox.Text = LogicCipher.FractionalCipher( this.InputTextRichTextBox.Text, CryptType.Encrypt); break; } }