gpt4 book ai didi

python - 简单的Python查询——MD5哈希

转载 作者:行者123 更新时间:2023-11-28 16:29:14 28 4
gpt4 key购买 nike

我正在尝试编写一个小的 python 脚本来散列一些单词。我正在使用 hashcat 来验证我的输出,但出了点问题,这应该是一个非常简单的过程。但我无法确定我做错了什么。只有我的输出的最后一个散列被正确散列。在示例文件中使用“123456”作为 5 行的测试时,我得到以下输出:

f447b20a7fcbf53a5d5be013ea0b15af

f447b20a7fcbf53a5d5be013ea0b15af

f447b20a7fcbf53a5d5be013ea0b15af

f447b20a7fcbf53a5d5be013ea0b15af

e10adc3949ba59abbe56e057f20f883e

谁能指出我方法的错误。将不胜感激。

import hashlib


my_file = open("sample.txt" , "r")

for line in my_file:
try:
hash_object = hashlib.md5(line)
print(hash_object.hexdigest())

except:
print "Error"

my_file.close()

最佳答案

前四行的哈希值不同,因为您在 MD5 哈希计算中包含了回车符。最后一行没有此回车符,因此返回不同的值。只需使用 strip() 删除回车符,您将获得所有五行的相同哈希值:

import hashlib


my_file = open("sample.txt" , "r")

for line in my_file:
try:
hash_object = hashlib.md5(line.strip())
print(hash_object.hexdigest())

except:
print "Error"

my_file.close()

这给出了输出:

e10adc3949ba59abbe56e057f20f883e
e10adc3949ba59abbe56e057f20f883e
e10adc3949ba59abbe56e057f20f883e
e10adc3949ba59abbe56e057f20f883e
e10adc3949ba59abbe56e057f20f883e

关于python - 简单的Python查询——MD5哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33740020/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com