[英]Search Hashed Password File Python
THIS IS A SCHOOL ASSIGNMENT, NOT FOR PERSONAL GAIN 这是学校的分配,不是为了个人收入
I am creating a script that searches through a file filled with passwords for it's hashed equivalent. 我正在创建一个脚本,搜索一个填充了密码的文件,它的哈希等价物。 The file itself is plain text passwords, I am using a loop to convert to md5, and then search for, and match a value which I have pre-set "testmd5".
文件本身是纯文本密码,我使用循环转换为md5,然后搜索,并匹配我预设“testmd5”的值。
The problem I'm having is, it keeps returning "Not Found". 我遇到的问题是,它一直返回“未找到”。 The hashed value is within the text file so I'm guessing I am not correctly converting the plain text to hash within the file!
散列值在文本文件中,所以我猜我没有正确地将纯文本转换为文件中的散列!
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()
Any help regarding the would be appreciated! 任何有关的帮助将不胜感激!
This is the method I just learned to read files. 这是我刚学会读取文件的方法。
with open("test.txt", "rt") as in_file:
while True:
text = in_file.readline()
if not text:
break
print(text)
You're not actually searching the file, you're searching the string "passwords.txt"
. 你实际上没有搜索文件,你正在搜索字符串
"passwords.txt"
。 You also miss the brackets from the function call to readline
, which I think should be readlines()
so that you can iterate the list of lines: 您还会错过函数调用
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()
It also seems unnecessary to pass the makemd5
function around, so I've removed that. 似乎没有必要传递
makemd5
函数,所以我删除了它。
Be consistent with quotes, you had used single for 'utf-8'
, but double quotes everywhere else. 与引号一致,你曾使用单个
'utf-8'
,但在其他地方使用双引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.