Python hashlib没有为md5生成正确的哈希

时间:2015-08-13 22:48:55

标签: python hash md5 hashlib

我正在研究一个小的python程序,它本质上是使用word文件强制md5哈希。程序将获取您的哈希值,然后您可以选择要用作单词列表的文件。然后它将在文件中逐行进行并生成md5哈希版本以检查您输入的版本。如果它们匹配,那么它将告诉你产生该哈希的单词。问题是,当程序将行转换为哈希值时,它不会产生正确的可识别md5哈希值。例如,它说测试的md5哈希是d8e8fca2dc0f896fd7cb4cb0031ba249。我已经尝试了多种编码文本和诸如此类的方法,但找不到正确的答案。我做错了什么?

import hashlib

mainhash = raw_input("What hash would you like to try and break?")
filename = raw_input("What file would you like to use?")
times = 0


if filename == "":
    print "A list file is required."
    exit()

f = open(filename)
for line in iter(f):
    times = times + 1
    word = line
    line = hashlib.md5(line.encode("utf")).hexdigest()
    print line
    if line == mainhash:
        print "Matching Hash found. Word is:"
        print word
        print times
        exit()

f.close()
print "Sorry no match was found. Please try a different word file or make sure the hash is md5."
print times

0 个答案:

没有答案
相关问题