-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword8Sequenziale.cpp
More file actions
137 lines (119 loc) · 4.96 KB
/
Copy pathPassword8Sequenziale.cpp
File metadata and controls
137 lines (119 loc) · 4.96 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <chrono>
#include <crypt.h>
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include <random>
//////////////////////
/// MAIN FUNCTION ///
/// /////////////////
int main() {
//// HASH VARIABLES ////
const std::string salt = "AB";
const char* salt_cstr = salt.c_str();
std::string found;
bool found_flag = false;
std::random_device rd;
std::mt19937 gen(rd());
//// TIMER START ////
const auto start = std::chrono::high_resolution_clock::now();
//// MAIN LOOP VARIABLES ////
constexpr int NUM_ITER = 500;
constexpr long long PASSWORDS_PER_ITER = 32LL * 13 * 2026;
long long total_passwords_tested = 0;
int correct_matches = 0;
int incorrect_matches = 0;
//// MAIN LOOP ////
for (int i = 0; i < NUM_ITER; i++) {
found = "";
found_flag = false;
//// GENERATE RANDOM PASSWORD TARGET ////
std::uniform_int_distribution<int> giorno(1, 31);
std::uniform_int_distribution<int> mese(1, 12);
std::uniform_int_distribution<int> anno(0, 2025);
const int g = giorno(gen);
const int m = mese(gen);
const int y = anno(gen);
char target_password[9];
target_password[0] = '0' + (g / 10);
target_password[1] = '0' + (g % 10);
target_password[2] = '0' + (m / 10);
target_password[3] = '0' + (m % 10);
target_password[4] = '0' + ((y / 1000) % 10);
target_password[5] = '0' + ((y / 100) % 10);
target_password[6] = '0' + ((y / 10) % 10);
target_password[7] = '0' + (y % 10);
target_password[8] = '\0';
//// CRYPT TARGET PASSWORD ////
const char* target = crypt(target_password, salt_cstr);
const std::string target_string = target;
//// BRUTE FORCE SEARCH ////
for (int a = 0; a <= 31 && !found_flag; ++a) {
for (int b = 0; b <= 12 && !found_flag; ++b) {
for (int c = 0; c <= 2025; ++c) {
if (found_flag) break;
char date[9];
date[0] = '0' + (a / 10);
date[1] = '0' + (a % 10);
date[2] = '0' + (b / 10);
date[3] = '0' + (b % 10);
date[4] = '0' + ((c / 1000) % 10);
date[5] = '0' + ((c / 100) % 10);
date[6] = '0' + ((c / 10) % 10);
date[7] = '0' + (c % 10);
date[8] = '\0';
//// CRYPT GENERATED DATE ////
const char* h = crypt(date, salt_cstr);
//// CHECK IF HASH MATCHES TARGET ////
if (h[2] == target[2] && h[3] == target[3]) {
if (strcmp(h, target_string.c_str()) == 0) {
found = date;
found_flag = true;
break;
}
}
}
}
}
//// UPDATE STATS ////
total_passwords_tested += PASSWORDS_PER_ITER;
if (!found.empty()) {
if (strcmp(found.c_str(), target_password) == 0) {
correct_matches++;
} else {
incorrect_matches++;
}
}
}
//// TIMER END ////
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = end - start;
double passwords_per_second = total_passwords_tested / elapsed.count();
//// PRINT RESULTS ////
std::cout << "========================================\n";
std::cout << "Elaborazione completata!\n";
std::cout << "========================================\n";
std::cout << "Tempo totale impiegato: " << std::fixed << std::setprecision(2) << elapsed.count() << " secondi\n";
std::cout << "Tempo medio per iterazione: " << std::fixed << std::setprecision(3) << (elapsed.count()/NUM_ITER) << " secondi\n";
std::cout << "Iterazioni totali: " << NUM_ITER << "\n";
std::cout << "Password testate totali: " << total_passwords_tested << "\n";
std::cout << "Password testate/secondo: " << std::fixed << std::setprecision(0) << passwords_per_second << "\n";
std::cout << "Thread utilizzati: 1 (sequenziale)\n";
std::cout << "========================================\n";
std::cout << "VERIFICA CORRETTEZZA:\n";
std::cout << "Password corrette trovate: " << correct_matches << "/" << NUM_ITER << "\n";
std::cout << "Password errate trovate: " << incorrect_matches << "/" << NUM_ITER << "\n";
//// FINAL CHECK CORRECTNESS ////
if (correct_matches == NUM_ITER) {
std::cout << "✓ SUCCESSO: Tutte le password sono state trovate correttamente!\n";
} else {
std::cout << "✗ ERRORE: Alcune password non sono state trovate o sono errate!\n";
}
if (!found.empty()) {
printf("✓ Ultima password trovata: %s\n", found.c_str());
} else {
printf("✗ Ultima password non trovata\n");
}
return 0;
}