Yesterday, I posted a thread asking for help on a random string generator. Well, I have gotten that to work properly now, but now I need help on something else. Also, you may notice my directions have changed. I misunderstood the instructions on my homework, and they have since been fixed.
The instructions on my project are to write a program in C++ that will randomly generate a string with only capital letters to serve as a password. This password will then be subjected to a brute force attack (AAAAAAA, AAAAAAB, AAAAAAC... AAAAAAZ, AAAAABA, ... ZZZZZZZ), and this is where I need help. I don't know how I would write something in C++ that would logically count upwards in letters, and not numbers (since this is essentially counting in base-26).
tl;dr, how would I write something that would count upward with only letters instead of numbers, using the same sort of logic?
Here is the code. The function for the brute force attack is at the very bottom, and as you can see, I did copy the variable declarations from my random generator since it should be somewhat the same in composition.
Code:
// Trey Brumley
// Topics in Computer Security
// Dr. Nelson J. Passos
// Class Project: Password Cracking
// =================================
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int x;
string randomStrGen(int length);
string bruteForceGen(int length);
int main()
{
char d = 'Y';
while (d != 'N')
{
restart:
cout << "Enter a value to serve as string length: ";
cin >> x;
cout << endl << endl;
string a = randomStrGen(x);
string b;
int c = 0; // running the two separately.
cout << "The compare string is "<< a << "." << endl << endl; // Makes sure a string is being properly stored in a.
while (b != a)
{
c++;
b = randomStrGen(x);
}
cout << "It took " << c << " attempts to crack this password." << endl << endl;
cout << "Would you like to crack another password? (Y or N) ";
cin >> d;
cout << endl;
if (d == 'N')
{
system("pause");
return 0;
}
else if (d == 'Y')
goto restart;
else
{
cout << "Invalid character. Please enter Y to run again or N to quit: ";
cin >> d;
cout << endl << endl;
}
}
system("pause");
return 0;
}
string randomStrGen(int length)
{
static string charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string result;
result.resize(length);
for (int i = 0; i < length; i++)
result[i] = charset[rand() % charset.length()];
return result;
}
string bruteForceGen(int length)
{
static string charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string result;
result.resize(length);
return result;
}