#!/usr/bin/python
################################################################################
# wordlistgen.py v 1.0
#
# @date:    10.12.2010
# @author:  Petr Juhanak
# @website: www.juhanak.cz/security
################################################################################

import string
  
def iterateTo(lim):
    """allows iteration 0 to lim-1"""
    num = 0
    while num < lim:
        yield num
        num = num + 1

def genDictionary(alphabet, positions):
    """generates all characters combination over defined alphabet and word length (possitions)"""
    
    a_base = len (alphabet)
    states_num = long(a_base**positions)
    
    # state vector
    conf = [alphabet[0]]*positions

    for state in iterateTo(states_num):
        div = state
        
        # walk through positions in reverse order, 
        # compute complement and divider for each position
        for pos in range(positions-1,-1,-1):
            comp = div % a_base
            div = div / a_base
            conf[pos] = alphabet[comp]
        
        # conversion list to string without space
        print string.join(conf,"")

# Define your alphabet          
################################################################################
ALPHABET_01    = "01"
ALPHABET_AZ_LC = "abcdefghijklmnopqrstuvwxyz"
ALPHABET_AZ_UC = "ABCDEFGIJKLMNOPQRSTUVWXYZ"
ALPHABET_NUM   = "0123456789"
ALPHABET_SPEC  = "_.!#$%^&*,()+-"
################################################################################
# and start with current one
alphabet = ALPHABET_AZ_UC.join(ALPHABET_NUM)
for word_length in range(3,5):
    genDictionary(alphabet, word_length)
