【问题标题】:What is the mistake in this script in python这个脚本在python中的错误是什么
【发布时间】:2019-11-24 07:45:40
【问题描述】:

如何修复此脚本未显示任何数据:

这是我的代码:

from hashlib import md5
counter = 1
pass_in = input('Enter the md5 hash: ')
pwfile = input('Please enter the passowrd file: ')

try:
    pwfile = open(pwfile,'r')
except:
    print('\nfile not found')
    quit()
for password in pwfile:
    filemd5 = md5()
    filemd5.update(password.strip().encode('utf-8'))
    filemd5.hexdigest()
    print('Trying password number')
    counter += 1

    if pass_in == filemd5:
        print('\n Match Found. \nPassword is: %s' + password)
        break
else:
    print('\n password not found!')

我忘记了什么?

有什么问题?

【问题讨论】:

    标签: python python-3.x md5 hashlib cracking


    【解决方案1】:

    filemd5.hexdigest() 不会将哈希对象转换为字符串,而是返回一个字符串。将该行更改为filemd5 = filemd5.hexdigest()

    同样在print('\n Match Found. \nPassword is: %s' + password) 中将+ 更改为%

    【讨论】:

    • 仍然得到相同的输出
    • @HamzaMirchi 这里是它的工作演示:repl.it/repls/DefinitiveGraciousInstance。如果它对您不起作用,则可能意味着您没有输入与密码文件中的密码对应的 md5 哈希。
    • 密码文件在哪里?
    【解决方案2】:

    更新:误读了您的问题。亚历克斯的回答是正确的,这有效(更新以显示没有文件的工作代码):

    from hashlib import md5
    counter = 1
    pass_in = input('Enter the md5 hash: ')  # use "5d41402abc4b2a76b9719d911017c592"
    
    for password in ['hello',]:
        filemd5 = md5()
        filemd5.update(password.strip().encode('utf-8'))
        filemd5 = filemd5.hexdigest()  # THIS LINE IS YOUR PROBLEM
        print('Trying password number')
        counter += 1
    
        if pass_in == filemd5:
            print('\n Match Found. \nPassword is: %s' + password)
            break
    else:
        print('\n password not found!')
    

    【讨论】:

    • 是什么意思?如何修复
    • 更新了我的答案,但我重新阅读了您的代码,我猜您希望用户知道密码的 md5 哈希?这很奇怪……如果密码未散列存储,并且用户正在寻找密码,为什么还要为所有散列而烦恼?它并没有真正提供任何安全性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 2016-02-27
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多