【发布时间】:2022-01-12 15:25:59
【问题描述】:
import hashlib
digest = ["sha1", "sha256", "md5"]
s = "5UA@/Mw^%He]SBaU".encode('utf-8')
h = "3281e6de7fa3c6fd6d6c8098347aeb06bd35b0f74b96f173c7b2d28135e14d45"
dictionary = open("dictionary.txt", "r")
for i in digest:
for line in dictionary:
testString = bytes(line, 'utf-8')
h2 = hashlib.digest[i](testString + s).hexdigest()
print(h2)
if h in h2:
print("the password is:", line)
我正在尝试找出一种方法来迭代 hashlib 的摘要。清单是否可行? (我知道它不起作用,因为我正在传递一个字符串)。
或者,进行这种迭代有哪些选择?
【问题讨论】:
-
将
hashlib.digest[i]替换为getattr(hashlib, i)。应该有效,但仍然不是最佳做法。 -
在事先不知道函数名称的情况下从模块中迭代函数:stackoverflow.com/questions/21885814/…
-
@mkrieger1 感谢方便知道,虽然我知道摘要所以只想有选择地遍历它们
标签: python python-3.x loops iteration