-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cxx
226 lines (201 loc) · 5.24 KB
/
main.cxx
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// generated by Fast Light User Interface Designer (fluid) version 1.0303
#include "main.h"
unsigned long long stringToULL(const char* c) {
{
} return std::stoull(c, 0, 10);
}
unsigned long long power(unsigned long long base, unsigned long long exponent) {
{
} long double result = 1;
for (int i = 1; i <= exponent; i++)
{
result = result * base;
}
return (result);
}
bool checkForLow(char c) {
{
} bool status;
if (c>='a'&&c<='z')
{
status = true;
}
else
{
status = false;
}
return (status);
}
bool checkForCaps(char c) {
{
} bool status;
if (c>='A'&&c<='Z')
{
status = true;
}
else
{
status = false;
}
return (status);
}
bool checkForNumbers(char c) {
{
} bool status;
if (c>='0'&&c<='9')
{
status = true;
}
else
{
status = false;
}
return (status);
}
bool checkForSpecialCharacters(char c) {
{
} bool status;
if ( (c>=' '&&c<='/') || (c>=':'&&c<='@') || (c>='['&&c<='`') || (c>='{'&&c<='~') )
{
status = true;
}
else
{
status = false;
}
return (status);
}
bool checkForNonASCIICharacters(char c) {
{
} bool status;
if ( !checkForLow(c) && !checkForCaps(c) && !checkForNumbers(c) && !checkForSpecialCharacters(c) )
{
status = true;
}
else
{
status = false;
}
return (status);
}
unsigned long long calculateCombinations(std::string s) {
{
} bool low = false, caps = false, numbers = false, specialCharacters = false, nonASCIICharacters = false;
unsigned long long charCombinations = 0;
for (int i = 0; i < s.length(); ++i)
{
if (!low)
{
low = checkForLow(s.at(i));
if (low) { charCombinations += 26; }
}
if (!caps)
{
caps = checkForCaps(s.at(i));
if (caps) { charCombinations += 26; }
}
if (!numbers)
{
numbers = checkForNumbers(s.at(i));
if (numbers) { charCombinations += 10; }
}
if (!specialCharacters)
{
specialCharacters = checkForSpecialCharacters(s.at(i));
if (specialCharacters) { charCombinations += 34; }
}
if (!nonASCIICharacters)
{
nonASCIICharacters = checkForNonASCIICharacters(s.at(i));
if (nonASCIICharacters) { charCombinations += 94; }
}
}
charCombinations = power(charCombinations, s.length());
return (charCombinations);
}
unsigned long long calculateTime(unsigned long long combinations, unsigned long long calcPerSec) {
{
} return(combinations/calcPerSec);
}
Fl_Group *grpInput=(Fl_Group *)0;
Fl_Input *txtCalculationsPerSecond=(Fl_Input *)0;
Fl_Input *txtPassword=(Fl_Input *)0;
Fl_Return_Button *btnSubmit=(Fl_Return_Button *)0;
static void cb_btnSubmit(Fl_Return_Button*, void*) {
std::string pass = "", calc = "";
long long unsigned calculationsPerSecond = 0;
long long unsigned combinations = 0;
long long unsigned timeToCrack = 0;
const char *pchar;
Fl_Text_Buffer *textBuff = new Fl_Text_Buffer();
txtOutput->buffer(textBuff);
pass.append(txtPassword->value());
calc.append(txtCalculationsPerSecond->value());
if (pass.compare("")==0)
{
fl_alert("The password is empty!");
}
else if (calc.compare("")==0||calc.compare("0")==0||calc.at(0)=='-')
{
fl_alert("Calculations Per Second must be greater or equal to 1!");
}
else
{
calculationsPerSecond = stringToULL(txtCalculationsPerSecond->value());
combinations = calculateCombinations(pass);
timeToCrack = calculateTime(combinations, calculationsPerSecond);
//std::cout << "characters: " << pass.length() << std::endl;
//std::cout << "combinations: " << combinations << std::endl;
//std::cout << "time to crack: " << timeToCrack << " seconds" << std::endl;
textBuff->text(""); // clear the contents
if (timeToCrack <= 1)
{
textBuff->append("It takes less than a second");
}
else
{
textBuff->append("It takes ");
pchar = std::to_string(timeToCrack).c_str();
textBuff->append(pchar);
textBuff->append(" seconds");
}
textBuff->append(" to crack this password");
txtPassword->take_focus();
};
}
Fl_Group *grpOutput=(Fl_Group *)0;
Fl_Text_Display *txtOutput=(Fl_Text_Display *)0;
int main(int argc, char **argv) {
Fl_Double_Window* w;
{ Fl_Double_Window* o = new Fl_Double_Window(400, 400, "Password Checker");
w = o;
o->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE));
o->hotspot(o);
{ grpInput = new Fl_Group(5, 30, 390, 105, "Input");
grpInput->box(FL_DOWN_BOX);
{ txtCalculationsPerSecond = new Fl_Input(15, 55, 370, 25, "Enter Calculations Per Second");
txtCalculationsPerSecond->align(Fl_Align(FL_ALIGN_TOP));
} // Fl_Input* txtCalculationsPerSecond
{ txtPassword = new Fl_Input(15, 100, 370, 25, "Enter Password");
txtPassword->align(Fl_Align(129));
} // Fl_Input* txtPassword
grpInput->end();
} // Fl_Group* grpInput
{ btnSubmit = new Fl_Return_Button(15, 150, 370, 25, "Submit");
btnSubmit->callback((Fl_Callback*)cb_btnSubmit);
} // Fl_Return_Button* btnSubmit
{ grpOutput = new Fl_Group(5, 205, 390, 180, "Output");
grpOutput->box(FL_DOWN_BOX);
{ txtOutput = new Fl_Text_Display(15, 215, 370, 160);
} // Fl_Text_Display* txtOutput
grpOutput->end();
} // Fl_Group* grpOutput
o->size_range(400, 400, 400, 400);
o->end();
} // Fl_Double_Window* o
txtCalculationsPerSecond->value("4000000000");
txtPassword->value("123");
txtPassword->take_focus();
w->show(argc, argv);
return Fl::run();
}