/// <summary> /// 发送文件 /// </summary> /// <param name="param">续传断点</param> private void SendFile(object param) { long breakpoint = Convert.ToInt64(param); string srcFile = InvokeCtrl.GetCtrlText(txtFile); string hashcode = FileUtils.GetHashCode(srcFile); string filename = FileUtils.GetFileName(srcFile); totalBytes = FileUtils.GetFileSize(srcFile); if (totalBytes - breakpoint <= 0) { return; } //间歇时间 Thread.Sleep(interval); MsgEntity msg = new MsgEntity(); msg.msgType = Constant.MSG_TYPE_CMD; msg.msgBody = Constant.CMD_FILE_TRANSFER_REQ; msg.args = new Dictionary <string, object>(); msg.args.Add("filename", filename); //文件名 msg.args.Add("hashcode", hashcode); //文件hash值 msg.args.Add("total", totalBytes); //文件大小 msg.args.Add("reseed", (breakpoint > 0)); //是否为续传 msg.args.Add("sendstate", ""); //传输状态(发送中/发送结束) msg.args.Add("offset", 0); //传输流的偏移量 int size = buffersize * 1024; if (breakpoint + size > totalBytes) { msg.args["sendstate"] = Constant.STATE_SEND_END; timerSendState.Stop(); } else { msg.args["sendstate"] = Constant.STATE_SEND_ON; } msg.args["offset"] = breakpoint; byte[] extendData = FileUtils.ReadFromFile(srcFile, size, breakpoint); byte[] sendbytes = FileUtils.GetSendBytes(msg, extendData); SendByteData(sendbytes); if (chkShowLog.Checked) { Log("发送文件流len=" + sendbytes.Length); } completeBytes += extendData.Length; int finish = (int)Math.Ceiling(100.0 * completeBytes / totalBytes); InvokeCtrl.UpdatePrgBarValue(prgBar1, finish, Color.FromKnownColor(KnownColor.Highlight), string.Format("发送完成{0} %", finish)); InvokeCtrl.UpdateCtrlText(lbFinish, FileUtils.getFinished(completeBytes, totalBytes)); }
private void crackDES() { do { if (counter > total) { timerCrackState.Stop(); InvokeCtrl.UpdateCtrlText(txtDesKey, desKey); InvokeCtrl.UpdateCtrlText(txtCipherGen, cipherGen); MessageBox.Show("任务结束,未找到密钥!"); InvokeCtrl.UpdateCtrlEnabled(btnCrack, true); InvokeCtrl.UpdateCtrlEnabled(btnPause, false); InvokeCtrl.UpdateCtrlEnabled(btnStop, false); InvokeCtrl.UpdateCtrlEnabled(txtPlaintext, true); InvokeCtrl.UpdateCtrlEnabled(txtCiphertext, true); InvokeCtrl.UpdateCtrlEnabled(txtThreadNum, true); LogHelper.Log(string.Format("任务结束,用时[{0}],未找到密钥!", InvokeCtrl.GetCtrlText(lbSeconds))); break; } /* * 1、假设密钥由md5生成(即字符范围[0-9A-F]),那么8位的密钥范围可以看作0x00000000-0xFFFFFFFF * 2、假设md5生成字符统一大写或小写,那么需要考虑切换大小写再加密 * 2、假设加密向量与密钥相同(否则计算量超出本算法范围。。) */ desKey = counter.ToString("x8"); counter++; prgValue = Convert.ToInt32(10000 * counter / total); //InvokeCtrl.UpdateCtrlText(lbCounter, counter.ToString()); //InvokeCtrl.UpdateCtrlText(txtDesKey, desKey); cipherGen = DESCrypt.Encrypt(desKey, plaintext, desKey); //InvokeCtrl.UpdateCtrlText(txtCipherGen, cipherGen); if (cipherGen.Equals(ciphertext)) { timerCrackState.Stop(); InvokeCtrl.UpdateCtrlText(txtDesKey, desKey); InvokeCtrl.UpdateCtrlText(txtCipherGen, cipherGen); MessageBox.Show("恭喜你,找到密钥:" + cipherGen); InvokeCtrl.UpdateCtrlEnabled(btnCrack, true); InvokeCtrl.UpdateCtrlEnabled(btnPause, false); InvokeCtrl.UpdateCtrlEnabled(btnStop, false); InvokeCtrl.UpdateCtrlEnabled(txtPlaintext, true); InvokeCtrl.UpdateCtrlEnabled(txtCiphertext, true); InvokeCtrl.UpdateCtrlEnabled(txtThreadNum, true); LogHelper.Log(string.Format("在进度[{0}]处,用时[{1}],找到密钥:{2}", InvokeCtrl.GetCtrlText(prgBar1), InvokeCtrl.GetCtrlText(lbSeconds), cipherGen)); break; } string desKeyUpcase = desKey.ToUpper(); if (desKeyUpcase.Equals(desKey)) { continue; } desKey = desKeyUpcase; //InvokeCtrl.UpdateCtrlText(txtDesKey, desKey); cipherGen = DESCrypt.Encrypt(desKey, plaintext, desKey); //InvokeCtrl.UpdateCtrlText(txtCipherGen, cipherGen); if (cipherGen.Equals(ciphertext)) { timerCrackState.Stop(); InvokeCtrl.UpdateCtrlText(txtDesKey, desKey); InvokeCtrl.UpdateCtrlText(txtCipherGen, cipherGen); MessageBox.Show("恭喜你,找到密钥:" + cipherGen); InvokeCtrl.UpdateCtrlEnabled(btnCrack, true); InvokeCtrl.UpdateCtrlEnabled(btnPause, false); InvokeCtrl.UpdateCtrlEnabled(btnStop, false); InvokeCtrl.UpdateCtrlEnabled(txtPlaintext, true); InvokeCtrl.UpdateCtrlEnabled(txtCiphertext, true); InvokeCtrl.UpdateCtrlEnabled(txtThreadNum, true); LogHelper.Log(string.Format("在进度[{0}]处,用时[{1}],找到密钥:{2}", InvokeCtrl.GetCtrlText(prgBar1), InvokeCtrl.GetCtrlText(lbSeconds), cipherGen)); break; } } while (true); }