public string encryptGronsfeld(string _plainText, int _key) { string cipherText = null; bool lowercase = false; string cipherChar = null; int letterNum = 0; // use algorithm from Caesar cipher because gronsfeld is just a modified caesar // cipher Caesar modifiedCaesar = new Caesar(); try { // loop through each digit within the key for (int x = 0; x < (_plainText.Length / Convert.ToInt32(Math.Abs(_key).ToString().Length)) + 1; x++) { for (int y = 0; y < Convert.ToInt32(Math.Abs(_key).ToString().Substring(Math.Abs(_key).ToString().Length - 1)); y++) { // pass the character and the correspoinding number from the key to // Caesar.encryption cipherText = modifiedCaesar.encryption(Convert.ToChar(_plainText.Substring(letterNum, 1)), lowercase, cipherChar, -Convert.ToInt32(Math.Abs(_key).ToString().Substring(y, 1))); letterNum++; } } } catch (Exception) { //lazy error handling } return(cipherText); }
//encryption private void шифруванняToolStripMenuItem_Click(object sender, EventArgs e) { switch (number_decryption) { case 1: Caesar encryption_Caesar = new Caesar(); richTextBox1.Text = encryption_Caesar.encryption(richTextBox1.Text); break; case 2: Tritemius encryption_Tritemius = new Tritemius(); richTextBox1.Text = encryption_Tritemius.encryption(richTextBox1.Text, false); break; case 3: gamm encryption_Gamm = new gamm(); richTextBox1.Text = encryption_Gamm.encryption(richTextBox1.Text); //label1.Text = encryption_Gamm.str_key(); break; case 4: Book_code encryption_Book_code = new Book_code(); richTextBox1.Text = encryption_Book_code.encryption(richTextBox1.Text); break; case 5: DES encryption_DES = new DES(); richTextBox1.Text = encryption_DES.encryption(richTextBox1.Text, cryptic.Key, cryptic.IV); break; case 0: MessageBox.Show("Виберіть метод шифрування", "Error:", MessageBoxButtons.OK); break; } }
//encryption private void шифруванняToolStripMenuItem_Click(object sender, EventArgs e) { switch (number_decryption) { case 1: Caesar encryption_Caesar = new Caesar(); richTextBox1.Text = encryption_Caesar.encryption(richTextBox1.Text); break; case 2: Tritemius encryption_Tritemius = new Tritemius(); richTextBox1.Text = encryption_Tritemius.encryption(richTextBox1.Text, false); break; case 3: gamm encryption_Gamm = new gamm(); richTextBox1.Text = encryption_Gamm.encryption(richTextBox1.Text); //label1.Text = encryption_Gamm.str_key(); break; case 4: Book_code encryption_Book_code = new Book_code(); richTextBox1.Text = encryption_Book_code.encryption(richTextBox1.Text); break; case 5: DES encryption_DES = new DES(); richTextBox1.Text = encryption_DES.encryption(richTextBox1.Text, cryptic.Key, cryptic.IV); break; case 6: Backpack encryption_Backpack = new Backpack(); richTextBox1.Text = encryption_Backpack.encryption(richTextBox1.Text); break; case 7: RSA encryption_RSA = new RSA(); Book_code_Form q = new Book_code_Form(); q.Get_button4_Visible(false); q.ShowDialog(); string st_key = q.Get_Key_backpack(); richTextBox1.Text = encryption_RSA.encryption(richTextBox1.Text, st_key); RSA = encryption_RSA.Encrypti_byte; label1.Text = rsa.ToXmlString(false) + "\n" + rsa.ToXmlString(true); //label1.Visible = true; break; case 0: MessageBox.Show("Виберіть метод шифрування", "Error:", MessageBoxButtons.OK); break; } }