【发布时间】:2012-08-23 21:57:15
【问题描述】:
我正在尝试构建一个 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))。 hashlib Python 3 文档指出传递给update() 的字符串应该是二进制表示。文档以m.update(b"Nobody inspects") 为例。在我的代码中,我不能简单地将b 附加到变量word 前面。所以我尝试使用binascii 库,但该库也在文档中注明:
注意
编码和解码函数不接受 Unicode 字符串。仅有的 可以处理bytestring和bytearray对象。
有人可以帮我解决这个问题吗?它对我越来越好。
【问题讨论】:
-
注意:
fileinput.input()在您的情况下可能太慢了。您可以使用md5(word).digest()而不使用明确的update()。
标签: binary python-3.x ascii md5