How to calculate and apply all possible char combinations

Pages: 12
I'm trying to figure out how to write a password cracking program that will try all possible char combinations for just two chars (without duplicating any combination guesses). Obviously, there would only be 4 possible truth table combinations for two boolean values, but how would a person calculate the number of all possible combinations for two values with 70 different possible chars?

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

using namespace std;

static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
/*
Boolean Truth Table for two values:
p   q
-----
T   T
T   F
F   T
F   F
Note that there are 70 chars in all specified above.
It will require much more than a simple truth table
to try every possible char combination (especially if
the password to be cracked is 2 or more chars). Using
this guy's code:
http://www.cplusplus.com/user/mausy131/
as a starting point, I'm writing a program that will
crack a password with a length of just 2 chars.
*/

int stringLength = 2;
char genRandom()
{
	return alphanum[rand() % stringLength];
}

int main()
{
	std::string password = "Sp";
	srand(time(0));
	std::string Str;
	for (int i = 0; i < 2; ++i)//"i" is the size of the string
	{
		Str += genRandom();		
	}
	while (Str != password){		
		cout << "Nope, wrong guess";
	}//currently results in an infinite loop
	cout << Str << endl;

	return 0;
}
how would a person calculate the number of all possible combinations for two values with 70 different possible chars?
Using school-level combinatorics. It is 70^2 = 4900 combinations.

You just need to generate all combinations of letters until two string are equal:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
std::string brute(const std::string& password)
{
    std::string guess(2, ' ');
    for(char c: alphanum) for(char d: alphanum) {
        guess[0] = c; guess[1] = d;
        if (guess == password)
            return guess;
    }
    return "";
}

int main()
{
    std::string password = "Sp";
    std::string answer = brute(password);
    if (answer != "")
        std::cout << "Password is " << answer;
    else
        std::cout << "No answer found";
}
Holy balls dude! I'm surprised with how little code it takes to make that work. Still though, I have a few questions about 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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";

std::string brute(const std::string& password)
//C++ is a sequential language, so how can the "string&"
//pointer point to the password variable when password
//is not even declared until below (in the main method)? 
{
	std::string guess(2, ' ');//Okay, two chars. But why
	                          //the empty quotes? Are they
	                          //initializing it?
	for (char c : alphanum) for (char d : alphanum) {
		//Nested for loops I presume? But how are they 
		//working without "char d : alphanum" being
		//nested in curly braces after the "char c alphanum"
		//for loop declaration statement?
		guess[0] = c; guess[1] = d;
		if (guess == password)
			return guess;
	}
	return "";//What is this return statement doing?
}

int main()
{
	std::string password = "Sp";
	std::string answer = brute(password);
	if (answer != "")
		std::cout << "Password is " << answer << endl;
	else
		std::cout << "No answer found" << endl;
}


Thanks for the help so far. In the mean time, I'm going to see if I can figure out how to modify the code to crack a 3 letter password.

One other thing. Will all school-level combinatorics work with exponents? In other words, are the following three statements correct?:
70^3 = 343000 combinations
70^4 = 24010000 combinations
70^5 = 1680700000 combinations

1
2
3
//C++ is a sequential language, so how can the "string&"
//pointer point to the password variable when password
//is not even declared until below (in the main method)?  
It is not a pointer, but reference. It will be created when function is called (in this case reference with name "password" will be created and bound to the passed argument).

1
2
3
//Okay, two chars. But why
//the empty quotes? Are they
//initializing it? 
They are not empty, they contain a character: space. This constructor does not have a default value for second argument, so I had to pass something to it. I decided to use space. Actualy it is irrelevant, as it is going to be overwritten right away.

1
2
3
4
//Nested for loops I presume? But how are they 
//working without "char d : alphanum" being
//nested in curly braces after the "char c alphanum"
//for loop declaration statement? 
You can have a single statement in the body of loops, conditional statements, etc. without needing braces. And outer loop has only one statement inside it: another loop. So braces are not needed here. On the other hand inner loop has more than one statement, so it needs braces around its body.

//What is this return statement doing?
It is returning an empty string. If no match for password is found, execution is going to leave loops and if we do not return string as we promised, we will get an undefined behavior which will break your program eventually. In addition to fulfilling our promise it is a way of telling user that we were not able to break his password.

I'm going to see if I can figure out how to modify the code to crack a 3 letter password.
Increase string size and add another loop. It is simple.

Will all school-level combinatorics work with exponents? In other words, are the following three statements correct?:
Do you mean "are those statements reflect amount of combinations for 3, 4 and 5 letter passwords, respectively"? If so, then yes, they do.
Not that I've got that working, I'm ready for you guys to help me start figuring out the tricky part. What if we don't know how many characters the password has? How do we get the program to dynamically keep trying all possible word combinations for a password that ranges from 1 character to 26 characters? Psuedo code hints would be awesome. Thanks in advance :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
guess = string NUM_CHAR length.

//Next portion should be in loop

for i = [0; NUM_CHAR)
    next = false;
    if guess[i] != last character in set
        guess[i] = next character in set
    else
        guess[i] = first character in set
        next = true
    if not next
        break;
 try password
Thanks again MiiNiPaa for your speedy reply. Using your pseudo code, this is what I've come up with so far:

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

using namespace std;

static const char alphanum[a] = //how else are we supposed to
                                //point to our alphanum array of 
								//70 possible chars other than using 
								//"[a]"?
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";

std::string brute(const std::string& password){

	int NUM_CHAR = 0;// = "password.length"? I'm still unsure
	                 //what NUM_CHAR should do. Is it just a 
 	                 //variable for the length of the password,
	                 //or something else?

	std::string guess(NUM_CHAR, ' ');

	for ((char i : alphanum); i < password.length; i++){
		//I know my for statement is wrong, but how else are we
		//supposed to tell the loop to keep iterating and trying
		//combinations of chars by using chars from the alphanum
		//array until we get a matching string?
		bool next = false;
		if (guess[i] != " "){//if we haven't encountered a blank 
			                 //space yet, we assume that we still 
			                 //have not yet gone past the final char
			                 //in the password string.
			guess[i] = alphanum[a];//get next char to be iterated and
			                       //tested for password combinatorics?
		}else{
			
			//MiiNiPa, I'm going to stop here for now, before I step into
			//a huge pile of crap, and over-confuse myself. The rest of 
			//the pseudo code can wait.

			/*
			guess[i] = first character in set
			next = true
			if not next
				break;
		try password
		*/
		}
	}
}
Line 8: do not tell compiler size of your array. Let it infer it from initialization string.
Line 19: NUM_CHAR is a currently tested number of characters. You need to increase it as you will finish testing of passwords of specific length. Also we need to initialize string to sensible value in ths case.
line 26 is completely wrong. We are changing letters manually and loop is needed so we could process all characters in line.
This part should work as mechanical counter https://www.google.ru/search?q=mechanical+counter&tbm=isch
When first character is not equal to the last in array of possible characters, we replace it with next one in array and break the loop. Else we replace it with first and go on to process next character: like carryover in mechanical counters work.
Observing what you said about Line 19, "You need to increase it as you will finish testing of passwords of specific length", would an approach like the following code be proper:

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
std::string guess(NUM_CHAR, ' ');

	for (char a : alphanum){
		guess[0] = a;
	}
	if (guess == password && NUM_CHAR == password.length){
		return guess;
	}
	else{
		for (char a : alphanum) for (char b : alphanum){
			guess[0] = a; guess[1] = b;
		}
		if (guess == password && NUM_CHAR == password.length){
			return guess;
	}
		else{
			for (char a : alphanum) for (char b : alphanum) for (char c : alphanum) {
				guess[0] = a; guess[1] = b; guess[2] = c;
		}
			if (guess == password && NUM_CHAR == password.length){
				return guess;
		}
			else{
				for (char a : alphanum) for (char b : alphanum) for (char c : alphanum) for (char d : alphanum) {
					guess[0] = a; guess[1] = b; guess[2] = c; guess[3] = d;
					//You get the idea...
			}
No. It is completely different. Those neat nested loops are working only if we know size of password. For string of unknows size we must simulate this behavior.

I'm not sure what you mean by "simulate this behavior". Also, don't forget that I want to tell the program to give up if the password is over 26 characters. That's as far as my

//You get the idea...

comment would have gotten up to if I finished writing all of my nested for loops. In any case, do we really need to check if NUM_CHAR is equal to the password length, or can we just cut it off all together?

Also, the link you gave me for the mechanical counter was not in English. I couldn't understand a single thing on my computer screen of your google image search. So, I did a google search of my own and found this:
http://stackoverflow.com/questions/2340073/multiple-counter-problem-in-for-loop

Is that anything like the link you tried to refer me to? If so, I'm still stuck, and I can't find a grasp on the logic that will change the following code to be dynamic:

1
2
3
4
5
6
7
8
9
std::string guess(3, ' ');//' ' space as default value for
	//next argument.   
	for (char a : alphanum) for (char b : alphanum) for (char c : alphanum) {

		guess[0] = a; guess[1] = b; guess[2] = c;
		if (guess == password)
			return guess;
	}
	return "";//in case a password is not matched 






do we really need to check if NUM_CHAR is equal to the password length
No. In fact we cannot. If we could, there would be better way to get password: guess = password;

I couldn't understand a single thing on my computer screen of your google image search
I always thought images do not have a language :P.

I meant something like this: http://ideone.com/P02oQm
So my nested if statements might work if I simply get rid of the
"&& NUM_CHAR == password.length"?

If not, I looked at the guy's code from your link, and have some /*questions*/

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

char letters[] = { 'a', 'b', 'c' };

template <typename T, std::size_t N>
std::size_t array_size(T(&)[N])
{
	return N;
}

bool next(std::string& in)/*What is this statement doing?*/
{
	for (std::size_t i = 0; i < in.size(); ++i)
		if (in[i] == letters[array_size(letters) - 1]){ //if current letter is last in set ...
					
		/*What does "last in set" mean? Is it talking about the 'c' in the letters array?*/

		in[i] = letters[0]; //Then we assign first letter and let loop continue
					
		/*What does "assign first letter" mean? How does the loop know what the correct char
		is before the loop has generated a combination of chars that matches the whole password
		string?*/
		}
		else {
			std::size_t pos = std::distance(std::begin(letters),/*What is meant by "distance" here?*/

				std::find(std::begin(letters), std::end(letters), in[i]));/*Try all chars in letter array, from 'a' thru 'c'?*/

			in[i] = letters[++pos]; //Else we assign next letter in set and return true
			return true; //As indication that it is not the last possible string
		}
		return false; //If loop finished, we exhausted all strings
}
Last edited on
/*What is this statement doing?*/
Mutates string setting it to the next in set of all possible combinations. If you run provided code you will see how is it done.
It returns true if there was no "rollover" (something like "ccc""aaa"), false otherwise. It works roughtly like next_permutaton from <algorithm>

/*What does "last in set" mean? Is it talking about the 'c' in the letters array?*/
Yes. array letters denotes a set of possible characters for string. We check if it is the last one (so we cannot take next) and assingn first instead.

/*Try all chars in letter array, from 'a' thru 'c'?*/
http://en.cppreference.com/w/cpp/algorithm/find
It returns pointer to the corresponding array element. casically I ask it to search for current string letter and return pointer to it.

/*What is meant by "distance" here?*/
http://en.cppreference.com/w/cpp/iterator/distance
It computes distance between two iterators. I use it to find distance between beginning of the aray and pointer to found element, i.e. index of element in array.

I increment this index and use it to assign next letter to the string.
I still don't understand what the significance of a rollover is (or why we need to prevent one).

If you look closely at this sample portion of http://ideone.com/P02oQm code's output:
1
2
3
4
5
6
7
8
9
10
11
12
13
b
c
a

ba
ca
ab
bb
cb
ac
bc
cc
aa


Notice that the first char of each combination goes in the consecutive pattern of 'b, c, a'. Why does it do that? Why isn't the pattern 'a, b, c' instead?

I also have more /*questions*/ in my updated 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
#include <iostream>
#include <iterator>
#include <algorithm>
#include <string>

//char letters[] = { 'a', 'b', 'c' };
static const char letters[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";

template <typename T, std::size_t N>
std::size_t array_size(T(&)[N])
{
	return N;
}

bool next(std::string& in)//Mutates string, setting it to the next in set of all possible combinations. 
						  //If you run provided code you will see how is it done. It returns true if there 
						  //was no "rollover" (something like "ccc" → "aaa"), false otherwise. It works 
						  //roughtly like next_permutaton from <algorithm>

						  /*I still don't fully understand what the significance of what a "rollover" is.
						  */
{
	for (std::size_t i = 0; i < in.size(); ++i)
		if (in[i] == letters[array_size(letters) - 1]){ //if current letter is last in set ...
					
		/**/

		in[i] = letters[0]; //Then we assign first letter and let loop continue

		/*In other words, we redirect the iterator to start from the beginning of
		the letters array, so that we can focus on the trying all 70 possible chars
		in our letters array for the next next char in our password guess string, 
		right?*/
		}
		else {
			std::size_t pos = std::distance(std::begin(letters),
				//computes distance between two iterators. I use it to find 
				//distance between beginning of the aray and pointer to found 
				//element, i.e. index of element in array.
																
				/*I increment this index and use it to assign next letter to the 
				string. This is done in the statement:
				"in[i] = letters[++pos];", right?*/

				/*Also by "two iterators", does it mean "begin(letters)"
				and "end(letters)"? If not, where did we declare 
				these two iterators in this code so far?*/

				std::find(std::begin(letters), std::end(letters), in[i]));
			//It returns pointer to the corresponding array 
			//element. casically I ask it to search for current 
			//string letter and return pointer to it.
																		  
			/*What does "casically" mean?*/

			in[i] = letters[++pos]; //Else we assign next letter in set and return true
			return true; //As indication that it is not the last possible string

			/*So does the if statement (that checks if the current combination of chars
			match the password string) go here then? My output would otherwise probably
			print a possible lengths of all possible char combinations, wouldn't it?*/
		}
		return false; //If loop finished, we exhausted all strings

}//closing brace of bool next 
Last edited on
/*I still don't fully understand what the significance of what a "rollover" is. */
Imagine a car mileage meter. It displays some value, like 0000, 0123, 5136, etc.
Now imagine, that it displays 9999. What next number will be? It would be 0000. It is like overflow with unsigned integers.

We detect rollover or overflow to know when we generated all combinations to avoid generating them second time.

/*I increment this index and use it to assign next letter to the string. This is done in the statement: "in[i] = letters[++pos];", right?*/
Yes.
/*What does "casically" mean?*/
Basically.

And note that lines 40 and 52 are part of a single expresion. They are divided in two lones to avoid really long lines.

/*So does the if statement (that checks if the current combination of chars match the password string) go here then? My output would otherwise probably print a possible lengths of all possible char combinations, wouldn't it?*/
No. Do not mix responsibilities. Only responsibility of next() should be generation of next string.

Ideally you should test your password where output statement is now.
And note that lines 40 and 52 are part of a single expresion. They are divided in two lones to avoid really long lines.


So then those two lines are our two iterators?

More /*questions*/ are in the following updated 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
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <iterator>
#include <algorithm>
#include <string>
#include <xutility>

//using namespace std;

//char letters[] = { 'a', 'b', 'c' };
static const char letters[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";

template <typename T, std::size_t N>/*Why can't this line just be "template <typename T>"?*/
std::size_t array_size(T(&)[N])
{
	return N;/*Is N only responsible for returning the size of the letters array?*/
}

bool next(std::string& in)//Mutates string, setting it to the next in set of all possible combinations. 
						  //If you run provided code you will see how is it done. It returns true if there 
						  //was no "rollover" (like preventing a car milage meter from displaying "0000"
						  //after exceeding "9999"), false otherwise. This is intended to prevent the
						  //generation of a possible combination more than once. "next" is a reference
						  //variable to the current combination being generated.
{
	for (std::size_t i = 0; i < in.size(); ++i)
		if (in[i] == letters[array_size(letters) - 1]){ //if current letter is last in set ...

		in[i] = letters[0]; //Then we assign first letter and let loop continue

		}//end of "if (in[i] == letters[array_size(letters) - 1])"
		else {
			std::size_t pos = std::distance(std::begin(letters),
				//Computes the distance between two iterators. It's used to find
				//the distance between the beginning of letters array and the pointer 
				//to the currently found element (to get the index of that element) in
				//the array.

				/*Where exactly in this code are the two iterators defined or declared?*/

				std::find(std::begin(letters), std::end(letters), in[i]));
			//It returns pointer to the corresponding array 
			//element. Basically I ask it to search for current 
			//string letter and return pointer to it.
																		  
			in[i] = letters[++pos]; //Else we increment the index and use it to assign 
			                        //the next letter in the set and return true.
			
			return true; //As indication that it is not the last possible string  
			
			/*Does this password tester belong here?
			std::string password = "97034031";
			if (in == password){
				std::cout << "The password is: " << in << std::endl;
			}
			*/

		}//end of else statement
		return false; //If loop finished, we exhausted all strings

}//closing brace of bool next

void print_all()
{
	/*constexpr*/const std:: size_t max = 10;//ERROR: error C2065: 'constexpr' : undeclared identifier
	for (std::size_t size = 1; size <= max; ++size) {//Generate sequences of all possible length
		//Create string of correspomding length. Note that we CANNOT use space as initializer
		//Or nothing would work at all.
		std::string guess(size, letters[0]);
		bool again = false;
		do { //Inner loop, generates all possible variation of given length
			again = next(guess); //Generate next string 
			/*see reference to class template instantiation 'std::iterator_traits<std::string>' being compiled ?*/
			std::string password = "97034031";
			if (guess == password){
				std::cout << "The password is: " << guess << std::endl;
			}
			//std::cout << guess << '\n';
		} while (again); /*Or should we use "while (guess != password)"?*/
		std::cout << '\n';
	}
}

int main()
{
	print_all();
}


And the output was:

1
2
3
4
5
6
7
8
9
1
1>  PasswordCracker.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2039: 'iterator_category' : is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>          c:\users\user\documents\visual studio 2013\projects\project1\project1\passwordcracker.cpp(135) : see reference to class template instantiation 'std::iterator_traits<std::string>' being compiled
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2146: syntax error : missing ';' before identifier 'iterator_category'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2602: 'std::iterator_traits<std::string>::iterator_category' is not a member of a base class of 'std::iterator_traits<std::string>'
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371) : see declaration of 'std::iterator_traits<std::string>::iterator_category'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2868: 'std::iterator_traits<std::string>::iterator_category' : illegal syntax for using-declaration; expected qualified-name
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
/*Is N only responsible for returning the size of the letters array?*/
Yes. It is called safe array size: if you call it on naything not an array, it will give you an error (unlike sizeof which often returns size of pointer instead of array)
/*Why can't this line just be "template <typename T>"?*/
Because then you cannot tell that you want an array here.

/*Where exactly in this code are the two iterators defined or declared?*/
We need to find index of current letter in array. It is a distance between beginning of the array and position of said letter. Beginning of array is easy: std::begin(letters). To find position of the letter we use std::find:
1
2
3
std::find( std::begin(letters), //Search from the beginning...
           std::  end(letters), //...to the end of the array...
           in[i] ) //...Looking for current letter 


//ERROR: error C2065: 'constexpr' : undeclared identifier
Visual studio STILL deos not support constexpr.

/*see reference to class template instantiation 'std::iterator_traits<std::string>' being compiled ?*/
I do not know what the problem is. Code is correct (if you delete xutility header) and should work.

/*Or should we use "while (guess != password)"?*/
Add return after outputting password.

I do not adwise to crack passwords more than 5 letters long. Or it will take huge amount of time.
Hey MiiNiPaa. I did everything you said, but I still have the same exact output problem.

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
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <iterator>
#include <algorithm>
#include <string>

//using namespace std;

//char letters[] = { 'a', 'b', 'c' };
static const char letters[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";

template <typename T, std::size_t N>/*Why can't this line just be "template <typename T>"? 
									Because then you cannot tell that you want an array here.*/
std::size_t array_size(T(&)[N])
{
	return N;/*It is called safe array size: if you call it on naything not an array, it will 
			 give you an error (unlike sizeof which often returns size of pointer instead of array)*/
}

bool next(std::string& in)//Mutates string, setting it to the next in set of all possible combinations. 
						  //If you run provided code you will see how is it done. It returns true if there 
						  //was no "rollover" (like preventing a car milage meter from displaying "0000"
						  //after exceeding "9999"), false otherwise. This is intended to prevent the
						  //generation of a possible combination more than once. "next" is a reference
						  //variable to the current combination being generated.
{
	for (std::size_t i = 0; i < in.size(); ++i)
		if (in[i] == letters[array_size(letters) - 1]){ //if current letter is last in set ...

		in[i] = letters[0]; //Then we assign first letter and let loop continue

		}//end of "if (in[i] == letters[array_size(letters) - 1])"
		else {
			std::size_t pos = std::distance(std::begin(letters),
				//Computes the distance between two iterators. It's used to find
				//the distance between the beginning of letters array and the pointer 
				//to the currently found element (to get the index of that element) in
				//the array

				std::find(std::begin(letters), std::end(letters), in[i]));//"in[i]" is the second iterator that
			                                                              //looks for the current letter being
			                                                              //pointed to in letters array
			
			in[i] = letters[++pos]; //Else we increment the index and use it to assign 
			                        //the next letter in the set and return true.
			
			return true; //As indication that it is not the last possible string  
						
		}//end of else statement
		return false; //If loop finished, we exhausted all strings

}//closing brace of bool next

void print_all()
{
	std::string password = "97034031";//password to be guessed
	const std:: size_t max = 10;//maximum password string length to guess for 
	for (std::size_t size = 1; size <= max; ++size) {//Generate sequences of all possible length
		//Create string of correspomding length. Note that we CANNOT use space as initializer
		//Or nothing would work at all.
		std::string guess(size, letters[0]);
		bool again = false;
		do { //Inner loop, generates all possible variation of given length
			again = next(guess); //Generate next string 			
			/*see reference to class template instantiation 'std::iterator_traits<std::string>' being compiled
			"next" is defined in my other "bool next" function. Do I need a pointer to it or something?*/
			//std::cout << guess << '\n';
		} while (guess != password);//while (again); 
		if (guess == password){
			std::cout << "The password is: " << guess << std::endl;
		}
		else{
			std::cout << "Sorry, no matching password was found." << std::endl;
		}
		return;
		//std::cout << '\n';

	}//end of for loop
}

int main()
{
	print_all();
}


I'm not sure, but the following link might help us:
http://stackoverflow.com/questions/4217733/distance-calculation-error-in-c
Code is compiling, but you are broke loop logic by changing inner loop condition, despite I warned you about it and told other solution to you.

Also, password is too big to be guessed.
Pages: 12