我想将一些256个字母的字母编码成90个字母的字母,我怎么能用Python编写。纯python中是否有任何标准库或扩展模块。
import os
string256 = os.urandom(32)
alphabet = []
alphabet.append(chr(0x21))
alphabet.extend([chr(x) for x in range(0x23, 0x2b+1)])
alphabet.extend([chr(x) for x in range(0x2d, 0x3a+1)])
alphabet.extend([chr(x) for x in range(0x3c, 0x5b+1)])
alphabet.extend([chr(x) for x in range(0x5d, 0x7e+1)])
# alphabet has 90 letters
s = encode(string256, alphabet)
d = decode(string256, alphabet)
assert(d == string256)
如何在Python中进行此类编码?