|
5 | 5 | class Solution(solution.Solution):
|
6 | 6 | def __init__(self, nr):
|
7 | 7 | super().__init__(nr)
|
8 | | - self.password = "" |
| 8 | + self.password1 = "" |
| 9 | + self.password2 = list("--------") |
9 | 10 |
|
10 | 11 | def calculate(self, test=False):
|
11 | 12 | self.read_instructions()
|
12 | 13 |
|
13 | 14 | def read_instructions(self):
|
14 | 15 | self.read_input()
|
15 | | - self.calc_password() |
16 | | - self.set_solution(1, self.password) |
| 16 | + self.calc_passwords() |
17 | 17 |
|
18 | | - def calc_password(self): |
| 18 | + def calc_passwords(self): |
| 19 | + pos1 = 0 |
| 20 | + calced2 = 0 |
19 | 21 | index = -1
|
20 | 22 | m = hashlib.md5()
|
21 | 23 | m.update(self.input.encode('utf-8'))
|
22 | | - foriinrange(0, 8): |
| 24 | + whilenotself.is_calculated(1) ornotself.is_calculated(2): |
23 | 25 | while True:
|
24 | 26 | index += 1
|
25 | 27 | mc = m.copy()
|
26 | 28 | mc.update(str(index).encode('utf-8'))
|
27 | 29 | md5 = mc.hexdigest()
|
28 | 30 | if md5[:5] == "00000":
|
29 | | - self.password += md5[5] |
| 31 | + if not self.is_calculated(1): |
| 32 | + self.password1 += md5[5] |
| 33 | + pos1 += 1 |
| 34 | + if pos1 > 7: |
| 35 | + self.set_solution(1, self.password1) |
| 36 | + if not self.is_calculated(2): |
| 37 | + if md5[5].isdigit() and -1 < int(md5[5]) < 8: |
| 38 | + if self.password2[int(md5[5])] == "-": |
| 39 | + self.password2[int(md5[5])] = md5[6] |
| 40 | + calced2 += 1 |
| 41 | + if calced2 > 7: |
| 42 | + self.set_solution(2, "".join(self.password2)) |
30 | 43 | break
|
0 commit comments