Trying to Write a Bruteforce Program

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 :
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
#include <iostream>
#include <string>

using std::string;
using namespace 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 !
Topic archived. No new replies allowed.