Search code examples
pythonhashsha1python-itertoolsbrute-force

Making all possible 6 digit combinations of digits and alphabets


I am trying to do a brute force on one hash key i have , key is 28 bit and i have to find password which is 6 digit and includes 0-9 and a-z like 36 total possibilities for each place.

I am using macbook with 16gb of ram but when i run following code it takes forever and eventually kills the process for using too much memory what i want to know is how to overcome it and secondly is it possible that instead of waiting for this whole loop to finish and then iterative abc to get all combinations and then passing them to SHA1 hash function i can pass combinations to hash function as they are being generated

abc = [''.join(i) for i in itertools.product("0123456789abcdefghijklmnopqrstuvwxyz",repeat=6)]

Solution

  • Don't create the list just iterate over the itertools.product object getting one value at a time to avoid storing all in memory at once:

    for ele in  itertools.product("0123456789abcdefghijklmnopqrstuvwxyz",repeat=6):
        print("".join(ele))
    
    000000
    000001
    000002
    000003
    000004
    000005
    000006
    000007
    000008
    000009
    00000a
    00000b
    00000c
    00000d
    00000e
    00000f
    00000g
    00000h
    00000i
    00000j
    00000k
    00000l
    00000m
    00000n
    00000o
    00000p
    00000q
    00000r
    00000s
    00000t
    00000u
    00000v
    00000w
    00000x
    00000y
    ...............