public string decrypt()
        {
            Des D3 = new Des(keys[2], input, mode);
            Des D2 = new Des(keys[1], D3.decode().Replace("-", ""), mode);
            Des D1 = new Des(keys[0], D2.Encode().Replace("-", ""), mode);

            return(D1.decode());
        }
Exemple #2
0
        private bool everythingIsFine()
        {
            if (rdioCeasar.Checked)
            {
                try{
                    int.Parse(txtKey.Text);
                } catch {
                    showMessage("Wrong key", "Key must be integer in Ceasar.");
                    return(false);
                }
            }
            else if (rdioPlayfair.Checked)
            {
                //TODO: Check for out-of-alphabet characters in key.
            }
            else if (rdioMonoalphabetic.Checked && txtKey.Text.Length != 26)
            {
                showMessage("Wrong key", "Key must be of exact 26 characters in Monoalphabetic.");
                return(false);
            }
            else if (rdioHill.Checked && txtKey.Text.Length != 4)
            {
                showMessage("Wrong key", "Key must be of exact 4 characters (2x2) in Hill.");
                return(false);
            }
            else if (rdioRailFence.Checked)
            {
                try{
                    int.Parse(txtKey.Text);
                } catch {
                    showMessage("Wrong key", "Key must be an integer in Rail Fence.");
                    return(false);
                }
            }
            else if (rdioColumnar.Checked)
            {
                try{
                    Helpers.getIntArray(txtKey.Text);
                } catch {
                    showMessage("Wrong key", "Key must be an array of integers, separated by spaces in Columnar.");
                    return(false);
                }
            }
            else if (rdioDES.Checked)
            {
                try{
                    Des.HexToByteArray(Helpers.removeDashes(txtKey.Text));
                } catch {
                    showMessage("Wrong key", "Key must be a valid hex value in DES.");
                    return(false);
                }
                try{
                    Des.HexToByteArray(Helpers.removeDashes(txtPlaintext.Text));
                } catch {
                    showMessage("Wrong key", "Plaintext must be a valid hex value in DES.");
                    return(false);
                }
                if (Helpers.removeDashes(txtKey.Text).Length != 16)
                {
                    showMessage("Wrong key", "Key must be a hex of exact 16 digit in DES.");
                    return(false);
                }
            }
            else if (rdioTripleDES.Checked)
            {
                string[] keys = txtKey.Text.Split(' ');

                if (keys.Length != 3)
                {
                    showMessage("Wrong key", "Key must consist of 3 hex keys separated by spaces in Triple-DES.");
                    return(false);
                }
                try{
                    foreach (string key in keys)
                    {
                        Des.HexToByteArray(Helpers.removeDashes(key));
                    }
                } catch {
                    showMessage("Wrong key", "Each key must be a valid hex value in DES.");
                    return(false);
                }
                try{
                    Des.HexToByteArray(Helpers.removeDashes(txtPlaintext.Text));
                } catch {
                    showMessage("Wrong key", "Plaintext must be a valid hex value in DES.");
                    return(false);
                }
                foreach (string key in keys)
                {
                    if (Helpers.removeDashes(key).Length != 16)
                    {
                        showMessage("Wrong key", "Each key must be a hex of exact 16 digit in DES.");
                        return(false);
                    }
                }
            }
            //TODO: Check when (key.Length == 0) for algorithms that require that.

            return(true);
        }