Here is the code:

from cs50 import get_string
from sys import argv, exit
from crypt import crypt
from itertools import combinations
import string

if len(argv) != 2:
    exit("usage: python crack.py hash")

def main():
    hashed = argv[1]
    salt = hashed[0] + hashed[1]
    alphabet = list(string.ascii_lowercase) + list(string.ascii_uppercase)
    for i in range(6):
        word = combinations(alphabet,i)
        for x in word:
            if crypt("".join(x),salt) == hashed:
if __name__ == "__main__":

1 Answer 1


combinations returns the characters in sorted order, without repeats (picking same character twice). It will return "abc", but never "acb" or any other permutation, nor will it return "aab".

Use product instead.

And don't forget to exit after you found the password. There's nothing left to do then.

  • Yes that did the trick. Thank you so much.
    – Will
    May 3, 2019 at 4:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .