THIS IS JUST FOR LEARNING PURPOSES. I WON'T BE USING THIS TO HACK ANYONE.
Here is a small algorithm I made to crack a password. This is just the background of a more complex code I'm going to make.
To be honest, this code is TERRIBLY written, so I need help on making it more efficient and flexible. It is limited to 5-characters password and not easy to expand.
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
std::string checkCharacters = {
'%',
'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',
'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',
'1','2','3','4','5','6','7','8','9','0'
};
std::string search(std::string password) {
for (int a = 0; a < checkCharacters.size(); a++)
for (int b = 0; b < checkCharacters.size(); b++)
for (int c = 0; c < checkCharacters.size(); c++)
for (int d = 0; d < checkCharacters.size(); d++)
for (int e = 0; e < checkCharacters.size(); e++)
{
std::string checkString = "";
checkString += checkCharacters[a];
checkString += checkCharacters[b];
checkString += checkCharacters[c];
checkString += checkCharacters[d];
checkString += checkCharacters[e];
checkString.erase(std::remove(checkString.begin(), checkString.end(), '%'), checkString.end());
if (checkString == password)
return checkString;
}
return "TARGET_PASSWORD_NOT_FOUND";
}
int main() {
while (1) {
std::string password;
std::cout << "Enter password : ";
std::cin >> password;
std::cout << "Your password is : " << password << std::endl;
std::string attempt = search(password);
std::cout << attempt << std::endl << std::endl;
}
}
k
from a set of sizen
. It might be a good learning experience to try to write such a general code for example using a simple recursive method and with templates to make your method work for arbitrary sets and arbitrary password-lengthsk
. \$\endgroup\$std::next_permutation
in a loop \$\endgroup\$std::next_permutation
gives you the next permutation of the current word but it does not add or remove letters from the word. \$\endgroup\$