所以我有一个简单的程序,它将常用密码列表中的所有值哈希,然后将哈希值与给定的哈希值进行比较。然后破解密码。
然而它似乎不起作用,因为passwd_found
仍然是假的,我相信它的IF语句不起作用。任何帮助表示赞赏。
dic = []
passwd_hash = '4297f44b13955235245b2497399d7a93'
passwd_found = False
for k in dic:
md5hash = hashlib.md5(k.encode('utf-8'))
print(md5hash.hexdigest())
if passwd_hash in md5hash:
passwd_found = True
else:
passwd_found = False
答案 0 :(得分:3)
我相信你的缩进已经关闭,你需要在比较中使用.hexdigest()
,否则你会收到错误:
TypeError:类型' _hashlib.HASH'的参数是不可迭代的
import hashlib
dic = ['123','1234','12345','123456','1234567','12345678','password', 'qwerty','abc','abcd','abc123','111111','monkey','arsenal','letmein','trustno1','dragon','baseball','superman','iloveyou','starwars','montypython','cheese','123123','football','batman']
passwd_hash = '4297f44b13955235245b2497399d7a93'
passwd_found = False
for k in dic:
md5hash = hashlib.md5(k.encode('utf-8'))
t_hash = md5hash.hexdigest()
print(t_hash)
if passwd_hash in t_hash:
passwd_found = True
else:
passwd_found = False
if passwd_found:
print(k) # 123123 matches