import zipfile
import os
#输入路径zFile,密码字符串password,输出解压文件到当前py路径,返回解压密码
def extractFile(zFile, password):
try:
if password == None:
zFile.extractall()
else:
zFile.extractall(path = os.getcwd(), pwd = password.encode('utf-8'))#解压文件到path,即解压目录,pwd为密码
print("FoundPassword:", password)#成功解压输出密码
return True
except:
return False
def main():
#zip文件路径
zFile = zipfile.ZipFile('C:\\Users\\cony1\\Desktop\\test2.zip')
#假设密码为手机号,以199开头,现对密码进行遍历
for i in range(0,100000000):
n=len(str(i))
if n<=8:
# pass_list.append('199'+'0'*(8-n)+str(i))
s='199'+'0'*(8-n)+str(i)
print(s)
if extractFile(zFile,s):
break
#若使用字典
# passFile = open('D:/1/dictionary.txt')
# for line in passFile.readlines():
# password = line.strip('\n')
# if extractFile(zFile, password):
# break
print("---end---")
if __name__ == '__main__':
main()
假设密码为手机号,已知开头为199,现对密码进行遍历
参考链接: