Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using itertools in Python password cracker

I made a simple password cracker:

import string as s
import itertools as it

things = s.ascii_letters

for digits in range(2, 6):
    for combo in it.combinations(things, digits):
        output = ''.join(combo)
        print(output)

but it doesn’t print out all possibilities.

For example, the last output this program gives out is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

VWXYZ

If I had a password starting with "X", the program wouldn’t be able to find it.

Is there any way I can fix this? What is wrong with my code?

>Solution :

Use itertools.product() with the repeat parameter. Using itertools.combinations() doesn’t allow for the same letter to be selected more than once:

import string as s
import itertools as it

things = s.ascii_letters

for digits in range(2, 6):
    for combo in it.product(things, repeat=digits):
        output = ''.join(combo)
        print(output)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading