Transformation en fonction

This commit is contained in:
rick 2021-03-24 23:24:46 +01:00
parent 448ca0d0fe
commit 90f99960fe
Signed by: Rick
GPG key ID: 2B593F087240EE99

View file

@ -1,29 +1,26 @@
import hashlib
myInput = "iwrupvqb"
def calculMd5(mot, nbZeros):
"""
Calcule la partie manquante de mot ayant un hash md5 commencant
par un nombre donné de 0.
: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
myInput = "iwrupvqb"
print("Traitement de la partie 1…")
while not find:
md = hashlib.md5((myInput + str(i)).encode("utf-8"))
if md.hexdigest()[0:5] == "00000":
find = True;
else:
i += 1
print(i)
print(calculMd5(myInput, 5))
print("Traitement de la partie 2…")
find = False
while not find:
md = hashlib.md5((myInput + str(i)).encode("utf-8"))
if md.hexdigest()[0:6] == "000000":
find = True;
else:
i += 1
print(i)
print(calculMd5(myInput, 6))