📄 mainwindow.cpp
字号:
#include "MainWindow.h"#include <iostream> //Debug.using namespace std; //Debug.#include <QTextCodec> //中文编码。#include <QMessageBox> //Debug.#include <QCryptographicHash> //加密。#include <QEventLoop> //消息循环。#include "md5.h" //md5类。#include <QString> //字符串类。#include <QScrollBar> //滚动条。MainWindow::MainWindow(){ setupUi(this); IKnowIt=false; Paused=true; CharSet[0]='0'; CharSet[1]='1'; CharSet[2]='2'; CharSet[3]='3'; CharSet[4]='4'; CharSet[5]='5'; CharSet[6]='6'; CharSet[7]='7'; CharSet[8]='8'; CharSet[9]='9'; CurPass="0"; NumArr[0]=NOTSET; //第0位是空的。 NumArr[1]=NOTSET; //第1位是空的。 NumArr[2]=NOTSET; //第2位是空的。 NumArr[3]=NOTSET; //第3位是空的。 NumArr[4]=NOTSET; //第4位是空的。 NumArr[5]=NOTSET; //第5位是空的。 NumArr[6]=NOTSET; //第6位是空的。 NumArr[7]=0; //第7位是0。 return;}; //MainWindow::MainWindow()void MainWindow::ToggleProcess(){ QTextCodec * TheLocaleCodec=QTextCodec::codecForLocale(); //本地编码。 if (Paused) //暂停状态。 { Paused=false; //取消暂停。 StartCalc_pushButton->setText(TheLocaleCodec->toUnicode("暂停(&A)")); DecryptNow(); //调用DecryptNow()从上次中断的地方开始。 } //if else //运行于破解状态。 { Paused=true; //暂停。 StartCalc_pushButton->setText(TheLocaleCodec->toUnicode("继续(&C)")); StartCalc_pushButton->setEnabled(false); //等DecryptNow()退出的时候再把它enable. }; //else return;}; //void MainWindow::ToggleProcess()void MainWindow::DecryptNow(){ QTextCodec * TheLocaleCodec=QTextCodec::codecForLocale(); //编码转换器。 bool ReachEnd; //是不是到头了。 QString Md5Sum; //计算出来的Md5值。 int Counter; //计数器。 uint HowMany9=0; //9的个数。 QString TempString=""; //临时字符串。 QString TargetMd5=""; //要破解的md5值。 TargetMd5=MD5_lineEdit->text(); //取得要破解的Md5值。 ReachEnd=ReachTheEnd(); while(!ReachEnd) //没结束。 { QCoreApplication::processEvents(QEventLoop::AllEvents); //处理消息。 if (Paused) //暂停了。 { StartCalc_pushButton->setEnabled(true); return; }; //if //首先根据NumArr[]计算出当前要用到的明文: CurPass=""; for (Counter=0;Counter<8;Counter++) //依次处理数字。 { if (NumArr[Counter]!=NOTSET) //有内容。 { CurPass.append(TempString.setNum(NumArr[Counter])); //接上一个数字。 }; //if }; //for //最后数字加1: if (NumArr[7]==9) //要进位了。 { //找出前头有几个连续的9: HowMany9=0; for (Counter=7;Counter>-1;Counter--) //从低位开始找。 { if (NumArr[Counter]==9) HowMany9++; else break; }; //for //根据9的个数来处理: if (HowMany9==8) //所有的数字都到9了。 { for (Counter=0;Counter<8;Counter++) NumArr[Counter]=NOTSET; } //if else //还耄到呢。 { if (NumArr[7-HowMany9]==NOTSET) NumArr[7-HowMany9]=0; //前头变成0。 else NumArr[7-HowMany9]++; //前头进一位。 for (Counter=(8-HowMany9);Counter<8;Counter++) NumArr[Counter]=0; }; //else } //if else NumArr[7]++; //不用进位。 //根据明文计算MD5: Md5Sum=MD5(CurPass).toString(); //比较: if (Md5Sum==TargetMd5) //找到了! { Log_textBrowser->moveCursor(QTextCursor::Start,QTextCursor::MoveAnchor); //光标移到开始。 Log_textBrowser->insertPlainText(TargetMd5+" <== "+CurPass+"\n"); //记录。 Progress_textBrowser->moveCursor(QTextCursor::Start,QTextCursor::MoveAnchor); Progress_textBrowser->insertPlainText(CurPass+" ==> "+Md5Sum+TheLocaleCodec->toUnicode("是正确的密码!\n")); //记录。 Paused=true; QMessageBox::information(this,TheLocaleCodec->toUnicode("获得结果!"),TheLocaleCodec->toUnicode("破解成功,密码是:\n"+CurPass.toAscii()+"\n。"),QMessageBox::Ok,QMessageBox::Ok); //报喜。 //重置状态: NumArr[0]=NOTSET; //第0位是空的。 NumArr[1]=NOTSET; //第1位是空的。 NumArr[2]=NOTSET; //第2位是空的。 NumArr[3]=NOTSET; //第3位是空的。 NumArr[4]=NOTSET; //第4位是空的。 NumArr[5]=NOTSET; //第5位是空的。 NumArr[6]=NOTSET; //第6位是空的。 NumArr[7]=0; //第7位是0。 Progress_progressBar->setValue(Progress_progressBar->maximum()); //进度条修改。 StartCalc_pushButton->setEnabled(true); //enble按钮。 StartCalc_pushButton->setText(TheLocaleCodec->toUnicode("开始(&S)")); return; } //if else //没找到。 { Progress_textBrowser->moveCursor(QTextCursor::Start,QTextCursor::MoveAnchor); Progress_textBrowser->insertPlainText(CurPass+" ==> "+Md5Sum+TheLocaleCodec->toUnicode("不正确。\n")); //记录。 Progress_progressBar->setValue((Progress_progressBar->value()+1)%Progress_progressBar->maximum()); }; //else }; //while //结束了。 Progress_progressBar->setValue(Progress_progressBar->maximum()); //进度条修改。 StartCalc_pushButton->setEnabled(true); //enble按钮。 StartCalc_pushButton->setText(TheLocaleCodec->toUnicode("开始(&S)")); QMessageBox::information(this,TheLocaleCodec->toUnicode("破解结束"),TheLocaleCodec->toUnicode("破解过程已经结束,没找到密码。"),QMessageBox::Ok,QMessageBox::Ok); //报告。 return;}; //void MainWindow::DecryptNow()bool MainWindow::ReachTheEnd(){ bool Result=false; //结果。 unsigned int Counter=0; //计数器。 unsigned int TempSum=0; //临时和。 for (Counter=0;Counter<8;Counter++) //一个个地加起来。 { TempSum+=NumArr[Counter]; }; //for if (TempSum==8*NOTSET) Result=true; //结束。 return Result;}; //bool MainWindow::ReachTheEnd()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -