Thread: help with password list generator

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    help with password list generator

    I'm trying to do a password list. I wan to be able to save in a file all possibles combination up to a determine length. The list should start with 0,1,3.....a,b,c.....0a,0b,0c, etc. all I have been able to do is do the list with only all possible combinations for the determine length only example if length is 3 the list starts with 001,002,003.... instead of 0,1,2.....001,002,003,etc. Can somebody help with this I'm stuck and out of ideas. Thanks a lot!!!
    This my code so far
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void printAllPossiblePasswords(int length, const char* charset){
        char* str;
        const char** counters;
        int i;
        FILE *password;
    
    	password=fopen("passwords.txt", "w+");
        str = malloc(length+1);
        counters = malloc(sizeof(char*)*(length + 1));
        counters[length] = 0;
        str[length] = 0;
        for (i = 0; i < length; i++)
        {
            counters[i] = charset;
        }
    
        while(1)
        {
            for (i = 0; i < length; i++)
    	    str[i] = *(counters[i]);
    
            fprintf(password,"%s\n", str);
    
            counters[0]++;
            for (i = 0; (i < length) && (*(counters[i]) == 0); i++)
            {
                counters[i] = charset;
                counters[i+1]++;
            }
    
            if (i == length)
    	    break;
        }
    
        free(str);
        free(counters);
        fclose(password);
    }
    
    int main ()
    {
    
        int length;
    
        system("clear");
        printf("****************Password Hash Generator****************\n");
    	printf("Enter the length of the password:");
    	scanf("%d",&length);
    	printf("Generating list...\n\n");
        printAllPossiblePasswords(length, "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM[]-=;'\\,./!@#$%^&*()_+{}:\"|<>?~`");
        //printAllPossiblePasswords(length, "1234567890qwertyuiopasdfghjklzxcvbnm");
    
        FILE *hash;
        hash = popen("openssl passwd -salt -crypt -in \"passwords.txt\" > \"hashes.txt\"", "r");
        pclose(hash);
    
        printf("With great powers  come great responsabilities!");
    
        return 1;
    }

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Code:
    for (int length = 1; length <= length_you_need; ++length) {
         run_your_program(length);
    }

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    First, I'd decide whether you want all possible combinations, or all possible *permutations*, and whether lowercase and uppercase letters will be treated as the same letter (case insensitive), or not.

    Then, someone can help you out.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    Is case sensitive and all possible combination. Example if length is 3 it should start with 0,1,2... all the up to ))) or zzz however you want to see it.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Probably not the most efficient, but one way is to use recursion
    Code:
    std::vector<std::string> all_combinations(int length);
    For length = 1, just use a loop.

    For length > 1, use a loop + all_combinations(length - 1)

    *edit*
    oops, C forum.

    Basically, you need to return a list of strings (possibly as a parameter).
    */edit*
    Last edited by cyberfish; 02-12-2009 at 02:26 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  2. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  3. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  4. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM