diff --git a/05/part01.py b/05/part01.py new file mode 100755 index 0000000..b5abf24 --- /dev/null +++ b/05/part01.py @@ -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) diff --git a/05/part02.py b/05/part02.py new file mode 100755 index 0000000..927fc9c --- /dev/null +++ b/05/part02.py @@ -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) diff --git a/README.md b/README.md index 57563e7..2dd1ae2 100644 --- a/README.md +++ b/README.md @@ -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?