Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #aoc_2015_14.py
- import hashlib
- import itertools
- salt = "yjdafjpo"
- pad = []
- def make_hash(s,i):
- '''
- '''
- text = s + str(i)
- hashkey = hashlib.md5(text.encode('utf-8')).hexdigest()
- return hashkey
- def extend_hash(h):
- '''
- '''
- for x in range(2016):
- h = hashlib.md5(h.encode('utf-8')).hexdigest()
- return h
- previous_hashes = {}
- while len(pad) < 5:
- for x in itertools.count(0):
- test_key = extend_hash(make_hash(salt, x))
- for i in range(len(test_key)-2):
- if test_key[i] == test_key[i+1] and test_key[i] == test_key[i+2]:
- char = test_key[i]
- break
- else:
- continue
- for y in range(x+1, x+1001):
- if y in previous_hashes:
- quintcheck = previous_hashes[y]
- else:
- quintcheck = extend_hash(make_hash(salt, y))
- previous_hashes[y] = quintcheck
- if char not in quintcheck:
- continue
- else:
- for j in range(len(quintcheck)-4):
- if quintcheck[j] == quintcheck[j+1] and quintcheck[j] == quintcheck[j+2] and quintcheck[j] == quintcheck[j+3] and quintcheck[j] == quintcheck[j+4] and quintcheck[j] == char:
- pad.append(x)
- print(x, test_key)
- print(y, quintcheck)
- print()
- break
Advertisement
Add Comment
Please, Sign In to add comment