使用列表而不是字典破解zip文件密码

2024-10-01 05:05:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让它工作,但我被困在循环部分。我不知道如何设置正确的循环和选择正确的密码!任何帮助都将不胜感激

import zipfile

def openZip(file, password=''):
    zip = zipfile.ZipFile(file)
    try:
        if password == '':
            zip.extractall()
        else:
            zip.extractall(pwd=bytes(password, 'utf-8'))
        return True
    except Exception as e:
        return False

passwords = ['qwerty', 'password', 'iloveyou', '123123', '111111', '12345', '12345678' , '1234567', '123456789', '123456']

file = input('What is the filename of the zip file? ')

for password in passwords:
    result = openZip(file, password)
    if result:
        print('the correct password is',password)
    else:
        print('incorrect:',password)

Tags: the密码returnifispasswordresultzip