?? 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 + -