python-3.xcombinationsbrute-forceword-list

Python Bruteforce (all possible combinations)


I want to generate all possible combinations from a-zA-Z0-9 and with my max string length.

So, for example, if I set the max length to 25, then my desired output is

a
...
z
aa
...
a1
...
zzzzzzzzzzzzzzzzzzzzzzzzz

So, generate all possible combinations and print each one to console I'm new in python, so I have no idea how to realize this...


Solution

  • It's going to take close to an eternity to run with e.g. max_length=25 (the number of possible combinations is astronomical), but I think this should do what you want (eventually):

    from itertools import combinations_with_replacement
    
    characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    
    max_length = 4
    
    for r in range(1, max_length+1):
        for combo in combinations_with_replacement(characters, r=r):
            print(''.join(combo))