brute force algorithm

I'd recently made an text encryption program. i need a brute force program that attempts all possible ASCII character combinations from char(32) till char(126), it should be something like
00000
00001
00002
00003
00004
What?
yea right. How much do u pay?
That's not hard. For god's sake, your question answers itself.

Do you know what a loop is?

Ugh.
Here is a quick and dirty method. You would have to add encryption into it and test the encrypted string against the encrypted password.

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
#include <iostream>
#include <string>
using namespace std;


int main()
{
	string test = "ghik";

	string crack = "";

	for(int i = 0; i < test.length(); ++i)
		crack += 'a';


//	for(int i = 0; i < test.length(); ++i)
//	{
		for(int j = 32; j < 126; ++j)
		{
			crack[0] = j;
			for(int k = 32; k < 126; ++k)
			{
				crack[1] = k;
				for(int l = 32; l < 126; ++l)
				{
					crack[2] = l;
					for(int m = 32; m < 126; ++m)
					{
						crack[3] = m;
						
						if(crack == test)
						{
							cout << "match!\n";
							cout << crack << endl;
							return 0;
						}
					}
				}
			}
		}		
//	}
	
	return 0;
}


You may have to add another loop to accommodate more letters.

Also, I don't know if this is the most 'elegant' method but it works for fixed length passwords.
First of all, that's not what the question is and second of all, don't help people do their homework.
Actually that is what the question is. He just has to encrypt and compare.

... and second of all, don't help people do their homework


I was merely providing an algorithm. He has to do the encryption, etc. I found that on google so I just rewrote.

Not helping with homework is a crappy attitude. If no one offered any help then how would people learn?
You can help people do it; I just mean don't do it for them.
Topic archived. No new replies allowed.