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();
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 3
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();
            }
        }