J'ai une liste d'identifiants que je veux ajouter avec la chaîne 'texte'. Je veux vérifier si l'un des ids (après avoir été ajouté avec la chaîne 'text') est égal à la chaîne 'text_compare'.SHA512 Python a produit un résultat différent pour la même chaîne
Ce qui est étrange, c'est que la chaîne avant que le hachage ait lieu est égale, mais après le hachage a lieu, le hachage ne semble pas avoir produit les mêmes résultats. Voici mon code. Vous pouvez le tester sur la ligne de commande Python.
import hashlib
h = hashlib.sha512()
text = 'beruk makye'
text_compare = '3beruk makye'
text_compare_hash = h.update(text_compare)
text_compare_hash = h.hexdigest()
ids = [1,2,3]
texts = []
bool_text = []
bool_text_hash = []
for id in ids:
texts.append(str(id) + text)
for t in texts:
if t == text_compare:
bool_text.append(True)
else:
bool_text.append(False)
for t in texts:
h.update(t)
t_hash = str(h.hexdigest())
if t_hash == text_compare_hash:
bool_text_hash.append(True)
else:
bool_text_hash.append(False)
print ids
# [1, 2, 3]
print texts
# ['1beruk makye', '2beruk makye', '3beruk makye']
print bool_text
# [False, False, True]
print bool_text_hash
# [False, False, False]
grâce, J'ai eu le même problème en utilisant MD5, j'ai fait la même erreur – clarenswd