aoc-2015/jour04/run.py

27 lines
656 B
Python
Raw Normal View History

2021-03-06 18:26:42 +00:00
import hashlib
2021-03-24 22:24:46 +00:00
def calculMd5(mot, nbZeros):
"""
Calcule la partie manquante de mot ayant un hash md5 commencant
par un nombre donné de 0.
2021-03-06 18:26:42 +00:00
2021-03-24 22:24:46 +00:00
:param mot string: le début du mot
:param nbZeros int: le nombre de zéro du hash md5
"""
i = 1
find = False
md = None
while not find:
md = hashlib.md5((mot + str(i)).encode("utf-8"))
if md.hexdigest()[0:nbZeros] == "0" * nbZeros:
find = True;
else:
i += 1
return i
2021-03-06 18:26:42 +00:00
2021-03-24 22:24:46 +00:00
myInput = "iwrupvqb"
print("Traitement de la partie 1…")
print(calculMd5(myInput, 5))
2021-03-06 18:26:42 +00:00
print("Traitement de la partie 2…")
2021-03-24 22:24:46 +00:00
print(calculMd5(myInput, 6))