编码和解码 ASCII85

Adobe 创建了自己的编码,称为 ASCII85 ,类似于 Base85,但有其不同之处。此编码在 Adobe PDF 文件中经常使用。这些函数在 Python 3.4 版中发布。否则,base64.a85encode()base64.a85encode() 的功能与前一个类似:

import base64
# Creating a string
s = "Hello World!"
# Encoding the string into bytes
b = s.encode("UTF-8")
# ASCII85 Encode the bytes
e = base64.a85encode(b)
# Decoding the ASCII85 bytes to string
s1 = e.decode("UTF-8")
# Printing ASCII85 encoded string
print("ASCII85 Encoded:", s1)
# Encoding the ASCII85 encoded string into bytes
b1 = s1.encode("UTF-8")
# Decoding the ASCII85 bytes
d = base64.a85decode(b1)
# Decoding the bytes to string
s2 = d.decode("UTF-8")
print(s2)

这输出如下:

ASCII85 Encoded: 87cURD]i,"Ebo80
Hello World!