私は2つのpythonスクリプトを持っています.1つはbase64にファイルをエンコードします(これは正常に動作します)。Pythonベース64のデコード - 改行を開始するのではなく nをプリントします。
import base64
read_file = input('Name of file to read: ')
write_file = input('Name of file to write to: ')
image = open("%s"% read_file,'rb')
image_read = image.read()
image_64_encode = base64.encodestring(image_read)
raw_file = open("rawfile.txt","w")
raw_file.write("%s"% image_64_encode) #Write the base64 to a seperate text file
raw_file.close()
image_64_decode = base64.decodestring(image_64_encode)
image_result = open('%s'% write_file,'wb')
image_result.write(image_64_decode)
image_result.close()
image.close()
上記のスクリプトは正常に実行され、新しいファイル(デコード済み)とエンコードされた文字列として表示される別のrawfile.txtを正常に書き込みます。したがって、この半分のプロセスは問題ありません。
私が生ファイルの内容を印刷することができる、rawfile.txt復号する第Pythonスクリプトを持っているのではなく、所望の
より生ファイルは、新しい行を有し、パイソンプリントsomerawfiletext\nmorerawfiletext
somerawfiletext
morerawfiletext
私はbase64のパディングエラーが発生するため、解読できません。
二Pythonスクリプトは:
import base64
rawfile = open("rawfile.txt",'r')
for line in rawfile:
print(line.rstrip())
decoded = base64.decodestring(rawfile)
print(decoded)
ありがとうございました。帰ってきたら、これを試してみます。 :) –