-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (66 loc) · 2.78 KB
/
Copy pathmain.cpp
File metadata and controls
89 lines (66 loc) · 2.78 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
#include <iostream>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <iomanip>
using namespace std;
// Utility
double bits_to_seconds(double bits, double guesses_per_sec) {
return exp2(bits) / guesses_per_sec;
}
string human_time(double seconds) {
if (seconds < 60) return to_string((int)round(seconds)) + " seconds";
if (seconds < 3600) return to_string((int)round(seconds / 60)) + " minutes";
if (seconds < 86400) return to_string((int)round(seconds / 3600)) + " hours";
if (seconds < 31536000) return to_string((int)round(seconds / 86400)) + " days";
return to_string((int)round(seconds / 31536000)) + " years";
}
// Expectation Entropy inspired operationalization
double expectation_entropy(const string &pw) {
if (pw.empty()) return 0.0;
map<string, int> freq;
for (unsigned char c : pw) {
if (islower(c)) freq["lower"]++;
else if (isupper(c)) freq["upper"]++;
else if (isdigit(c)) freq["digit"]++;
else freq["symbol"]++;
}
double L = pw.length();
double per_char_entropy = 0.0;
for (auto &kv : freq) {
double p = kv.second / L;
double class_pool = 26;
if (kv.first == "digit") class_pool = 10;
if (kv.first == "symbol") class_pool = 32;
double symbol_prob = p / class_pool;
if (symbol_prob > 0) {
per_char_entropy += -p * log2(symbol_prob);
}
}
return per_char_entropy * L;
}
// Main
int main() {
cout << "=== Educational Password Strength Estimator ==="<<endl<<endl;
cout << "DISCLAIMER:"<<endl;
cout << "This tool provides an EDUCATIONAL estimation based on Expectation Entropy and simplified offline attacker assumptions. It does NOT account for leaked passwords or advanced cracking strategies."<<endl<<endl;
string password;
cout << "Enter a password to evaluate: ";
cin>>password;
double entropy_bits = expectation_entropy(password);
const double gpu_attacker = 1e9; // guesses/sec
const double state_attacker = 1e12; // guesses/sec
double time_gpu = bits_to_seconds(entropy_bits, gpu_attacker);
double time_state = bits_to_seconds(entropy_bits, state_attacker);
cout <<endl<< "=== Results ==="<<endl<<endl;
cout << "Estimated entropy: " << (int)round(entropy_bits) << " bits"<<endl<<endl;
cout << "Estimated offline brute-force crack time:"<<endl;
cout << "1) GPU-scale attacker (1e9 guesses/sec): "
<< human_time(time_gpu) << endl;
cout << "2) Nation-state attacker (1e12 guesses/sec): "
<< human_time(time_state) << endl;
cout <<endl;
cout << "These estimates show how long a offline brute-force attack might take under the documented assumptions. They are NOT guarantees of real-world security."<<endl;
return 0;
}