編碼和解碼 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!