36 lines
987 B
Python
36 lines
987 B
Python
![]() |
#!/usr/bin/env python
|
||
|
|
||
|
import argparse
|
||
|
import hashlib
|
||
|
|
||
|
def main(args):
|
||
|
seq = 0
|
||
|
password = " "
|
||
|
|
||
|
while True:
|
||
|
char_input = "{}{}".format(args.input, seq)
|
||
|
m = hashlib.md5()
|
||
|
m.update(char_input.encode('utf-8'))
|
||
|
h = m.hexdigest()
|
||
|
if h.startswith('00000'):
|
||
|
pos = h[5]
|
||
|
if pos not in "01234567":
|
||
|
seq += 1
|
||
|
continue
|
||
|
pos = int(pos)
|
||
|
char = h[6]
|
||
|
if password[pos] == " ":
|
||
|
password = password[:pos] + char + password[(pos+1):]
|
||
|
print("id: {}, pass: {}, hash: {}".format(seq, password, h))
|
||
|
if " " not in password:
|
||
|
break;
|
||
|
seq += 1
|
||
|
print(password)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
parser = argparse.ArgumentParser(description='AdventOfCode 2016 Day 01')
|
||
|
parser.add_argument('--input', '-i', action='store', required=True, help='input file')
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
main(args)
|