base全家桶的安装使用方法

base编码是Binary-to-text encoding的一种实现方法,它可以把二进制数据(含不可打印的字符)编码成可打印字符序列。

本文会不定时收录“base全家桶”:base64、base32、base16、base58、base91、base92等。

------------------

0x01 base64

安装:python2.7自带

alphabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

padding:

=

使用:

import base64
c=base64.b64encode('pcat.cc')
m=base64.b64decode(c)
print c,m

0x02 base32

安装:python2.7自带

alphabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZ234567

padding:

=

使用:

import base64
c=base64.b32encode('pcat.cc')
m=base64.b32decode(c)
print c,m

0x03 base16

安装:python2.7自带

alphabet:

0123456789ABCDEF

使用:

import base64
c=base64.b16encode('pcat.cc')
m=base64.b16decode(c)
print c,m

注意:

当b16decode的参数含有小写字母时,需要传入第二个参数True

base64.b16decode('706361742e6363',True)

或者使用python2.7的.decode('hex')则无须考虑大小写。

'706361742e6363'.decode('hex')

0x04 base58

github项目:https://github.com/keis/base58

安装:

pip install base58

alphabet:

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

使用:

import base58
c=base58.b58encode('pcat.cc')
m=base58.b58decode(c)
print c,m

0x05 base91

网址:http://base91.sourceforge.net/

github项目:https://github.com/aberaud/base91-python

安装:

pip install base91

alphabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~"

使用:

import base91
c=base91.encode('pcat.cc')
m=base91.decode(c)
print c,m

0x06 base92

github项目:https://github.com/thenoviceoof/base92

安装:

pip install base92

alphabet:

!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}

a special denotation (an empty string):

~

使用:

import base92
c=base92.encode('pcat.cc')
m=base92.decode(c)
print c,m

注意:

encode,b92encode,base92_encode是一样的,
decode,b92decode,base92_decode是一样的。

猜你喜欢

转载自www.cnblogs.com/pcat/p/11625834.html
今日推荐