Generating every possible combination

Hi,
because I've forgotten the password to my encrypted USB Stick but still know which characters I used in it I wanted to write a program that gives me an output of every possible combination.

To accomplish this I want to use recursive functions.

Thats the code so far(also I dunno how to use pointers for char arrays it gives an error whenever I'll try to use one on the array):
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
#include <iostream>
using namespace std;

int generator(char pass[],int anzahl, int lauf);

int main()
{
	//18 Array(19 Zeichen)
	char password[]={'a','c','d','e','h','i','k','M','n','o','r','s','u','V','v','.','-',','};
	generator(password, 0, 1);
	return 0;
}

int generator(char pass[],int anzahl, int lauf)
{
	for(int x=0; x<18; x++)
	{	
		cout << pass[x];
			
		if(x==17)
		{
			anzahl++;
		}
		
		if(anzahl == lauf and anzahl <= 40)
		{
				generator(pass, anzahl, ++lauf);
		}
		cout << endl;	
	}
	return 0;
}


In it's current form it gives no output as far as I could discover it its because of:
1
2
3
4
if(anzahl == lauf and anzahl <= 40)
		{
				generator(pass, anzahl, ++lauf);
		}


but why is that so? (also, I really suck at the logic part with recursive functions (at least when it comes to use them for something a bit more complex))
I really could need some tips,
Thanks
Last edited on
closed account (18hRX9L8)
See this post. It might be able to help you.
http://www.cplusplus.com/forum/beginner/14264/#msg69682
Well that would be really inflexible.
Also I think it would be a completely long mess of code to do loops for a length from 15 to 40.

I'm done now, thats 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	int pwstr[40];
	char password[]={'a','c','d','e','h','i','k','M','n','o','r','s','u','V','v','.','-',','};
	int maxclength=sizeof(password);
	int minlength=15;
	--minlength;
	int curlength=0;
	int curchar=0;
	bool a=true;
	
	
	if(curlength<minlength)
	{
		curlength=minlength;
		for(int x=0; x<=curlength; x++)
		{
			pwstr[x]=0;
		}
	}
	
	ofstream pwout("password.lst");
	
	
	for(int count=0; curlength<40; count++)
	{		
		if(count==maxclength)
		{			
			while(a==true)
			{
				
				if(pwstr[curchar]==17)
				{
					if(curchar==curlength)
					{
						for(int x=curlength; x>0; --x)
						{
							pwstr[x]=0;
						}
						curlength++;
						cout << curlength;
						pwstr[curlength]=0;
						a=false;
					}
					
					else
						curchar++;
				}
				
				else
				{
					for(int x=--curchar; x>=0; --x)
						{
							pwstr[x]=0;
						}++curchar;
					pwstr[curchar]++;
					a=false;
				}
			}
			a=true;
			curchar=0;
			count=0;
		}
		
		pwstr[curchar]=count;
		for(int x=curlength; x>=0; x--)
		{	
			pwout << password[pwstr[x]];;
			if(x==0)
				pwout << endl;
		}
	}	
	return 0;
}


But I realized it's impossible to get the password with brute force (its luks encryption so there would be 1or2 passwords per second) (I stopped after some minutes of passwordgeneration because i already had 50 million combination and it was nearly a scratch of everything).

Thanks for the help.
Topic archived. No new replies allowed.