private void buttonDecrypt_Click(object sender, EventArgs e) { try { if (textBoxData.Text == String.Empty) { MessageBox.Show("Please enter data in text area"); return; } if (dec) { MessageBox.Show("Data has already decrypted"); return; } RC4 rc4 = new RC4(this.key); rc4.Text = RC4.HexStrToStr(this.cipher); textBoxData.Text = rc4.EnDeCrypt(); dec = true; enc = false; } catch (Exception ex) { MessageBox.Show("Exception in Decryption : " + ex.Message + "------>" + ex.StackTrace); } }
private void buttonEncrypt_Click(object sender, EventArgs e) { try { if (textBoxData.Text == String.Empty) { MessageBox.Show("Please enter data in text area"); return; } if (enc) { MessageBox.Show("Data has already encrypted"); return; } if (!radioButton1.Checked && !radioButton2.Checked && !radioButton3.Checked && !radioButton4.Checked) { MessageBox.Show("Please enter type of encryption"); return; } if (radioButton1.Checked) { Random random = new Random(); int pos = random.Next(4); this.key = keySet1[pos]; } else if (radioButton2.Checked) { Random random = new Random(); int pos = random.Next(4); this.key = keySet2[pos]; } else if (radioButton3.Checked) { Random random = new Random(); int pos = random.Next(4); this.key = keySet3[pos]; } else if (radioButton4.Checked) { Random random = new Random(); int pos = random.Next(4); this.key = keySet4[pos]; } if (!enc) { this.cipher = ""; RC4 rc4 = new RC4(this.key, textBoxData.Text); this.cipher = RC4.StrToHexStr(rc4.EnDeCrypt()); textBoxData.Text = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(cipher)); this.enc = true; this.dec = false; } } catch (Exception ex) { MessageBox.Show("Exception in Encryption : " + ex.Message + "----->" + ex.StackTrace); } }