1

I'm stuck on Crack (in Python). I wrote the following code, which I think should cover every case, however it runs for hours without finding a solution. Any thoughts/advice are appreciated.

from sys import argv
import string
import crypt
import itertools

hash = argv[1]

# remove username from string
colon_index = hash.find(":")
#find the salt used as part of crypt.crypt
salt = hash[colon_index + 1:colon_index + 3]
#the hashed password including salt, to be used for comparison
hash_and_salt = hash[colon_index + 1:]

# list of uppercase and lowercase english letter alphabet
dictionary = list(string.ascii_lowercase) + list(string.ascii_uppercase)

# using itertools and itertools.combinations to create every possible letter combination
# check for success in finding password
for pwdCheck in range(0, len(dictionary)+1):
    for subset in itertools.combinations(dictionary, pwdCheck):
        pwdString = ''.join(subset)
        print(crypt.crypt(pwdString, salt))
        if crypt.crypt(pwdString, salt) == hash_and_salt:
            print("Found!")
            break
2

Two things. First, and foremost, your program will keep going after it finds the password because your break only breaks out of the inner for loop. After finding the password, you should exit immediately.

Second, printing the crypted possibilities will really slow down the program. And it masked the first problem, since your "Found!" was printed in amongst all those possibilities.

| improve this answer | |

You must log in to answer this question.

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