最近想要弄一个base全家桶的解密大全,在网站找了很多资料
主要是依靠大神的博客
https://www.cnblogs.com/pcat/p/11625834.html
但是这篇博客有一部分库是基于python2的,在python3中并不适用,因此有了这篇文章。
文章将按照base编码的顺序逐一介绍。
1.base16
python自带
import base64
c = base64.b16decode(cipher_text) #加密
m = base64.b16encode(plain_text) #解密
########例子
m = base64.b16encode(b'123')
c = base64.b16decode(m)
#这里的默认参数是字节串,为了方便使用可以转码,这样就可以直接使用字符串输入
base64.b16encode(plain_text.encode('utf-8'))
#通过这个即可将字符串转换字节串
#同理默认输出也是字节串,我们可以通过.decode() 方法将其转换成字符串
#后文中的所有内容同理,在此不做过多解释
#所以如果想要全程使用字符串的话可以
c = base64.b16decode(cipher_text).decode()
m = base64.b16encode(plain_text.encode('utf-8')).decode()
2.base32
python自带
import base64
m = base64.b32decode(cipher_text).decode() #解密
c = base64.b32encode(plain_text.encode('utf-8')).decode() #加密
3.base36
需要安装
pip install base36
github项目:https://github.com/tonyseek/python-base36
import base36
c = base36.dumps(int(cipher_text)) #解密
m = base36.loads(plain_text) #加密
4.base58
python自带
import base64
c = base58.b58decode(cipher_text).decode() #解密
m = base58.b58encode(plain_text.encode('utf-8')).decode() #加密
5.base64
python自带
import base64
c = base64.b64decode(cipher_text).decode() #解密
m = base64.b64encode(plain_text.encode('utf-8')).decode() #加密
6.base85
python自带
import base85
###ASCII85型(ctf常用)
c = base64.a85decode(cipher_text).decode() #解密
m = base64.a85encode(plain_text.encode('utf-8')).decode()#加密
###RFC1924型(没什么卵用,就是花里胡哨)
c = base64.b85decode(cipher_text).decode() #解密
m = base64.b85encode(plain_text.encode('utf-8')).decode()#加密
7.base91
需要安装
pip install base91
github项目:https://github.com/aberaud/base91-python
import base91
c = base91.decode(cipher_text).decode() #解密
m = base91.encode(plain_text.encode('utf-8')) #加密
8.base92
原来的base92库不适用于py3
因此需要安装这个库
github项目:https://github.com/Gu-f/py3base92
import py3base92
c = py3base92.decode(cipher_text) #解密
m = py3base92.encode(plain_text) #加密
9.base128
需要安装
github项目:https://github.com/rpuntaie/base128
此外还需要安装bitarray
在python3中如果直接pip安装bitarray会失败,因此我们需要手动安装这个项目。
window下的安装方法如下:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
在这个python库中找到bitarray(cp34表示适用的python版本 cp34即表示适用python3.4)(读者可根据需求自行下载对应版本)
(轮子的安装在此不多赘述)
import base128
b128 = base128.base128(chars = None, chunksize = 7)
c = b''.join(b128.decode(cipher_text)).decode() #解密
m = list(b128.encode(plain_text.encode(encoding="utf-8"))) #加密