基于python的Base全家桶解码

发布时间 2023-04-24 18:18:32作者: 北京测试菜鸟

https://www.cnblogs.com/0yst3r-2046/p/11962942.html
 

函数介绍

  1. base64.b16encode  # 对字符串进行base16编码
  2. base64.b16decode  # 对字符串进行base16解码
  3. base64.b32encode  # 对字符串进行base32编码
  4. base64.b32decode  # 对字符串进行base32解码
  5. base58.b58encode  # 对字符串进行base58解码
  6. base58.b58decode  # 对字符串进行base58解码
  7. base64.b64encode  # 对字符串进行base64解码
  8. base64.b64decode  # 对字符串进行base64解码
  9. base64.a85encode  # 对字符串进行base85编码
  10. base64.a85decode  # 对字符串进行base85解码
  11. base91.encode    # 对字符串进行base91编码
  12. base91.decode    # 对字符串进行base91解码
  13. py3base92.encode  # 对字符串进行base92编码
  14. py3base92.decode  # 对字符串进行base92解码
  15. b128.encode     # 对字符串进行base128编码
  16. b128.decode     # 对字符串进行base128解码

 

 

1、base16

import base64

data = 'test{123456}'
sec = str.encode(data, 'utf-8')
c = base64.b16encode(sec)
print(c)  # 输出base16编码后的结果
m = base64.b16decode(c)
print(m)  # 输出base16解码后的结果

  

2、base32

import base64

data = 'test{123456}'.encode('utf-8')
sec = base64.b32encode(data)
print(sec)  # 输出base32编码后的结果
flag = base64.b32decode(sec)
print(flag)  # 输出base32解码后的结果

  

3、base36

import base36

# pip install base36
data = 'test123456'
m = base36.loads(data)  # 编码
c = base36.dumps(int(m))  # 解码
print(m)  # 输出编码后的结果
print(c)  # 输出解码后的结果

  

4、base58

import base58

# pip install base58
data = 'test{123456}'
m = base58.b58encode(data.encode('utf-8')).decode()  # base58编码
c = base58.b58decode(m).decode()  # base58解码
print(m)  # 输出编码后的结果
print(c)  # 输出解码后的结果

  

5、base64

import base64

data = 'test{123456}'
m = base64.b64encode(data.encode('utf-8')).decode()  # 编码
c = base64.b64decode(m).decode()  # 解码
print(m)  # 输出编码后的结果
print(c)  # 输出解码后的结果

  

6、base85

import base64

data = 'test{123456}'
m = base64.a85encode(data.encode('utf-8')).decode()  # 编码
c = base64.a85decode(m).decode()  # 解码
print(m)  # 输出编码后的结果
print(c)  # 输出解码后的结果

  

7、base91

import base91

# pip install base91
data = 'test{123456}'
m = base91.encode(data.encode('utf-8'))  # 编码
c = base91.decode(m).decode()  # 解码
print(m)  # 输出编码后的结果
print(c)  # 输出解码后的结果

  

8、base92

import py3base92

data = 'test{123456}'
sec = str.encode(data, 'utf-8')
m = py3base92.encode(sec)  # 编码
print(m)  # 输出编码后的结果
c = py3base92.decode('F#S<YRW^.DFd=<\\')  # 解码
print(c)  # 输出解码后的结果


旧的base92库已经不支持了,需要用py3base92库,这个库也不是python的内置库,需要把库下载下来手动安装。

https://github.com/Gu-f/py3base92/releases/tag/1.0.3-1
Windows下载下来后解压,直接双击install.bat即可安装成功。
Linux直接运行命令:python3 setup.py install

   

 

 

9、base128

import base128

# pip install base128 
data = 'test{123456}'
b128 = base128.base128(chars=None, chunksize=7)
m = list(b128.encode(data.encode(encoding="utf-8")))  # 编码
c = b''.join(b128.decode(m)).decode()  # 解码
print(m)  # 输出编码后的结果
print(c)  # 输出解码后的结果