超级简单的暴力枚举法-破解压缩包密码-python

文章目录

  • 前言
  • 代码需知


前言

超级简单的暴力枚举法-破解压缩包密码-python_第1张图片

准备工作:

导入库:

import itertools as its
import os
from zipfile import ZipFile

代码需知

passwd函数尝试给定的压缩包密码来解压:
path:文件路径
i:密码

def passwd(path,i):
    type_ = os.path.splitext(path)[-1][1:]
    if type_ == "zip":
        with ZipFile(path,'r') as zip:
            try:
                zip.extractall('./create_data/文件',pwd=str(i).encode('utf-8'))
                print(f"解压成功,密码是{i}")
                print("解压后文件位置:./create_data/文件")
                return 1
            except Exception as e:
                pass

创建密码:

def create_pwd(length):
    # words = '1234567890qwertyuiopalskdjfhgzmxncbv'  //根据words生成密码
    words='1234567890'
    for i in range(1,length+1): //生成密码长度为1~length
        base = its.product(words,repeat=i) //根据words生成密码,密钥长度和可重复字符数目为i
        for i in base: //把生成的密码发送出去
            yield ''.join(i)

主程序:

if __name__ == '__main__':
    path="./tp.zip"
    for p in create_pwd(4):
        print("输入密码为:",p)
        flag = passwd(path,p)
        if flag:
            break

你可能感兴趣的:(Python--数据收集,python,开发语言)