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(); }
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); } }