예제 #1
0
        //decryption
        private void дишифруванняToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (number_decryption)
            {
                case 1:
                    Caesar decryption_Caesar = new Caesar();
                    richTextBox1.Text = decryption_Caesar.decryption(richTextBox1.Text);
                    break;

                case 2:
                    Tritemius decryption_Tritemius = new Tritemius();
                    richTextBox1.Text = decryption_Tritemius.decryption(richTextBox1.Text);
                    break;

                case 3:
                    gamm decryption_Gamm = new gamm();
                    richTextBox1.Text = decryption_Gamm.decryption(richTextBox1.Text);
                    break;

                case 4:
                    Book_code decryption_Book_code = new Book_code();
                    richTextBox1.Text = decryption_Book_code.decryption(richTextBox1.Text);
                    break;

                case 5:

                    DES decryption_DES = new DES();
                    richTextBox1.Text = decryption_DES.decryption(richTextBox1.Text, cryptic.Key, cryptic.IV);
                    break;

                case 0:
                    MessageBox.Show("Виберіть метод дешифрування", "Error:", MessageBoxButtons.OK);
                    break;
            }
        }
예제 #2
0
        //encryption
        private void шифруванняToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (number_decryption)
            {
                case 1:
                    Caesar encryption_Caesar = new Caesar();
                    richTextBox1.Text = encryption_Caesar.encryption(richTextBox1.Text);
                    break;

                case 2:
                    Tritemius encryption_Tritemius = new Tritemius();
                    richTextBox1.Text = encryption_Tritemius.encryption(richTextBox1.Text, false);
                    break;

                case 3:
                    gamm encryption_Gamm = new gamm();
                    richTextBox1.Text = encryption_Gamm.encryption(richTextBox1.Text);
                    //label1.Text = encryption_Gamm.str_key();
                    break;

                case 4:
                    Book_code encryption_Book_code = new Book_code();
                    richTextBox1.Text = encryption_Book_code.encryption(richTextBox1.Text);
                    break;

                case 5:
                    DES encryption_DES = new DES();
                    richTextBox1.Text = encryption_DES.encryption(richTextBox1.Text, cryptic.Key, cryptic.IV);
                    break;

                case 0:
                    MessageBox.Show("Виберіть метод шифрування", "Error:", MessageBoxButtons.OK);
                    break;
            } 
        }
예제 #3
0
        public string encryptGronsfeld(string _plainText, int _key)
        {
            string cipherText = null;
            bool   lowercase  = false;
            string cipherChar = null;
            int    letterNum  = 0;

            // use algorithm from Caesar cipher because gronsfeld is just a modified caesar
            // cipher
            Caesar modifiedCaesar = new Caesar();

            try
            {
                // loop through each digit within the key
                for (int x = 0; x < (_plainText.Length / Convert.ToInt32(Math.Abs(_key).ToString().Length)) + 1; x++)
                {
                    for (int y = 0; y < Convert.ToInt32(Math.Abs(_key).ToString().Substring(Math.Abs(_key).ToString().Length - 1)); y++)
                    {
                        // pass the character and the correspoinding number from the key to
                        // Caesar.encryption
                        cipherText = modifiedCaesar.encryption(Convert.ToChar(_plainText.Substring(letterNum, 1)), lowercase, cipherChar, -Convert.ToInt32(Math.Abs(_key).ToString().Substring(y, 1)));
                        letterNum++;
                    }
                }
            }
            catch (Exception)
            {
                //lazy error handling
            }

            return(cipherText);
        }
예제 #4
0
        //encryption
        private void шифруванняToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (number_decryption)
            {
            case 1:
                Caesar encryption_Caesar = new Caesar();
                richTextBox1.Text = encryption_Caesar.encryption(richTextBox1.Text);
                break;

            case 2:
                Tritemius encryption_Tritemius = new Tritemius();
                richTextBox1.Text = encryption_Tritemius.encryption(richTextBox1.Text, false);
                break;

            case 3:
                gamm encryption_Gamm = new gamm();
                richTextBox1.Text = encryption_Gamm.encryption(richTextBox1.Text);
                //label1.Text = encryption_Gamm.str_key();
                break;

            case 4:
                Book_code encryption_Book_code = new Book_code();
                richTextBox1.Text = encryption_Book_code.encryption(richTextBox1.Text);
                break;

            case 5:
                DES encryption_DES = new DES();
                richTextBox1.Text = encryption_DES.encryption(richTextBox1.Text, cryptic.Key, cryptic.IV);
                break;

            case 6:
                Backpack encryption_Backpack = new Backpack();
                richTextBox1.Text = encryption_Backpack.encryption(richTextBox1.Text);
                break;

            case 7:
                RSA            encryption_RSA = new RSA();
                Book_code_Form q = new Book_code_Form();
                q.Get_button4_Visible(false);
                q.ShowDialog();
                string st_key = q.Get_Key_backpack();

                richTextBox1.Text = encryption_RSA.encryption(richTextBox1.Text, st_key);
                RSA         = encryption_RSA.Encrypti_byte;
                label1.Text = rsa.ToXmlString(false) + "\n" + rsa.ToXmlString(true);
                //label1.Visible = true;
                break;

            case 0:
                MessageBox.Show("Виберіть метод шифрування", "Error:", MessageBoxButtons.OK);
                break;
            }
        }
예제 #5
0
        //decryption
        private void дишифруванняToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (number_decryption)
            {
            case 1:
                Caesar decryption_Caesar = new Caesar();
                richTextBox1.Text = decryption_Caesar.decryption(richTextBox1.Text);
                break;

            case 2:
                Tritemius decryption_Tritemius = new Tritemius();
                richTextBox1.Text = decryption_Tritemius.decryption(richTextBox1.Text);
                break;

            case 3:
                gamm decryption_Gamm = new gamm();
                richTextBox1.Text = decryption_Gamm.decryption(richTextBox1.Text);
                break;

            case 4:
                Book_code decryption_Book_code = new Book_code();
                richTextBox1.Text = decryption_Book_code.decryption(richTextBox1.Text);
                break;

            case 5:
                DES decryption_DES = new DES();
                richTextBox1.Text = decryption_DES.decryption(richTextBox1.Text, cryptic.Key, cryptic.IV);
                break;

            case 6:
                Backpack decryption_Backpack = new Backpack();
                richTextBox1.Text = decryption_Backpack.decryption(richTextBox1.Text);
                break;

            case 7:
                RSA decryption_RSA = new RSA();
                decryption_RSA.Encrypti_byte = RSA;
                Book_code_Form q = new Book_code_Form();
                q.Get_button4_Visible(false);
                q.ShowDialog();
                string st_key = q.Get_Key_backpack();

                richTextBox1.Text = decryption_RSA.decryption(richTextBox1.Text, st_key);
                //label1.Visible = false;
                break;

            case 0:
                MessageBox.Show("Виберіть метод дешифрування", "Error:", MessageBoxButtons.OK);
                break;
            }
        }
예제 #6
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            // make sure the user has entered a plain text message
            if (txtPlainText.Text != "" && txtPlainText.Text != " ")
            {
                int    cipher     = cboCipher.SelectedIndex;
                string plainText  = txtPlainText.Text;
                string cipherText = null;

                // instantiate the class for the selected cipher, declare and assign value
                // to a key variable if neccesary, call the encrypt method
                switch (cipher)
                {
                case 0:
                    HashFunction hash = new HashFunction();

                    cipherText = hash.EncrpytHash(plainText);

                    break;

                case 1:
                    Caesar caesar = new Caesar();
                    try
                    {
                        int cKey = Convert.ToInt32(txtKey.Text);

                        cipherText = caesar.EncrpytCaesar(plainText, cKey);
                    }
                    catch (FormatException)
                    {
                        // users must enter a numeric key
                        MessageBox.Show("Please enter a valid encryption key");
                    }
                    break;

                case 2:
                    try {
                        RailFence railFence = new RailFence();
                        int       rKey      = Convert.ToInt32(txtKey.Text);

                        cipherText = railFence.encryptRailFence(plainText, rKey);
                    }
                    catch (FormatException)
                    {
                        // users must enter a numeric key
                        MessageBox.Show("Please enter a valid encryption key");
                    }
                    break;

                case 3:
                    Polybius polybius = new Polybius();

                    cipherText = polybius.encryptPoly(plainText);

                    break;

                case 4:
                    try
                    {
                        Gronsfeld gronsfeld = new Gronsfeld();
                        int       gKey      = Convert.ToInt32(txtKey.Text);

                        cipherText = gronsfeld.encryptGronsfeld(plainText, gKey);
                    }
                    catch (FormatException)
                    {
                        // users must enter a numeric key
                        MessageBox.Show("Please enter a valid encryption key");
                    }
                    break;

                case 5:
                    FourSquare fourSquare = new FourSquare();

                    cipherText = fourSquare.encryptFourSquare(plainText);

                    break;
                }
                // ensure that the message was encrypted
                if (cipherText != null)
                {
                    txtCipherText.Text = cipherText;
                }
            }
            else
            {
                MessageBox.Show("Please enter a message to encrypt");
            }
        }
예제 #7
0
        private void btnDecrpyt_Click(object sender, EventArgs e)
        {
            // make sure the user has entered a cipher text message
            int    cipher     = cboCipher.SelectedIndex;
            int    key        = 0;
            string plainText  = null;
            string cipherText = txtCipherText.Text;

            // instantiate the class for the selected cipher, declare and assign value
            // to a key variable if neccesary, call the decrypt method
            switch (cipher)
            {
            case 0:
                MessageBox.Show("Hash functions cannot be decrypted");

                break;

            case 1:
                try {
                    Caesar dCaesar = new Caesar();
                    key = Convert.ToInt32(txtKey.Text);

                    plainText = dCaesar.EncrpytCaesar(cipherText, -key);
                }
                catch (FormatException)
                {
                    // users must enter a numeric key
                    MessageBox.Show("Please enter a valid encryption key");
                }
                break;

            case 2:
                try {
                    RailFence dRailFence = new RailFence();
                    key = Convert.ToInt32(txtKey.Text);

                    plainText = dRailFence.decryptRailFence(cipherText, key);
                }
                catch (FormatException)
                {
                    // users must enter a numeric key
                    MessageBox.Show("Please enter a valid encryption key");
                }
                break;

            case 3:
                Polybius dPolybius = new Polybius();

                plainText = dPolybius.decryptPoly(cipherText);

                break;

            case 4:
                try {
                    Gronsfeld dGronsfeld = new Gronsfeld();
                    key = Convert.ToInt32(txtKey.Text);

                    plainText = dGronsfeld.encryptGronsfeld(cipherText, -key);
                }
                catch (FormatException)
                {
                    // users must enter a numeric key
                    MessageBox.Show("Please enter a valid encryption key");
                }
                break;
            }

            // ensure that the message was decrypted
            if (cipherText != null)
            {
                txtPlainText.Text = plainText;
            }
        }