import py7zr
#from zipfile import ZipFile
import os
import itertools as its
from multiprocessing import Pool
def passwd(archive_path,output_path,pwd):
# def passwd(archive_path,pwd):
type_ = os.path.splitext(archive_path)[-1][1:]
if type_ == '7z':
try:
with py7zr.SevenZipFile(archive_path, mode='r',password=str(pwd)) as z:
#password=str(pwd).encode('utf-8')
print(f'正在尝试密码: {pwd}')
# file_list = z.namelist()
# for filename in file_list:
# print(filename)
zc = z.extractall(output_path)
print(f'解压成功,密码是:{pwd}')
return True
except Exception as e:
print(f'尝试密码 {pwd} 失败,错误信息: {e}')
def create_pwd(length):
import itertools as its
words='1234567890a'
for i in range(3,length+1):
base = its.product(words,repeat=i)
for i in base:
yield ''.join(i)
if __name__ == "__main__":
# passwd('./base_data/aa.zip')
for p in create_pwd(20):
# flag = passwd(r'testpassword.7z',p)
flag = passwd(r'testpassword.7z',r'create_data',p)
if flag:
break
#flag = passwd(r'testpassword.7z',r'create_data',123)
为什么只能运到97就无法继续破解了