Exemplo n.º 1
0
        private void enfile_Click(object sender, EventArgs e)
        {
            string       fileContent1   = "";
            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 (name.SelectedItem.ToString() == "RSA")
            {
                Key.Text     = skey[0];
                fileContent1 = RSAcipher.EncryptString(fileContent, skey[0]);
            }
            if (find.Text.Trim() != string.Empty)
            {
                if (Key.Text.Trim() != string.Empty)
                {
                    if (name.SelectedItem.ToString() == "Caesar cipher")
                    {
                        int k = Convert.ToInt32(this.Key.Text);
                        fileContent1 = Caecar.Caecarcipher.Caesar(fileContent, k);
                    }
                    else if (name.SelectedItem.ToString() == "DES")
                    {
                        fileContent1 = DEScipher.Encrypt(fileContent, Key.Text);
                    }
                    else if (name.SelectedItem.ToString() == "Permutation cipher")
                    {
                        if (order.Text.ToString() != string.Empty)
                        {
                            fileContent1 = permutation.permutationcipher.encrypt(fileContent, order.Text, Convert.ToInt32(Key.Text));
                        }
                        else
                        {
                            MessageBox.Show(this, "请输入顺序!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else if (name.SelectedItem.ToString() == "AutoKey cipher")
                    {
                        fileContent1 = Autokeycipher.encryption(fileContent, Key.Text);
                    }
                    else if (name.SelectedItem.ToString() == "Keyword cipher")
                    {
                        fileContent1 = Keywordcipher.encrypt(fileContent, Key.Text);
                    }
                    else if (name.SelectedItem.ToString() == "Vigenere cipher")
                    {
                        fileContent1 = Vigenere.Vigenere.encrypt(fileContent, Key.Text);
                    }
                    else if (name.SelectedItem.ToString() == "Playfair cipher")
                    {
                        fileContent1 = playfair.Program.encryption(fileContent, Key.Text);
                    }
                    else if (name.SelectedItem.ToString() == "CA")
                    {
                        if (order.Text.ToString() != string.Empty)
                        {
                            fileContent1 = CA.CA.encrypt(fileContent, order.Text, Convert.ToInt32(Key.Text));
                        }
                        else
                        {
                            MessageBox.Show(this, "请输入二进制密钥流!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else if (name.SelectedItem.ToString() == "Column cipher")
                    {
                        fileContent1 = Column.Column.encrypt(fileContent, Key.Text);
                    }
                }
                else
                {
                    MessageBox.Show(this, "请输入密钥!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(this, "请选择要加密的文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            FileStream   myStreamr      = new FileStream(save.Text, FileMode.Create, FileAccess.Write); //创建一个文件,把字符串写入文件
            StreamWriter myStreamWriter = new StreamWriter(myStreamr);

            myStreamWriter.Write(fileContent1);
            myStreamWriter.Close();
        }
Exemplo n.º 2
0
 private void entext_Click(object sender, EventArgs e)
 {
     if (name.SelectedItem.ToString() == "RSA")
     {
         Key.Text        = skey[0];
         Cyphertext.Text = RSAcipher.EncryptString(Plaintext.Text, skey[0]);
     }
     if (Plaintext.Text.Trim() != string.Empty)
     {
         if (Key.Text.Trim() != string.Empty)
         {
             if (name.SelectedItem.ToString() == "Caesar cipher")
             {
                 int k = Convert.ToInt32(this.Key.Text);
                 Cyphertext.Text = Caecar.Caecarcipher.Caesar(Plaintext.Text, k);
             }
             else if (name.SelectedItem.ToString() == "DES")
             {
                 Cyphertext.Text = DEScipher.Encrypt(Plaintext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "Permutation cipher")
             {
                 if (order.Text.ToString() != string.Empty)
                 {
                     Cyphertext.Text = permutation.permutationcipher.encrypt(Plaintext.Text, order.Text, Convert.ToInt32(Key.Text));
                 }
                 else
                 {
                     MessageBox.Show(this, "请输入密钥顺序!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else if (name.SelectedItem.ToString() == "AutoKey cipher")
             {
                 Cyphertext.Text = Autokeycipher.encryption(Plaintext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "Keyword cipher")
             {
                 Cyphertext.Text = Keywordcipher.encrypt(Plaintext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "Vigenere cipher")
             {
                 Cyphertext.Text = Vigenere.Vigenere.encrypt(Plaintext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "Playfair cipher")
             {
                 Cyphertext.Text = playfair.Program.encryption(Plaintext.Text, Key.Text);
             }
             else if (name.SelectedItem.ToString() == "CA")
             {
                 if (order.Text.ToString() != string.Empty)
                 {
                     Cyphertext.Text = CA.CA.encrypt(Plaintext.Text, order.Text, Convert.ToInt32(Key.Text));
                 }
                 else
                 {
                     MessageBox.Show(this, "请输入二进制密钥流!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else if (name.SelectedItem.ToString() == "Column cipher")
             {
                 Cyphertext.Text = Column.Column.encrypt(Plaintext.Text, Key.Text);
             }
         }
         else
         {
             MessageBox.Show(this, "请输入密钥!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show(this, "请输入要加密的文本!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }