-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrutForce.cpp
57 lines (40 loc) · 1.62 KB
/
BrutForce.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
#include <iostream>
#include <chrono>
std::string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // all characters to check
std::string password;
void userPassword()
{
std::cout << "Enter the password to crack: ";
std::cin >> password;
}
void BrutForce()
{
// put as many "first letters" as letters in "password"
std::string passwordToCheck(password.size(), characters.front());
// check every combination of password
int index_letters = 0; // index to search in "characters" string
size_t lastLetter; // hold the position of the last letter of "characters" in the passwordToCheck
auto start = std::chrono::steady_clock::now(); // start the chrono
while (passwordToCheck != password)
{
passwordToCheck.back() = characters[index_letters]; // put the next letter
index_letters++;
lastLetter = passwordToCheck.find(characters.back()); // check if the last letter is reached
while (lastLetter != std::string::npos) // if there is the last letter
{
passwordToCheck[lastLetter] = characters.front(); // put the first letter
passwordToCheck[lastLetter - 1] = characters[characters.find(passwordToCheck[lastLetter - 1])+1]; // increase of one letter the previous letter
lastLetter = passwordToCheck.find(characters.back()); // recheck another time
index_letters = 0;
}
}
auto end = std::chrono::steady_clock::now(); // stop the chrono
std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "time : " << elapsed_seconds.count() << " seconds";
}
int main()
{
userPassword();
BrutForce();
return 0;
}