python对压缩文件zip密码尝试破解

RS 技术•随笔评论488字数 590阅读1分58秒阅读模式
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

 
RS
  • 本文由 RS 发表于 2022年11月30日 09:28:10
助你整理杂乱无章的文件 技术•随笔

助你整理杂乱无章的文件

今天的小程序,可以一键完成文件整理,一起来看看吧! 按照文件格式整理 具体来说就是不同的文件后缀名称放置到不同的文件夹当中 今天我们只需要使用 os 和 shutil 两个库就足够了。os 是 Pyt...
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定