Ejemplo n.º 1
0
 private void buttonDec_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);
     }
 }
Ejemplo n.º 2
0
 private void buttonEnc_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)
         {
             RC4 rc4 = new RC4(this.key, textBoxData.Text);
             this.cipher = RC4.StrToHexStr(rc4.EnDeCrypt());
             MessageBox.Show("Cipher Text is " + this.cipher);
             textBoxData.Text = cipher;
             this.enc         = true;
             this.dec         = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception in Encryption : " + ex.Message + "----->" + ex.StackTrace);
     }
 }