如何将某些字符字母编码为另一个字符?

时间:2015-05-17 08:14:17

标签: python

我想将一些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中进行此类编码?

0 个答案:

没有答案