day 05
This commit is contained in:
parent
438ad24f77
commit
9960a5b436
29
05/part01.py
Executable file
29
05/part01.py
Executable 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
35
05/part02.py
Executable 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)
|
Loading…
x
Reference in New Issue
Block a user