Hello, for awhile now I've been trying to make a "string generator" that is, something similar to something that might be used in a hash bruteforcer or something. Well, of course I thought it would be logical to take up the string permutations challenge, but how then would I allow it to make all combinations of a selected character set with a selected size.
Well, being the noob that I am I gvae up and started translating a PHP one back into C++ for whatever reason. But, now I just seem to be encountering problems, mainly with the use of the position [] array I believe. I would try to follow the logic of the program through on pen and paper, but I really couldn't get my head around the logic for this program.
How about I just give you the code and mark what I'm being stupid on:
test.cpp
Code:
#include "test.h"
BruteForce::BruteForce()
{
//Initialize variables
wordLength = 0;
charNumber = 0;
maxNumber = 0;
depth = 0;
characters = new char[27];
//Fill up the array
for(char i = 'A'; i <= 'Z'; i++)
characters[i - 'A'] = i;
}
BruteForce::BruteForce(int len, char* set)
{
//Initialize variables, sorry for C/C++ raping
wordLength = len;
depth = 0;
memset(word, 0, len);
characters = new char[len + 1];
characters = set;
charNumber = strlen(characters);
maxNumber = pow(charNumber, len);
//I don't even understand position []
//So I'm giving it a lot of space to work with
//Set it all to zero. Bad n3wb technque
for(int i = 0; i <= 1000; i++)
position[i] = 0;
}
char * BruteForce::getNext()
{
//Should be something here to tell it to stop
//By checking position[0] against wordLength?
position[0]++;
depth = 0;
getWord();
return word;
}
BOOL BruteForce::getWord() {
int result = true;
if(depth < wordLength)
{
result = false;
depth++;
//Basically I'm not getting my head around what
//position[depth] should look like.
sprintf(word, "%s%c", word, characters[position[depth]]);
if(getWord())
{
position[depth]++;
if(position[depth] == charNumber)
{
position[depth] = 0;
result = true;
}
}
depth--;
}
return result;
}
int main() {
BruteForce* bruteForce = new BruteForce(3, "aaa");
//Yes, should stop somewhere, not jsut while(1)
while(1) { printf("%s\n", bruteForce->getNext()); }
return 0;
}
test.h
Code:
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <malloc.h>
class BruteForce {
public:
char* getNext();
BOOL getWord();
BruteForce();
BruteForce(int len, char* set);
private:
int wordLength;
char word[5]; //I don't really know
int position[1000]; //I don't really know
int charNumber;
double maxNumber;
int depth;
char* characters;
};
But anyways, the output seems "almost good" but not really, there's a clear attempt to make something though
aaa
aaaaaa
aaaaaaaaa
aaaaaaaabaa
aaaaaaaacaaaaM
aaaaaaaadaaaaMai
*Crash*
There's some clear attempt to do an abcd in column, what, column 9 of that for some reason. I'm just having a lot of trouble making a flow chart for my project, any help is appreciated. Sorry if maybe this looks like homework or if I'm dumping a big load on you. For some reason it's been my goal for awhile to make some sort of hash brute-forcer not for any malicious reasons at all just because it feels like a fun experience.