import os.path
from zipfile import ZipFile
import os
#解压
def passwd(path,pwd):
type_=os.path.splitext(path)[-1][1:] #获取扩展名类型
if type_ == 'zip':
with ZipFile(path,'r') as zip:
print(f'正在尝试密码:{pwd}')
try:
zip.extractall('./data',pwd=str(pwd).encode('utf-8'))
print(f'解压成功,密码是:{pwd}')
return True #如果解压成功,近回True
except Exception as e:
pass
#生成密码
def create_pwd(length): #length密码长度
import itertools as its
words='0123456789asd' #密码包含的字符,可以自行添加更多的字符
for i in range(1,length):
base=its.product(words,repeat=i)
for i in base:
yield ''.join(i)
if __name__=="__main__":
# passwd('aa.zip')
for p in create_pwd(5):
flag=passwd('aa.zip',p)
if flag: #如果解压成功,退出程序
break
评论