private void test()
        {
            string enc, dec, key, result;

            enc = Ceasar.encrypt("Haz-em", 3);
            dec = Ceasar.decrypt(enc, 3);

            enc = Playfair.encrypt("Hazem", "playfairexample");
            dec = Playfair.decrypt(enc, "playfairexample");

            key = Vigenere.formulateKey("Haz-em", "bla", VigenereType.AUTO_KEY);
            enc = Vigenere.encrypt("Haz-em", key);
            dec = Vigenere.decrypt(enc, key);

            enc = RC4.encrypt("Hazem", "ehm");
            dec = RC4.decrypt(enc, "ehm");

            result = MD5.getHash("Hazem AbuMostafa").ToLower();
        }
Beispiel #2
0
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            string ciphertext = txtCiphertext.Text,
                   key        = txtKey.Text;

            /* CATCHING ERRORS */
            if (!everythingIsFine())
            {
                return;
            }

            if (ciphertext.Length == 0)
            {
                return;
            }

            /* DECRYPTING */
            if (rdioCeasar.Checked)
            {
                txtPlaintext.Text = Ceasar.decrypt(ciphertext, int.Parse(key));
            }
            else if (rdioPlayfair.Checked)
            {
                txtPlaintext.Text = Playfair.decrypt(ciphertext, key);
            }
            else if (rdioVigenereRe.Checked)
            {
                txtKey.Text       = Vigenere.formulateKey(ciphertext, key, VigenereType.REPEATING_KEY);
                txtPlaintext.Text = Vigenere.decrypt(ciphertext, txtKey.Text);
            }
            else if (rdioVigenereAuto.Checked)
            {
                txtKey.Text       = Vigenere.formulateKey(ciphertext, key, VigenereType.AUTO_KEY);
                txtPlaintext.Text = Vigenere.decrypt(ciphertext, txtKey.Text);
            }
            else if (rdioRC4.Checked)
            {
                txtPlaintext.Text = RC4.decrypt(ciphertext, key);
            }

            //Second part:
            else if (rdioMonoalphabetic.Checked)
            {
                txtPlaintext.Text = new MonoAlpha(ciphertext, key).Decrypt();
            }
            else if (rdioHill.Checked)
            {
                try { txtPlaintext.Text = new HillCipher(ciphertext, key).Decrypt(); }
                catch (Exception) { showMessage("Bad key", "Can't find an inverse for the determinant of the key."
                                                + "\nPlease decrypt with another key."); }
            }
            else if (rdioRailFence.Checked)
            {
                txtPlaintext.Text = new RailFence(ciphertext, int.Parse(key)).Decrypt();
            }
            else if (rdioColumnar.Checked)
            {
                txtPlaintext.Text = new Colum(ciphertext, Helpers.getIntArray(key)).Decrypt();
            }

            //Third part:
            else if (rdioDES.Checked)
            {
                txtPlaintext.Text = new Des(Helpers.removeDashes(key), Helpers.removeDashes(ciphertext), 1).decode();
            }
            else if (rdioTripleDES.Checked)
            {
                txtPlaintext.Text = new TripleDes(Helpers.removeDashes(ciphertext), Helpers.removeDashes(key.Split(' ')), 1).decrypt();
            }
        }