簡體   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