Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdio>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- //varibles and using char for all possible numbers and letters for pass code cracker
- char chars[]={'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'};
- string code;
- void checkPassword(string password);
- void recurse(int width, int position, string baseString);
- // varibles for clock and starting the clock
- clock_t start;
- double duration;
- int main() {
- //starting the clock for how long it takes for the code to run
- start = clock();
- // asking user to enter code and stores it
- cout << "Enter a 4 or 5 digit password: " << endl;
- cin >> code;
- // setting limits for how many digits a user can enter
- while (code.length() > 5)
- {
- cout << "Invalid password, input again" << endl;
- cin >> code;
- }
- while (code.length() < 4)
- {
- cout << "Invalid password, input again" << endl;
- cin >> code;
- }
- // checks each digits width
- int maxChars = 5;
- for(int i=0;i<maxChars+1;i++) {
- cout << "checking passwords width [" << i << "]..." << endl;
- recurse(i,0,"");
- }
- return 0;
- }
- //looking for the given digit by looking through the 36 possible we gave
- void recurse(int width, int position, string baseString) {
- for(int i=0;i<36;i++) {
- if (position < width-1) {
- recurse(width, position + 1, baseString+chars[i]);
- }
- checkPassword(baseString+chars[i]);
- }
- }
- // finding a match
- void checkPassword(string password) {
- if (password==code) {
- cout << "match [" << password << "]" << endl;
- //giving the time on how long it took
- duration = (clock() - start) / (double)CLOCKS_PER_SEC;
- cout<< "TIME: It took this ammount of seconds to crack your code " << duration << '\n';
- exit(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement