advent/2016/05.py

27 lines
517 B
Python
Raw Permalink Normal View History

2017-01-14 00:34:25 +00:00
# Python!
import hashlib
string = b'ffykfhsq'
password = 'xxxxxxxx'
print(password)
i = 0
while True:
hash_input = string + str(i).encode()
hash_output = hashlib.md5(hash_input).hexdigest()
index = -1
try:
index = int(hash_output[5])
except ValueError:
pass
if hash_output[:5] == '00000' and 0 <= index <= 7 and password[index] == 'x':
password = password[:index] + hash_output[6] + password[index + 1:]
print(password)
if 'x' not in password:
break
i += 1
print('Full password:', password)