Results 1 to 2 of 2

Thread: BruteForcing with Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Question BruteForcing with Qt

    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:
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QDebug>
    3. void BruteForce(int min, int max, QString charset);
    4. void recurse(int width, int pos, QString s, QString charset);
    5. int main(int argc, char *argv[])
    6. {
    7. QCoreApplication a(argc, argv);
    8.  
    9. BruteForce(1,3,"abcdef");
    10.  
    11. return a.exec();
    12. }
    13.  
    14. void BruteForce(int min, int max, QString charset)
    15. {
    16. for (int i=min; i<=max; i++)
    17. {
    18. qDebug() << "Checking with" << i << "char " << endl;
    19. recurse(i,0,"",charset);
    20. }
    21. }
    22.  
    23. void recurse(int width, int pos, QString s, QString charset)
    24. {
    25. QChar c;
    26. for (int i=0;i<=charset.length();i++)
    27. {
    28. if (pos < width - 1)
    29. {
    30. recurse(width, pos+1 , s + c , charset);
    31.  
    32. }
    33. c=charset[i];
    34.  
    35. qDebug() << s+c;
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: BruteForcing with Qt

    The first time through the for loop in the recurse() function, the variable "c" has been declared but is unassigned, probably contains garbage. Who knows what appending it to "s" does in that case.

    Aside from the fact that you're using QString and QChar, what does this have to do with Qt? It's a basic C++ programming error problem.

    By the way, "BruteForce" and "recurse" are very clever names for functions. I am sure when you look at this code a year from now, you'll be able to tell from the names exactly what those functions are supposed to do, assuming you ever get them to do what you intend for them to do.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.