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();
        }
示例#2
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            string plaintext = txtPlaintext.Text,
                   key       = txtKey.Text;

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

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

            /* ENCRYPTING */
            if (rdioCeasar.Checked)
            {
                txtCiphertext.Text = Ceasar.encrypt(plaintext, int.Parse(key));
            }
            else if (rdioPlayfair.Checked)
            {
                txtCiphertext.Text = Playfair.encrypt(plaintext, key);
            }
            else if (rdioVigenereRe.Checked)
            {
                txtKey.Text        = Vigenere.formulateKey(plaintext, key, VigenereType.REPEATING_KEY);
                txtCiphertext.Text = Vigenere.encrypt(plaintext, txtKey.Text);
            }
            else if (rdioVigenereAuto.Checked)
            {
                txtKey.Text        = Vigenere.formulateKey(plaintext, key, VigenereType.AUTO_KEY);
                txtCiphertext.Text = Vigenere.encrypt(plaintext, txtKey.Text);
            }
            else if (rdioRC4.Checked)
            {
                txtCiphertext.Text = RC4.encrypt(plaintext, key);
            }
            else if (rdioMD5.Checked)
            {
                txtCiphertext.Text = MD5.getHash(plaintext).ToLower();
            }

            //Second part:
            else if (rdioMonoalphabetic.Checked)
            {
                txtCiphertext.Text = new MonoAlpha(plaintext, key).Encrypt();
            }
            else if (rdioHill.Checked)
            {
                txtCiphertext.Text = new HillCipher(plaintext, key).Encrypt();
            }
            else if (rdioRailFence.Checked)
            {
                txtCiphertext.Text = new RailFence(plaintext, int.Parse(key)).Encrypt();
            }
            else if (rdioColumnar.Checked)
            {
                txtCiphertext.Text = new Colum(plaintext, Helpers.getIntArray(key)).Encrypt();
            }

            //Third part:
            else if (rdioDES.Checked)
            {
                txtCiphertext.Text = new Des(Helpers.removeDashes(key), Helpers.removeDashes(plaintext), 1).Encode();
            }
            else if (rdioTripleDES.Checked)
            {
                txtCiphertext.Text = new TripleDes(Helpers.removeDashes(plaintext), Helpers.removeDashes(key.Split(' ')), 1).encrypt();
            }
        }