-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
112 lines (84 loc) · 2.78 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "QCryptographicHash"
#include <QElapsedTimer>
#include <QMutex>
#include <QThread>
#include <iostream>
#include <thread>
#include <ui_mainwindow.h>
using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//QObject::connect(this, &MainWindow::stopWorkerSignal, this, &MainWindow::stop_worker);
}
MainWindow::~MainWindow()
{
delete ui;
}
QString SHA1(QString input)
{
QByteArray sha1Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha1);
return sha1Hash.toHex();
}
int thr_num = 0;
int ui_update_frequency = 10000000;
void MainWindow::sha1_worker(long long start_val, long long end_val, int thread_number = thr_num++)
{
QString true_hash = ui->lineEdit->text();
QString phone_prefix = "+";
QElapsedTimer timer;
timer.start();
long long val = start_val;
while (val < end_val)
{
QString input = phone_prefix + QString::number(val);
QString result_hash = SHA1(input);
if(result_hash == true_hash)
{
ui->textEdit->append("Found possible number: " + input + " with SHA1 = " + result_hash);
}
if(val % ui_update_frequency == 0)
{
emit workDone();
}
val++;
}
ui->textEdit->append("Exiting thread # " + QString::number(thread_number) + " after " + QString::number(int(timer.nsecsElapsed() / 1000000000.0)) + " seconds");
}
vector<QThread*> worker_threads {};
void MainWindow::launch_sha1_calc(int threads_number = QThread::idealThreadCount())
{
long long starting_phone = 380000000000;
long long final_phone = 381000000000;
long long operations_amount = final_phone - starting_phone;
long long operations_amount_per_thread = operations_amount / threads_number + 1;
ui->progressBar->setMaximum(operations_amount);
connect(this, &MainWindow::workDone, this, &MainWindow::updateUI);
for(int i = 0; i < threads_number; i++)
{
long long start_val = starting_phone + i * operations_amount_per_thread;
long long end_val = start_val + operations_amount_per_thread;
QThread* thread = new QThread;
QObject::connect(thread, &QThread::started, [=] {
sha1_worker(start_val, end_val);
});
worker_threads.push_back(thread);
for (int i = 0; i < worker_threads.size(); i++)
{
thread->start();
}
}
ui->textEdit->append("Started hash cracking with " + QString::number(threads_number) + " parallel threads...");
}
void MainWindow::on_pushButton_clicked()
{
launch_sha1_calc();
}
void MainWindow::updateUI()
{
ui->progressBar->setValue(ui->progressBar->value() + ui_update_frequency);
}