如何在 base64 中编码二进制文件并且每行有 72 个字符?
这是我尝试过的,但它不起作用,我不知道我是否正确格式化输出以便对其进行解码。
import base64
fin = open("/Users/kyle/one_time_pad/encrypt/cipher_text.txt", "rb")
binary_data = fin.read()
fin.close()
b64_data = base64.b64encode(binary_data)
file = b64_data
def split_len(seq, length):
return [seq[i:i+length] for i in range(0, len(seq), length)]
def organize():
for a in split_len(file, 72):
print a
open("/Users/kyle/Desktop/test.txt", "w").write(organize())
它给出了错误TypeError: expected a character buffer object