python脚本-自动检测Base16、32、64、85系列编码、多层解码(新增base91解码)

自动检测Base16、32、64、85系列编码,多层解码:

import base64
import re
import base91

def baseDec(text,type):
    if type == 1:
        return base64.b16decode(text)
    elif type == 2:
        return base64.b32decode(text)
    elif type == 3:
        return base64.b64decode(text)
    elif type == 4:
        return base64.b85decode(text)
    elif type == 5:
        return base91.decode(text.decode())
    else:
        pass

def detect(text):
    try:
        if re.match("^[0-9A-F=]+$",text.decode()) is not None:
            return 1
    except:
        pass
    
    try:
        if re.match("^[A-Z2-7=]+$",text.decode()) is not None:
            return 2
    except:
        pass

    try:
        if re.match("^[A-Za-z0-9+/=]+$",text.decode()) is not None:
            return 3
    except:
        pass

    try:
        if re.match("^[A-Za-z0-9$%()*+,-./:;?@[\]^_`{|}~]+$",text.decode()) is not None:
            return 4
    except:
        pass

    try:
        if re.match("^[^-\']+$",text.decode()) is not None:
            return 5
    except:
        pass
    
    return 5

def autoDec(text):
    floor = 0
    while True:
        try:
            code = detect(text)
            text = baseDec(text,code)
            floor += 1
            print("第{0}层:\n".format(floor),text)
            if not text:break
        except:
            break

if __name__ == "__main__":
    # with open("Autopy/crypto/doc/form",'rb') as f:
    #     content = f.read()
    content = "@iH<,{*;oUp/im\"QPl`yR*ie}NK;.D!Xu)b:J[Rj+6KKM7P@iH<,{*;oUp/im\"QPl`yR".encode()
    autoDec(content)


  • 注意:报错binascii.Error: Incorrect padding,要在字符串后补=
  • base91通过命令 pip install base91 安装
  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值