silur
23rd August 2012, 14:21
Hi i'm creating a BruteForce function in Qt and altough this code works in my Python version the C++ seems to be a little buggy:
#include <QtCore/QCoreApplication>
#include <QDebug>
void BruteForce(int min, int max, QString charset);
void recurse(int width, int pos, QString s, QString charset);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
BruteForce(1,3,"abcdef");
return a.exec();
}
void BruteForce(int min, int max, QString charset)
{
for (int i=min; i<=max; i++)
{
qDebug() << "Checking with" << i << "char " << endl;
recurse(i,0,"",charset);
}
}
void recurse(int width, int pos, QString s, QString charset)
{
QChar c;
for (int i=0;i<=charset.length();i++)
{
if (pos < width - 1)
{
recurse(width, pos+1 , s + c , charset);
}
c=charset[i];
qDebug() << s+c;
}
}
and my output:
....
"aed"
"aee"
"aef"
"ae
"af"
"afa"
"afb"
"afc"
"afd"
"afe"
"aff"
"af
"a
"b"
"b
"b
"b
"b
"b
"b
"b
"ba"
"baa"
"bab"
"bac"
"bad"
"bae"
"baf"
"ba
"bb"
......
as you can see it goes trough aaa to aaf and check again ? aa ?
after a 3 character check it prints the actual item in the cahrset in [charset lenght] times O.o
any guesses?
#include <QtCore/QCoreApplication>
#include <QDebug>
void BruteForce(int min, int max, QString charset);
void recurse(int width, int pos, QString s, QString charset);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
BruteForce(1,3,"abcdef");
return a.exec();
}
void BruteForce(int min, int max, QString charset)
{
for (int i=min; i<=max; i++)
{
qDebug() << "Checking with" << i << "char " << endl;
recurse(i,0,"",charset);
}
}
void recurse(int width, int pos, QString s, QString charset)
{
QChar c;
for (int i=0;i<=charset.length();i++)
{
if (pos < width - 1)
{
recurse(width, pos+1 , s + c , charset);
}
c=charset[i];
qDebug() << s+c;
}
}
and my output:
....
"aed"
"aee"
"aef"
"ae
"af"
"afa"
"afb"
"afc"
"afd"
"afe"
"aff"
"af
"a
"b"
"b
"b
"b
"b
"b
"b
"b
"ba"
"baa"
"bab"
"bac"
"bad"
"bae"
"baf"
"ba
"bb"
......
as you can see it goes trough aaa to aaf and check again ? aa ?
after a 3 character check it prints the actual item in the cahrset in [charset lenght] times O.o
any guesses?