Пример #1
0
 private void debutton_Click(object sender, EventArgs e)
 {
     if (this.qBox.Text.Length == 0)
          MessageBox.Show("密钥未生成");
      else if (this.cipherBox.Text.Length > 0)//输入新的密文
      {
          plainBox.Text = "";
          ciphertext = this.cipherBox.Text;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          RSA rsa = new RSA(1);
          plaintext = rsa.OnDecode(ciphertext, dekey, n);
          sw.Stop();
          TimeSpan ts = sw.Elapsed;
          codetime = ts.TotalMilliseconds;
          resultBox.Text =  plaintext;
          MessageBox.Show("解密总花费"+(codetime+protime).ToString()+"ms.");
      }
      else//不输入新密文,直接解密
      {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          RSA rsa0 = new RSA(1);
          plaintext = rsa0.OnDecode(ciphertext, dekey, n);
          sw.Stop();
          TimeSpan ts = sw.Elapsed;
          codetime = ts.TotalMilliseconds;
          resultBox.Text =  plaintext;
          MessageBox.Show("解密总花费" + (codetime + protime).ToString() + "ms.");
      }
 }
Пример #2
0
 private void enbutton_Click(object sender, EventArgs e)
 {
     if (this.qBox.Text.Length == 0)
          MessageBox.Show("密钥未生成");
      else if (this.plainBox.Text.Length > 0)//输入新的明文
      {
          cipherBox.Text = "";
          plaintext = this.plainBox.Text;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          RSA rsa = new RSA(0);
          ciphertext = rsa.OnCode(plaintext, enkey, n);
          sw.Stop();
          TimeSpan ts = sw.Elapsed;
          codetime = ts.TotalMilliseconds;
          resultBox.Text = ciphertext;
          MessageBox.Show("加密总花费" + (codetime + protime).ToString() + "ms.");
      }
 }