'text'문자열을 추가하려는 ID 목록이 있습니다. 'text'문자열이 추가 된 후 ID가 'text_compare'문자열과 같은지 확인하고 싶습니다.SHA512 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]
덕분에, MD5를 사용하는 동안 동일한 문제가 발생했습니다. 동일한 실수를했습니다. – clarenswd