This Forum References:
Programming in C++
The time has come. Your destiny is taking shape. You are taking your next big leap in your journey of becoming the greatest software developer the world has ever seen! Well maybe... Don't hold us liable for that or anything...
String
If you really wanted you could do something like this:
int maxStringLength = 5;
for (int i = 1; i <= maxStringLength; i++)
{
//start string here as ""
for (int j = 0; j < i; j++)
{
//build string to compare with here by adding characters
//you could start with char x = 'a' + j
}
}
Hope that get's you back on track! Let me know how it goes.
Bryan
Once I wrote it all down and actually assigned some variable names I realised that i needed something to tick over every time it tried all the letters. I remember "clock" functions doing these (well, mod).
I designed a little loop to "tick" over every time the end letter went through it's 26 letters. For that you need to establish if the last letter is multiples of 26 (straight calculation of how many iterations we are up to, "counter" with the number of letters) with the char from the end, you need to see the whole number (counter/26^1) which is 0 until 27 and then it's 1. 1%26 = 1. so that would tick over the second char to the char(97) + 1. - complex to exmplain so here's my code ...
I'm quite the captain chuffy at the moment ... (if you couldn't tell!)
Now, back to the "real learning" ...
Brad
int findPassWord(string actualPassWord)
{
clock_t startTime;
startTime = clock ();
int pwLength = actualPassWord.length();
string userPassWord(actualPassWord);
char* pw ;
pw = (char* )malloc(pwLength+1); //allocate the amount of memory needed by pw
//initialise the pw to all 'a's.
for (int j = 0; j < pwLength; j++) {pw[j] = char(97);}
int numPossibleChars = 26; //(a-z)
for (int counter = 0; counter < pow(numPossibleChars,pwLength); counter++)
{
// step through each char in the pasword and set it based on where we are with the coutner
for (int i = 0; i < pwLength; i++)
{
/* below is a term "counter/pow(numPossibleChars,i)%numPossibleChars" which will cycle through all chars needed (a-z for example) and then at multiples of 26, will increment the next one by 1). */
pw[i] = (char)(97+((int)(counter/pow(numPossibleChars,i))%numPossibleChars));
if (pw==userPassWord)
{
cout << "Hey Buddy, you guessed my password ... \"" << pw << "\" in " << (clock() - startTime)/1000 << " seconds" << endl;
return 0; // is there a better way of returning??
}
}
}
free(pw);
cout << "Program Failed to get password" << endl;
return 0;
}
Cheers,
cbrad.)
"You are taking your next big leap in your journey of becoming the greatest software developer the world has ever seen!" -
the best first post i could possibly read! 
Glad I joined
___________________________________________
mp4 to avi http://freemp4toaviconverter.com/
Forum Rules/Features
Welcome to the WiBit.net forums! Check out our terms and features:
Hot Topic(s)
Annoy your friends
Is this something you think someone else would enjoy? Is it not for you, but do you know someone who is down with this type of content? Well share away:
Tweet
The Blog
Don't Let XML Make You a Cheater
This blog is a reminder that cheating in software development can get you into big trouble. Sometimes developers get really really lazy, OR are pressured to write something using overly simplified data structures. Almost every time this happens you are bitten in the butt! Sometimes the problems show up immediately and other times it may take months or years (especially in integrated systems).
- 1 of 78
- ››























My little project that couldn't ...
I've taken it upon myself to play with some loops and thought to see how long would it take for a good computer to guess my password using brute force. It seems harder than I first thought.
if I know the length of the password (let's say 3) it's easy as it's a nested loop with three levels that tests all combinations aginst the supplied string. This extends to an "n" length password will need an "n" level nested loop - easy peasy.
e.g. for 3 character pw
aaa, aab, aac, ... , aaz, aba, abb, abc, ..., abz, aca ... it's 27^3 = 20000 iterations but is okay.
THE QUESTION IS: could you give me a hint of how to dynamically loop an "n" length string? Seems hard and maybe at this early stage I don't have all the tools I need.
I toyed with goto statements, while loops, etc but keep coming up against an impass. I don't know get the nested loop I need to do this. I searched google for a few things but the only one I found was in c# and it just tested to see if passwordTest(i) = suppliedPassword(i) which is easy to do and not what I was going for.
I thought of making a 2D array of my possible characters and somehow using that
{a, a, a
b, b, b,
c, c, c}
I think I then run into the same issues - how do I increment one leve at a time while cycling thorugh all possibilities?
Please put me out of my misery ...
Cheers,
cbrad.)