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.