【问题标题】:MD5: Why am I getting different results for the same string?MD5:为什么相同的字符串会得到不同的结果?
【发布时间】:2023-02-10 04:38:59
【问题描述】:

我希望以下代码在每种情况下都返回相同的结果,因为字符串值相同但每次都得到不同的结果。我能做些什么(如果有的话)来解决这个问题?

import hashlib

a = 'some text'
b = 'some text'
hashA = hashlib.md5(b'{a}').hexdigest()[:8]
hashB = hashlib.md5(b'{b}').hexdigest()[:8]
hashT = hashlib.md5(b'some text').hexdigest()[:8]

print(hashT) # 552e21cd
print(hashA) # e78fce13
print(hashB) # 09b94c63
print (a==b) # True

【问题讨论】:

    标签: python md5 hashlib


    【解决方案1】:

    因为格式化字符串的前缀是 f 。 a、b 和'some text' 是不同的。

    【讨论】:

    • 我认为那是不对的。
    猜你喜欢
    • 1970-01-01
    • 2015-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多