import zipfile
import itertools
filename = '解压文件.zip'
def uncompress(filename, password):
try:
with zipfile.ZipFile(filename) as zfile:
zfile.extractall("./", pwd=password.encode('utf-8'))
return True
except:
return False
flog = 0
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
le = len(chars) + 1
ch = [i for i in range(0, le)]
for i in ch:
for c in itertools.permutations(chars, i):
password = "".join(c)
result = uncompress(filename, password)
if not result:
print("解压失败", password)
else:
print('解压成功', password)
flog = 1
if flog == 1:
break
- 注意解压文件与python脚本的相对路径位置
- 注意可以对密码的可能字符是未知,更具实际情况来修改脚本,中密码的可能字符