This commit is contained in:
Peter Hudec 2018-01-16 14:03:41 +01:00
parent 438ad24f77
commit 9960a5b436
Signed by: peter.hudec
GPG Key ID: 427BD558E277E410
3 changed files with 65 additions and 0 deletions

29
05/part01.py Executable file
View File

@ -0,0 +1,29 @@
#!/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'):
password = "{}{}".format(password, h[5])
print("id: {}, hash: {}".format(seq, h))
if len(password) == 8:
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)

35
05/part02.py Executable file
View File

@ -0,0 +1,35 @@
#!/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)

View File

@ -8,3 +8,4 @@
- **Day 2**: Bathroom Security
- **Day 3**: Squares With Three Sides
- **Day 4**: Security Through Obscurity
- **Day 5**: How About a Nice Game of Chess?