python 解压密码zip

import zipfile
import itertools
 
filename = "297.zip"
# 创建一个解压的函数,入参为文件名和密码
# 并使用try-except,避免报错中断程序。
def uncompress(file_name, pass_word):
    try:
        with zipfile.ZipFile(file_name) as z_file:
            z_file.extractall("./", pwd=pass_word.encode("utf-8"))
        return True
    except:
        return False
 
# chars是密码可能的字符集
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
aa=0
for i in range(4,12):
    for c in itertools.permutations(chars, i):
        password = ''.join(c)
        print(password)
        result = uncompress(filename, password)
        if not result:
            print('解压失败。', password)
        else:
            print('解压成功。', password)
            aa=1
            break
    if aa==1:
        break

http://www.sy72.com/download/D_cn.html

posted @ 2023-04-12 06:03  myrj  阅读(77)  评论(0编辑  收藏  举报