Brute Force

Right, so you've read the title and you thought wanna be hacker eh? Wrong, I really just want to try this and make it as a cool gimmick to try it out and see what it would really do. I know this will not work over the internet and all that so i was just wondering what I should do after this part?

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main () {

	int i;
	
	for (i= 0 ; i< 255; i++) 
	{
		cout << i <<endl;
	}
    return 0;
}


I know its quite nooby but how do I expand on it and search for numbers like 552 instead of just numbers up to 255?



EDIT: Also how would I "use" this item on something for example MSN or some database field? I can't see how it would work just running the file? Again I do not plan to use a brute force tool to well, brute force as its not hacking ;)
Last edited on
What? If you want the loop continuing until 552, just type '552' instead of 255
Huh? I thought though that 255 was the maximum for an array?! And so basically if I typed 99999999, that in effect is a brute force tool? Then then next stage is work with letters by doing the same thing?

I don't think I understand what you're trying to do, here.
Basically helios I am just trying to list all possible combinations of letters for example


1111111
1111112
1111113
1111114
1111115
1111116
1111117
1111118

ect all the way to 9999999

and once ive done that how would i go about using the program somewhere?
I am just trying to list all possible combinations of letters for example

1111111
1111112
1111113
1111114
1111115
1111116
1111117
1111118
Where do you see the 'letters' there?

and once ive done that how would i go about using the program somewhere?
Are you creating a program which doesn't have any use you know?
Ok I made a mistake alright? Anyway I am trying out with numbers right now and yes I know it has no use hence my first post, so if your not going to help me and you are going to spell check all my posts then can you leave and let someone actually help me?

I also ment how would I actually use it as once I have the code what would i do next -.-
Last edited on
Why does the series start at 1111111? What about 0000001?

Anyway, here's how it's done:
1
2
3
4
5
6
7
8
9
10
11
12
13
const size_t N=4;
char test[N]={0};
while (1){
	for (int a=N;a>=0;a--)
		std::cout <<test[a];
	std::cout <<std::endl;
	test[0]++;
	for (size_t a=0;a<N-1;a++)
		if (!test[a])
			test[a+1]++;
	if (!test[N-1])
		break;
}

This will take a long time to complete. Incrementing N by 1 multiplies the running time by 256. N=8 should never finish, I think.
Why does the series start at 1111111? What about 0000001?

Anyway, here's how it's done:

const size_t N=4;
char test[N]={0};
while (1){
for (int a=N;a>=0;a--)
std::cout <<test[a];
std::cout <<std::endl;
test[0]++;
for (size_t a=0;a<N-1;a++)
if (!test[a])
test[a+1]++;
if (!test[N-1])
break;
}

This will take a long time to complete. Incrementing N by 1 multiplies the running time by 256. N=8 should never finish, I think.


WOW Kudos mate. Shame I don't understand little bits of it however I'll work my way through it. Am I right in saying you've used an algorithm?

Thanks mate, glad SOMEONE helped me.
Last edited on
Am I right in saying you've used an algorithm?
... I suppose. Technically speaking, every program is an algorithm. This isn't what people think when they think "algorithm", though.
Brute force isn't an algorithm. It's merely a problem solving method.
Last edited on
Sorry to take up your time but when I run this nothing happens? Also if its possible whats different from my version to yours and how does your work?
My bad. I was going to do something else but forgot to update a different part in my head.
This one works, but you'll get something interesting if your send the output to the console:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

int main(){
	const size_t N=4;
	char test[N]={0};
	while (1){
		for (int a=N;a>=0;a--)
			std::cout <<test[a];
		std::cout <<std::endl;
		test[0]++;
		bool _break=0;
		for (size_t a=0;a<N;a++){
			if (!test[a]){
				if (a==N-1)
					_break=1;
				else
					test[a+1]++;
			}else
				break;
		}
		if (_break)
			break;
	}
}
I'm not sure it's what you want but you could do something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
srand((unsigned)time(0));
// Create a pseudo-random number between min and max inclusive:
int min = 0, max = 255, range = (max - min);

int randVal = min + int(range * rand()) / (RAND_MAX + 1.0)); // Create the pseudo-random number

unsigned char myChar[256];

for (int i = 0; i < sizeof(myChar); ++i) {
    myChar[i] = randVal;
}

myChar[255] = '\0'; // Null-terminate the array

std::cout << myChar;

if you want a pseudo-random number/character generator.
I'm fairly sure the range of an unsigned char is 0-255. I may be wrong, although I don't think I am.

It's non-standard but I guess you could also use the itoa function.

If that's nothing like what you want you should use Helios' solution. You want 0 - (upper bound of integer) right? Well that's what I think Helios is doing. Then, you could do 0-255 for an unsigned char if you want to do letters...
Last edited on
Ok thanks everyone for all your help, seems its a bit too advanced for me right now. I'll just stick with my calculators :)
Topic archived. No new replies allowed.