Hello everybody. It's been 2 weeks since I have really started coding in c++. Today, I tried to create a little program that would try to brute force a password (so there has nothing to do with hacking, since bruteforcing isn't really efficient : I just want to learn coding :) !). I haven't find something similar on the internet so I am reaching to you to help me in this. Let me present you the code :
#include <iostream>
#include <string>
using std::string;
usingnamespace std;
string bruteForce(string password);
int main()
{
string crack("test");
string password("test");
cout << "Enter the password" <<endl;
cin >> password;
crack = bruteForce(password);
cout << "Your password was " << crack << "." << endl;
return 0;
}
string bruteForce(string password)
{
string crackedPassword("");
int p = 0;
int i = 33;
int a = 0;
while (crackedPassword != password)
{
crackedPassword.push_back(0);
for(int n = p; n >= 0; n--)
{
int i = 33;
a = 0;
while((crackedPassword != password) && i <= 126 )
{
crackedPassword[n] = i;
i++;
cout << crackedPassword << endl;
if ((i == 126) && (crackedPassword[0] != 126) && a <=83)
{
i = 33;
crackedPassword[p-n] = 33 + a;
crackedPassword[n] = i;
a++;
}
}
}
p++;
}
return crackedPassword;
}
The "i" in the code, which goes from 33 to 126 represents every caracters one may use in ASCII code. The code works well until the password is longer than... 2 caracters. Once the password is longer, the string "crackedPassword" only contains tilde between the first and last caracter, and I can't figure out why. Any help is welcomed !