我正在尝试构建一个MD5破解器进行练习。在进一步之前,这是我的代码:
def offline_wordlist_attack(list_path):
with fileinput.input(files=(list_path)) as wordlist:
for word in wordlist:
md5_hash_object = hashlib.md5() # constructing an md5 hash object
md5_hash_object.update(binascii.a2b_uu(word))
word_digest = md5_hash_object.digest() # performing the md5 digestion of the word
print(word_digest) # Debug
我的问题出在md5_hash_object.update(binascii.a2b_uu(word))
上。Python 3 的hashlib文档指定传递给update()
的字符串应为二进制表示。文档使用m.update(b"Nobody inspects")
作为示例。在我的代码中,我不能只是在变量word
前面添加b
。所以我尝试使用binascii库,但该库的文档也有一个注释:
注意
编码和解码函数不接受Unicode字符串。只能处理字节串和字节数组。
有人能帮我解决这个问题吗?这让我很困扰。
fileinput.input()
可能会过慢。您可以使用md5(word).digest()
而无需显式地调用update()
。 - jfs