Exemple #1
0
        private string decryptText(string s)
        {
            if (lbCiphers.SelectedItem == null)
            {
                MessageBox.Show("Please select a cipher to use!", "Warning!");
                return(null);
            }

            switch (lbCiphers.SelectedItem.ToString())
            {
            case "Rail-Fence":
                plainText = RailFence.decrypt(s, tbKey.Text);
                break;

            case "DES":
                if (tbKey.Text.Length == 8)
                {
                    plainText = DES.decrypt(s, tbKey.Text);
                }
                else
                {
                    MessageBox.Show("Please type a key of size 8");
                }
                break;

            case "RSA":
                plainText = RSA.decrypt(s);
                break;

            default:
                break;
            }
            return(plainText);
        }
Exemple #2
0
        private string encryptText(string s) //function to select correct cipher algorithm. Chance to add more ciphers in the future
        {
            if (lbCiphers.SelectedItem == null)
            {
                MessageBox.Show("Please select a cipher to use!", "Warning!");
                return(null);
            }
            if (s.Length <= 0)
            {
                MessageBox.Show("Please type plain text to encrypt");
                return(null);
            }

            switch (lbCiphers.SelectedItem.ToString())
            {
            case "Rail-Fence":
                cipherText = RailFence.encrypt(s, tbKey.Text);
                break;

            case "DES":
                if (tbKey.Text.Length == 8)
                {
                    cipherText = DES.encrypt(s, tbKey.Text);
                }
                else
                {
                    MessageBox.Show("Please type a key of size 8");
                }
                break;

            case "RSA":
                cipherText = RSA.encrypt(s);
                break;

            default:
                break;
            }
            return(cipherText);
        }