예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            string       fileresult     = "";
            FileStream   myStream       = new FileStream(find.Text, FileMode.Open, FileAccess.Read); //打开文件,把文件读取到string变量
            StreamReader myStreamReader = new StreamReader(find.Text, System.Text.Encoding.Default);
            string       fileContent;

            fileContent = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            if (find.Text.Trim() != string.Empty)
            {
                if (key.Text.Trim() != string.Empty)
                {
                    if (DES.Checked == true)
                    {
                        fileresult = DEScipher.Decrypt(fileContent, key.Text);
                    }
                    else if (AES.Checked == true)
                    {
                        //byte[] encryptB = Encoding.UTF8.GetBytes(ciphertext1.ToString());
                        byte[] decryptBytes = AEScipher.AESDecrypt(encryptBytes, key.Text);
                        fileresult = Encoding.UTF8.GetString(decryptBytes);
                    }
                    else if ((test.Checked == true) && (m.Text.Trim() != string.Empty) && (int.Parse(m.Text) >= 3))
                    {
                        fileresult = NDes.NDes.NDESDecrypt(fileContent, key.Text, m.Text);
                    }
                }
                else
                {
                    MessageBox.Show(this, "Please Input the Key!", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(this, "Please choose the file to be decrypt!", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            FileStream   myStreamr      = new FileStream(save.Text, FileMode.Create, FileAccess.Write); //创建一个文件,把字符串写入文件
            StreamWriter myStreamWriter = new StreamWriter(myStreamr);

            myStreamWriter.Write(fileresult);
            myStreamWriter.Close();
        }
예제 #2
0
 private void Decrypt_Click(object sender, EventArgs e)
 {
     if (DES.Checked == false && AES.Checked == false && test.Checked == false)
     {
         MessageBox.Show("You must choose a cipher method!", "Oops!", MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
     }
     else if (key.Text == null)
     {
         MessageBox.Show("You must enter decryption key!", "Oops!", MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
     }
     else
     {
         if (ciphertext.Text == null)
         {
             MessageBox.Show("Please enter the text need to be decrypt.", "Tips", MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
         }
         else
         {
             if (DES.Checked == true)
             {
                 plaintext1.Text = DEScipher.Decrypt(ciphertext.Text, key.Text);
             }
             else if (AES.Checked == true)
             {
                 //byte[] encryptB = Encoding.UTF8.GetBytes(ciphertext1.ToString());
                 byte[] decryptBytes = AEScipher.AESDecrypt(encryptBytes, key.Text);
                 plaintext1.Text = Encoding.UTF8.GetString(decryptBytes);
             }
             else if ((test.Checked == true) && (m != null) && (int.Parse(m.Text.ToString()) >= 3))
             {
                 string decipherresult_ndes = NDes.NDes.NDESDecrypt(ciphertext.Text, key.Text, m.Text);
                 plaintext1.Text = decipherresult_ndes;
             }
         }
     }
 }
예제 #3
0
 private void detext_Click(object sender, EventArgs e)
 {
     if (name.SelectedItem.ToString() == "RSA")
     {
         Key.Text       = skey[1];
         Plaintext.Text = RSAcipher.DecryptString(Cyphertext.Text, skey[1]);
     }
     if (Cyphertext.Text.Trim() != string.Empty)
     {
         if (Key.Text.Trim() != string.Empty)
         {
             if (name.SelectedItem.ToString() == "Caesar cipher")
             {
                 int k = Convert.ToInt32(this.Key.Text);
                 Plaintext.Text = Caecar.Caecarcipher.DeCaesar(Cyphertext.Text, k);
             }
             else if (name.SelectedItem.ToString() == "DES")
             {
                 Plaintext.Text = DEScipher.Decrypt(Cyphertext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "Permutation cipher")
             {
                 if (order.Text.ToString() != string.Empty)
                 {
                     Plaintext.Text = permutation.permutationcipher.decrypt(Cyphertext.Text, order.Text, Convert.ToInt32(Key.Text));
                 }
                 else
                 {
                     MessageBox.Show(this, "请输入密钥顺序!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else if (name.SelectedItem.ToString() == "AutoKey cipher")
             {
                 Plaintext.Text = Autokeycipher.decryption(Cyphertext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "Keyword cipher")
             {
                 Plaintext.Text = Keywordcipher.decrypt(Cyphertext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "Vigenere cipher")
             {
                 Plaintext.Text = Vigenere.Vigenere.decrypt(Cyphertext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "Playfair cipher")
             {
                 Plaintext.Text = playfair.Program.Decrypt(Cyphertext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "CA")
             {
                 if (order.Text.ToString() != string.Empty)
                 {
                     Plaintext.Text = CA.CA.decrypt(Cyphertext.Text, order.Text, Convert.ToInt32(Key.Text));
                 }
                 else
                 {
                     MessageBox.Show(this, "请输入二进制密钥流!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else if (name.SelectedItem.ToString() == "Column cipher")
             {
                 Plaintext.Text = Column.Column.decrypt(Cyphertext.Text, Key.Text);
             }
         }
         else
         {
             MessageBox.Show(this, "请输入密钥!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show(this, "请输入要解密的文本!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }