Files
  • main.cpp
  • passwords.txt
main.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
#include <iostream>
#include <string>
#include <unistd.h>
#include <time.h>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

bool stop = false;
int amount = 0;
string password;

const char Alphabet[82] = {
	'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U','V', 'W', 'X', 'Y', 'Z', '@', '_', '~', '>', '<', '.', ',', '`', '!', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '='
    
};

void inline Generate(unsigned int length, string current) {
	if (length == 0 && stop == false) {
	    amount++;
        if (current == password) {
            stop = true;
        }
		return;
	}
    if (stop == false) {
    	for(unsigned int i = 0; i < 82; i++) {
    		string appended = current + Alphabet[i];
    		Generate(length -1, appended);
    	}
    }
}

int main() {
    cout << "Welcome to CyanCoding's 2nd Brute Force Password Cracker!" << endl << endl;
    sleep(2);
    cout << "This program was created in C++ (the other in Python 3)" << endl << endl;
    sleep(2);
    cout << "This program runs much faster and gets smarter as it goes!" << endl << endl;
    sleep(2);
    cout << "With an exact side-by-side test (we checked the math), we found that this program usually runs 1,430\% faster than the Python BFPC." << endl << endl;
    sleep(5);
    cout << "For increased speed, we don't have the program tell you how many million passwords it's guessed." << endl << endl;
    sleep(4);
    cout << "What do you want your password to be? > ";
    cin >> password;
	cout << endl << "Attempting to crack " << password << endl << endl;
    fstream passwordsFile;
    string passwords;
    passwordsFile.open("passwords.txt");
    getline(passwordsFile, passwords);
    stringstream ssin(passwords);
    int i = 0;
    string enter;
    vector <string> arr;
    passwordsFile.close();
    while (ssin.good()){
        ssin >> enter;
        arr.push_back(enter);
        i++;
    }
	for (i = 0; i < arr.size(); i++) {
	    amount++;
	    if (password == arr[i]) {
	        cout << "Your password has been entered in this program before! It knew to look for it first! It found it in " << amount << " tries!";
	        stop = true;
	        break;
	    }
	}
	if (stop == false) {
	    fstream passwordFile;
	    passwordFile.open("passwords.txt");
    	passwords = password;
    	passwords += " ";
    	for (i = 0; i < arr.size(); i++) {
    	    passwords += arr[i];
    	    passwords += " ";
    	}
    	passwordFile << passwords;
    	passwordFile.close();
	}
	if (stop == false) {
    	clock_t start = clock();
    	while (stop == false) {
    	    static unsigned int stringLength = 1;
    	    Generate(stringLength, "");
    	    stringLength++;
    	    if (stop == true) {
    	        break;
    	    }
    	}
    	cout << "CyanCoding's C++ BFPC cracked the password " << password << " in " << amount << " attempts and " << setprecision(2) << fixed << (float)(clock() - start)/CLOCKS_PER_SEC << " seconds." << endl << endl << "That's about " << setprecision(0) << amount / ((float)(clock() - start)/CLOCKS_PER_SEC) << " passwords per second!";
	}
	return 0;
}