-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day5.py
28 lines (27 loc) · 987 Bytes
/
Day5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import hashlib
id = "ffykfhsq"
num_zeros = 5
password_length = 8
found_characters_1 = []
found_characters_2 = [None] * password_length
i = 0
while len(found_characters_1) < password_length or None in found_characters_2:
m = hashlib.md5()
m.update((id + str(i)).encode("utf-8"))
hashed = m.hexdigest()
if hashed.startswith("0" * num_zeros):
c = hashed[num_zeros]
c_2 = hashed[num_zeros+1]
print("[Part 2] Iteration %d: Character in hash %s: %s at position %s" % (i, hashed, c_2, c))
try:
idx = int(c)
if idx < password_length and found_characters_2[idx] is None:
found_characters_2[idx] = c_2
except ValueError:
pass
if len(found_characters_1) < password_length:
print("[Part 1] Iteration %d: Character in hash %s: %s" % (i, hashed, c))
found_characters_1.append(c)
i += 1
print("".join(found_characters_1))
print("".join(found_characters_2))