相同输入的不同md5

uurv41yg  于 2021-09-08  发布在  Java
关注(0)|答案(2)|浏览(364)

这个问题在这里已经有了答案

python 3相同的文本但不同的md5哈希(1个答案)
昨天关门了。
我做了一个散列程序。

import hashlib as h
h=h.md5()
while 1:
        h.update(input("type here:").encode("utf-8"))
        print(h.hexdigest())

当我试图计算散列时,我得到了以下错误。所有输出都比其他输出更加不同。如何解决这个问题?

编辑:现在可以了

import hashlib as h

while 1:
        h_=h.md5()
        h_.update(input("type here:").encode("utf-8"))
        print(h_.hexdigest())
a7qyws3x

a7qyws3x1#

不要在while循环中使用相同的md5对象。您可以这样做:

from hashlib import md5
while 1:
    hash = md5(input("type here:").rstrip().encode("utf-8"))
    print(hash.hexdigest())
qoefvg9y

qoefvg9y2#

根据文件:
重复调用相当于连接所有参数的单个调用:m.update(a);m、 update(b)相当于m.update(a+b)。
所以每次你打电话 update() 您正在附加到正在散列的文本。尝试为每个输入创建一个新对象。

相关问题