Hello.
I am working on a project for computer security, where we are to write code in C++ that will come up with a random string of k characters (k being 1-7, each to be done 10 times). This random string consists only of all 26 capital letters. This random string will serve as a password, and two functions will generate random passwords to compare and engage in a brute force sequential attack respectively.
After both functions have been carried out, I am to record how many attempts it took out of how many possible attempts there are for each one, average all ten per k value, and then graph the results. This part doesn't matter too much here, since it's pretty self-explanatory.
I have started on this project with some help from friends, who have helped me to write a random string generator, but that is the extent of our progress. The generator debugs just fine, but no results turn up. Whenever I run the code, I included a statement to see if it was coming up with anything, and all it gave me was "The string is ."
Naturally, I'm using the same generator twice, once to come up with the password, and again to come up with random ones to compare to the password, but this leads me to the second help.
I have no idea how to write a brute force script. Someone told me to look at it as writing a Base-26 counting machine, but that doesn't help me any. Can someone help me out with this?
tl;dr
1. Random String Generator not actually coming up with string. See code below
2. How do I write a string generator that goes "A, if not A then B, if not B then C, if not C then D..." and will even increment the ten position so to speak if AZ doesn't match when I get to 2 digits, and so on.
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; int stringLength = x; string randomStrGen(int length); int main() { cout << "Enter a value to serve as string length: "; cin >> x; cout << endl << endl; string a; string b; a = randomStrGen(stringLength); int c = 0; cout << "The compare string is "<< a << "." << endl << endl; while (b != a) { c++; b = randomStrGen(stringLength); } cout << "It took " << c << " attempts to crack this password." << 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; }