Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <stdlib.h>
- #include <thread>
- #include <cstdio>
- #include <ctime>
- std::string password; //DO NOT ACCESS
- bool cracked = false;
- std::string legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_";
- std::string crackedPassword;
- int countChar(std::string str, char c)
- {
- int rtn = 0;
- for(unsigned i = 0; i < str.length(); i++)
- {
- if(str[i] == c)
- {
- rtn++;
- }
- }
- return rtn;
- }
- std::string charToString(char c)
- {
- std::stringstream ss;
- std::string target;
- ss << c;
- ss >> target;
- return target;
- }
- int testFirstChar(char c)
- {
- std::string toTest = charToString(c);
- if(toTest == password)
- {
- cracked = true;
- crackedPassword = toTest;
- return 1;
- }
- else
- {
- bool doneTwo;
- bool doneThr;
- bool doneFou;
- for(int i = 0; i < 73; i++)
- {
- doneTwo = false;
- for(int j = 0; j < 73; j++)
- {
- doneThr = false;
- for(int k = 0; k < 73; k++)
- {
- doneFou = false;
- for(int l = 0; l < 73; l++)
- {
- if(cracked)
- {
- return 1;
- }
- toTest = charToString(c) + charToString((char) legalChars[i]);
- if(!doneTwo)
- {
- if(toTest == password)
- {
- cracked = true;
- crackedPassword = toTest;
- return 1;
- }
- doneTwo = true;
- }
- toTest += charToString((char) legalChars[j]);
- if(!doneThr)
- {
- if(toTest == password)
- {
- cracked = true;
- crackedPassword = toTest;
- return 1;
- }
- doneThr = true;
- }
- toTest += charToString((char) legalChars[k]);
- if(!doneFou)
- {
- if(toTest == password)
- {
- cracked = true;
- crackedPassword = toTest;
- return 1;
- }
- doneFou = true;
- }
- toTest += charToString((char) legalChars[l]);
- if(toTest == password)
- {
- cracked = true;
- crackedPassword = toTest;
- return 1;
- }
- }
- }
- }
- }
- }
- std::cout << "oh well" << std::endl;
- }
- void testFirstChars(std::string str)
- {
- for(unsigned i = 0; i < str.length(); i++)
- {
- if(!cracked)
- {
- int crack = testFirstChar((char) str[i]);
- if(crack == 1)
- {
- break;
- }
- }
- }
- }
- int main() {
- std::clock_t start;
- double duration;
- start = std::clock();
- bool acceptPassword = true;
- std::cout << "Please input a password. Maximum length is 5 characters. Alphanumeric characters and !@#$%^&*()_ only." << std::endl;
- std::cin >> password;
- if(password.length() > 5)
- {
- acceptPassword = false;
- }
- else
- {
- for(unsigned i = 0; i < password.length(); i++)
- {
- char cur = (char) password[i];
- if(countChar(legalChars, cur) == 0)
- {
- acceptPassword = false;
- }
- }
- }
- while(!acceptPassword)
- {
- acceptPassword = true;
- std::cout << "Invalid password. Please try again." << std::endl;
- std::cout << "Please input a password. Maximum length is 5 letters. Permitted characters: Letters (upper and lower case); !@#$%^&*()_" << std::endl;
- std::cin >> password;
- if(password.length() > 5)
- {
- acceptPassword = false;
- }
- else
- {
- for(unsigned i = 0; i < password.length(); i++)
- {
- char cur = password[i];
- if(countChar(legalChars, cur) == 0)
- {
- acceptPassword = false;
- }
- }
- }
- }
- std::cout << "Working. Please wait for completion." << std::endl;
- std::thread t1(testFirstChars, "ABCDEFGH1");
- std::thread t2(testFirstChars, "IJKLMNOP2");
- std::thread t3(testFirstChars, "QRSTUVWX3");
- std::thread t4(testFirstChars, "YZabcdef4");
- std::thread t5(testFirstChars, "ghijklmn5");
- std::thread t6(testFirstChars, "opqrstuv6");
- std::thread t7(testFirstChars, "wxyz!@#$7");
- std::thread t8(testFirstChars, "%^&*()_890");
- t1.join();
- t2.join();
- t3.join();
- t4.join();
- t5.join();
- t6.join();
- t7.join();
- t8.join();
- duration = (std::clock() - start) / ((double) CLOCKS_PER_SEC);
- std::cout << "Cracked password: " + crackedPassword << std::endl;
- std::cout << " in " + std::to_string(duration) + "ms." << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment