Ejemplo n.º 1
0
        //Decrypt
        public string Decrypt(string inputText, int key)
        {
            key1          = key;
            key2          = (int)Math.Floor((double)(key1 * inputText.Length / 10));
            substitution  = new Rot(key);
            transposition = new Transposition(key);
            string transText;
            string outputText;

            transText  = substitution.Decrypt(inputText);
            outputText = transposition.Decrypt(transText);
            return(outputText);
        }
Ejemplo n.º 2
0
        //Start Encrypt & DecryptS
        private void Start_Click(object sender, EventArgs e)
        {
            #region  Caesar Encrypt & Decrypt
            if (DropDown.SelectedIndex == 1 && Encrypt.Checked == true)
            {
                Output.Text = activeSub.Encrypt(Input.Text);
            }
            if (DropDown.SelectedIndex == 1 && Decrypt.Checked == true)
            {
                Output.Text = activeSub.Decrypt(Input.Text);
            }
            #endregion
            #region Rot Encrypt & Decrypt
            if (DropDown.SelectedIndex == 2 && Encrypt.Checked == true)
            {
                activeSub   = new Rot(Convert.ToInt32(CustomParameter.Text));
                Output.Text = activeSub.Encrypt(Input.Text);
            }
            if (DropDown.SelectedIndex == 2 && Decrypt.Checked == true)
            {
                activeSub   = new Rot(Convert.ToInt32(CustomParameter.Text));
                Output.Text = activeSub.Decrypt(Input.Text);
            }
            #endregion
            #region Rot13 Encrypt & Decrypt
            if (DropDown.SelectedIndex == 3 && Encrypt.Checked == true)
            {
                Output.Text = activeSub.Encrypt(Input.Text);
            }
            if (DropDown.SelectedIndex == 3 && Decrypt.Checked == true)
            {
                Output.Text = activeSub.Decrypt(Input.Text);
            }
            #endregion
            #region Vigenere Encrypt & Decrypt
            if (DropDown.SelectedIndex == 4 && Encrypt.Checked == true)
            {
                Output.Text = v.Encrypt(Input.Text, CustomParameter.Text);
            }
            if (DropDown.SelectedIndex == 4 && Decrypt.Checked == true)
            {
                Output.Text = v.Decrypt(Input.Text, CustomParameter.Text);
            }
            #endregion
            #region Transposition Encrypt & Decrypt
            if (DropDown.SelectedIndex == 5 && Encrypt.Checked == true)
            {
                t           = new Transposition(Convert.ToInt32(CustomParameter.Text));
                Output.Text = t.Encrypt(Input.Text);
            }
            if (DropDown.SelectedIndex == 5 && Decrypt.Checked == true)
            {
                t           = new Transposition(Convert.ToInt32(CustomParameter.Text));
                Output.Text = t.Decrypt(Input.Text);
            }
            #endregion
            #region AES Encrypt & Decrypt
            if (DropDown.SelectedIndex == 6 && Encrypt.Checked == true)
            {
                //Variables
                string key = CustomParameter.Text;
                string IV  = CustomParameterTwo.Text;

                //Vailid Key and IV length ?
                if (key.Length != 32 || IV.Length != 16)
                {
                    MessageBox.Show("Invaild Key or IV. IV Size: 16, Key Size: 32");
                }

                //Encrpt Text
                AES_CBC aes = new AES_CBC(key, IV);

                Output.Text = aes.Encrypt(Input.Text);
            }
            if (DropDown.SelectedIndex == 6 && Decrypt.Checked == true)
            {
                //Variables
                string key = CustomParameter.Text;
                string IV  = CustomParameterTwo.Text;

                //Vailid Key and IV length?
                if (key.Length != 32 || IV.Length != 16)
                {
                    MessageBox.Show("Invaild Key or IV. IV Size: 16, Key Size: 32");
                }

                //Decrypt
                AES_CBC aes = new AES_CBC(key, IV);

                try
                {
                    Output.Text = aes.Decrypt(Input.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            #endregion
            #region PaulCryption Encrypt & Decrypt
            if (DropDown.SelectedIndex == 7 && Encrypt.Checked == true)
            {
                Output.Text = pc.Encrypt(Input.Text, Convert.ToInt32(CustomParameter.Text));
            }
            if (DropDown.SelectedIndex == 7 && Decrypt.Checked == true)
            {
                Output.Text = pc.Decrypt(Input.Text, Convert.ToInt32(CustomParameter.Text));
            }
            #endregion
        }