Results 1 to 7 of 7

Thread: Possible logic error?

  1. #1
    Member Dissident85's Avatar
    Join Date
    Jun 2008
    Posts
    127

    Default Possible logic error?

    Hi all, itís been a while since I have been on here, how are we all? I have been playing around with making a program that will manipulate a wordlist to pipe into jtr. Now Iím not sure if there is a problem at all but I think there might be a logic error in a function I am playing around with. Now here is a chunk of the program (ill post the full source once it is finished)
    Code:
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    long int count = 0;
    void attcase (string str,int i){
         ::count++;
         cout << str << endl;
         while (i<str.length()){
             str[i]=toupper(str[i]);
             i++; attcase(str,i);
             str[i-1]=tolower(str[i-1]);
             } 
         return;    
    }
    int main(int argc, char *argv[])
    {
        attcase("abcdefghijklmnopqrstuvwxyz",0);
        cout << ::count << endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Now what the above program dose is take for example abc and turn it into abc, Abc, ABc, ABC, AbC, aBc, aBC, abC. Now it works with 3 letter words, but I am not confident that it works with longer words, which doesnít really make sense. But the totals that the program is giving me is different to what i am working out on a calculator. but it has been a long day and i could be making a simple maths error :S

    What do you think? Oh it can take a considerable time longer if your print every word to the screen but if you comment out ď cout << str << endl; ď it will run incredibly faster. And just give you a total at the end.

  2. #2
    Moderator KMDave's Avatar
    Join Date
    Jan 2010
    Posts
    2,281

    Default

    I've been dealing with the exact same problem some time ago. Haven't found the algorithm yet to solve the issue at hand but haven't had much time either for dealing with it.
    Tiocfaidh Šr lŠ

  3. #3
    Member Dissident85's Avatar
    Join Date
    Jun 2008
    Posts
    127

    Default

    I started this a few months ago as well, but ditch it because I couldnít find a efficient algorithm. But had an idea today and I think this one works. If it works for a 3 character string, it should work no matter what the length is. But it has been a long day and as I said before the numbers just arenít adding up right.

    I think I might just have to try it with a 5 character string and go thought it and check the output, but thatís just such a tedious process.

  4. #4
    Moderator KMDave's Avatar
    Join Date
    Jan 2010
    Posts
    2,281

    Default

    Yup it is. I might think over it again too. But that will need some more time. If you found a result before, just let me know
    Tiocfaidh Šr lŠ

  5. #5
    Good friend of the forums
    Join Date
    Jun 2008
    Posts
    425

    Default

    Code:
    str[i]=toupper(str[i]);
             i++; attcase(str,i);
             str[i-1]=tolower(str[i-1]);
    try this
    Code:
    str[i]=toupper(str[i]);
             i++; attcase(str,i);
             str[i-1]=tolower(str[i-1]);
        i++;
    is it meant to toupper [0] then lower[1] then upeer[2]

    I think at the moment it does
    upper [0] lower[1] upper[1] lower[2] upper[2]

  6. #6
    Member Dissident85's Avatar
    Join Date
    Jun 2008
    Posts
    127

    Default

    That code doesn’t work, I ran it with abc and I got this abc, Abc, ABc, ABC, abC
    After some sleep woke up this morning and had a look at my maths again and did a check on running it with 4 characters and 5 and from what I could see it works...
    With 4 characters
    Code:
    abcd
    Abcd
    ABcd
    ABCd
    ABCD
    ABcD
    AbCd
    AbCD
    AbcD
    aBcd
    aBCd
    aBCD
    aBcD
    abCd
    abCD
    abcD
    16

  7. #7
    Very good friend of the forum Virchanza's Avatar
    Join Date
    Jan 2010
    Posts
    863

    Default

    I dunno if your objective is to write this code on your own for fun or learning or whatever, but if you'd like someone just to throw a solution out there... well I have C code for this on my website, just scroll down to "Uppercase Lowercase Combinator". The code I wrote also takes into account that numbers and symbols don't have uppercase equivalents so it doesn't throw out extra passwords that are identical. My code should be pretty fast too, it doesn't deal with any dynamic memory allocation or fancy algorithms, it's pretty much just bitwise operations.

    http://virjacode.com/
    Ask questions on the open forums, that way everybody benefits from the solution, and everybody can be corrected when they make mistakes. Don't send me private messages asking questions that should be asked on the open forums, I won't respond. I decline all "Friend Requests".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •