import itertools as its
import zipfile
#from unrar import rarfile
import threading
# 判断线程是否需要终止
flag = True
#生成密码本
def pwd():
words = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
r = its.product(words, repeat=3) # repeat要生成多少位的字典,这生成了一个三位的密码本
with open("pwd.txt", "a")as f:
for i in r:
f.write("".join(i))
f.write("\r")
#判断当前密码能否解压
def extract(password, file):
try:
password = str(password)
file.extractall(path=r'C:\\Users\\Desktop\\', members=file.namelist(),pwd=password.encode('utf-8'))#zip解压缩
#file.extractall(pwd=password)#rar解压缩
print("压缩包的密码是:%s"%password)
global flag
flag = False
except Exception:
print('密码错误,继续尝试....')
pass #密码错误则跳过
#读取密码本内容,进行尝试
def main():
pwd() #生成密码本
file = zipfile.ZipFile(r"C:\\Users\\Desktop\\aim.zip")#压缩文件
#file = rarfile.RarFile("pwd.rar")
passwords = open('pwd.txt') #密码字典
for line in passwords.readlines():#逐行读取密码
if flag is True:
password = line.strip('\n') #去掉回车
print(line,end="") #逐个查看当前密码
t = threading.Thread(target=extract, args=(password, file))
t.start() #开始
t.join() #Parent父线程会等待child子线程运行完再继续运行
if __name__ == '__main__':
main()
python 破解压缩文件zip的解压密码
最新推荐文章于 2025-02-25 13:36:38 发布