[py] Simplify 2015_04
This commit is contained in:
parent
18b58fd936
commit
55a9a39d9d
1 changed files with 6 additions and 18 deletions
|
|
@ -1,29 +1,17 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
# PART 1
|
|
||||||
|
|
||||||
|
def brute_force(seed, start):
|
||||||
def leading_zeroes(amount, start):
|
|
||||||
n = 1
|
n = 1
|
||||||
what = "0" * amount
|
|
||||||
while True:
|
while True:
|
||||||
text = (start + str(n)).encode("utf-8")
|
text = f"{seed}{n}".encode("utf-8")
|
||||||
h = hashlib.md5(text).hexdigest()
|
h = hashlib.md5(text).hexdigest()
|
||||||
if h[:amount] == what:
|
if h.startswith(start):
|
||||||
return n
|
return n
|
||||||
|
|
||||||
# if n % 100000 == 0:
|
|
||||||
# print(f"{n:9} {text} {h}")
|
|
||||||
|
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
|
|
||||||
# PART 2
|
|
||||||
|
|
||||||
|
|
||||||
def solve(inputstr):
|
def solve(inputstr):
|
||||||
hashstart = inputstr.strip()
|
seed = inputstr.strip()
|
||||||
n = leading_zeroes(5, hashstart)
|
print(f"Part 1: {brute_force(seed, '00000')}")
|
||||||
print(f"Part 1: {n}")
|
print(f"Part 2: {brute_force(seed, '000000')}")
|
||||||
n_2 = leading_zeroes(6, hashstart)
|
|
||||||
print(f"Part 2: {n_2}")
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue