Part 1
In this puzzle we are asked to find a password found by mining. A string made from a seed and an increasing integer is md5-hashed until the hashed begins with 5 zeroes. The 6 digit is then saved as the next character of the password. This is repeated until the password is 8 characters long.
To solve it, we basically only have to follow the algorithm described. We count from 0, build the string, hash it and search for valid hashes to add to the password until we found all digits.
password = ""
for i in count(0):
string = initial_password + str(i)
m = hashlib.md5(string.encode())
hash = m.hexdigest()
if hash[:5].startswith("00000"):
password += hash[5]
if len(password) == 8:
return password
Part 2
In part 2, the construction of the password is made more difficult. In valid hashes the 6th digit is now the position for the 7th digit, so "000001f..." means put character "f " at position "1".
To solve this harder version, we modified the part of the function after we found a valid hash. We take the 6th and 7th digits and only update if the password has no valid character it this position.
password = list("-" * 8)
#...
if hash[:5] == "0" * 5:
pos = hash[5]
value = hash[6]
if pos.isdigit() and int(pos) < 8:
pos = int(pos)
if password[pos] == "-":
password[pos] = value
No comments:
Post a Comment