【发布时间】:2017-03-28 14:13:30
【问题描述】:
这是学校作业,不是为了个人利益
我正在创建一个脚本,该脚本在一个填充了密码的文件中搜索它的哈希等效项。该文件本身是纯文本密码,我正在使用循环转换为 md5,然后搜索并匹配我预先设置的“testmd5”的值。
我遇到的问题是,它一直返回“未找到”。散列值在文本文件中,所以我猜我没有正确地将纯文本转换为文件中的散列!
import hashlib
testmd5 = "a90f4589534f75e93dbccd20329ed946"
def makemd5(key_string):
new_keystring=key_string.encode('utf-8')
return (hashlib.md5( new_keystring ).hexdigest())
def findmd5(makemd5):
found = False
with open("passwords.txt", "rt") as in_file:
text = in_file.readline()
for text in ("passwords.txt"):
if makemd5(text) == testmd5:
print(text)
found = True
if found == False:
print("Not Found")
def main():
findmd5(makemd5)
main()
任何有关的帮助将不胜感激!
这是我刚学会的读取文件的方法。
with open("test.txt", "rt") as in_file:
while True:
text = in_file.readline()
if not text:
break
print(text)
【问题讨论】:
-
我认为你需要再看看如何读取文件。
-
检查问题。
-
不要将代码放入 cmets。使用新代码编辑您的问题。
-
for text in ("passwords.txt")应该做什么? -
我假设 line 会创建用于读取文件中“文本”的变量
标签: python function python-3.x hash