} //Boolean TestOxCurrent() private void jiami_Click(object sender, EventArgs e) { string key = KeyText.Text; if (true == testASCII("Key", key)) { if (16 == key.Length) { if (true == testASCII("PlainText", PlainText.Text)) { if (0 != PlainText.Text.Length) { TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); //获取当前时间的刻度数 string plaintext = PlainText.Text; Sms4 sms4 = new Sms4(key); int pLength = plaintext.Length; string newPaint = plaintext; for (int i = 0; i < (16 - pLength % 16) % 16; i++) { newPaint += '0'; } string cipherText = ""; string flag = ""; for (int i = 0; i < newPaint.Length / 16; i++) { flag = sms4.encryption(newPaint.Substring(i * 16, 16)); cipherText += flag; } ClipherText.Text = cipherText; TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = ts2.Subtract(ts1).Duration();//时间差的绝对值 String spanTime = "加密运行时间: " + ts.Seconds.ToString() + "秒" + ts.Milliseconds.ToString() + "毫秒"; toolStripStatusLabel1.Text = spanTime; } else { MessageBox.Show("明文框中不能为空值!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else { if (KeyText.Text.Length < 16) { MessageBox.Show("key的位数小于16,请在key文本框内输入ASCII码表中的字符!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("key的位数大于16,请在key文本框内内ASCII码表中的字符!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } }
private void jiemi_Click(object sender, EventArgs e) { string key = KeyText.Text; if (true == testASCII("Key", key)) { if (16 == key.Length) { if (true == TestOxCurrent(ClipherText.Text)) { if (0 != ClipherText.Text.Length && 0 == ClipherText.Text.Length % 32) { TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); //获取当前时间的刻度数 string ciphertext = ClipherText.Text; Sms4 sms4 = new Sms4(key); string plaintext = string.Empty; for (int i = 0; i < ciphertext.Length / 32; i++) { plaintext += sms4.decryption(ciphertext.Substring(i * 32, 32)); } PlainText.Text = plaintext; TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = ts2.Subtract(ts1).Duration();//时间差的绝对值 String spanTime = "解密运行时间: " + ts.Seconds.ToString() + "秒" + ts.Milliseconds.ToString() + "毫秒"; toolStripStatusLabel1.Text = spanTime; } else { MessageBox.Show("密文框中不能为空值且长度是32的整数倍!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("密文框中只能输入十六进制的数(0~F)!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("key的位数不足,请在key文本框内输入ASCII码表中的字符!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }