我试图使它起作用,但是我陷入了循环部分。我不知道如何设置适当的循环并选择正确的密码!任何帮助将不胜感激。
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)
答案 0 :(得分:1)
for password in passwords:
result = openZip(file, password)
if result:
print('the correct password is',password)
else:
print('incorrect:',password)
将根据需要打印密码。