图中的题目需要怎样做才能实现要求

img

主要使用with open写法将密码字节保存到password.txt中,然后遍历获取并判断即可。

import hashlib 
a='1234567890'.encode('utf-8')
b='666666'.encode('utf-8')
c='root'.encode('utf-8')
d='admin'.encode('utf-8')
with open('password.txt','wb') as f:
    f.write(a+b'\n'+b+b'\n'+c+b'\n'+d)
def crack():
    with open('password.txt','rb') as f:
        ps=f.read().split(b'\n')
        for i in ps:
            #print(hashlib.md5(i).hexdigest())
            if hashlib.md5(i).hexdigest()=='21232f297a57a5a743894a0e4a801fc3':
                print("password is %s"%i)
            
crack()

如有帮助,请点击我回答的右上方采纳按钮给予采纳~~

可以用with open函数,给你一个链接可以参考
我用#CSDN#这个app发现了有技术含量的博客,小伙伴们求同去《python_open函数》, 一起来围观吧