繁体   English   中英

搜索哈希密码文件Python

[英]Search Hashed Password File Python

这是学校的分配,不是为了个人收入

我正在创建一个脚本,搜索一个填充了密码的文件,它的哈希等价物。 文件本身是纯文本密码,我使用循环转换为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)

你实际上没有搜索文件,你正在搜索字符串"passwords.txt" 您还会错过函数调用readline的括号,我认为它应该是readlines()以便您可以迭代行列表:

import hashlib
testmd5 = "a90f4589534f75e93dbccd20329ed946"

def makemd5(key_string):
    new_keystring=key_string.encode("utf-8")
    return (hashlib.md5( new_keystring ).hexdigest())

def findmd5():
    found = False
    with open("passwords.txt", "rt") as in_file:
       full_text = in_file.readlines()
    for text in full_text:
        if makemd5(text) == testmd5:
            print(text)
            found = True
    if found == False:
        print("Not Found")

if __name__ == "__main__":
    findmd5()

似乎没有必要传递makemd5函数,所以我删除了它。

与引号一致,你曾使用单个'utf-8' ,但在其他地方使用双引号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM