I have this script that opens a file and encrypts it to base64 and then saves the encryption in file output.txt
, but there is a problem, it collects the words in a file in one line, I want to print each word in a file and save each word on a new line and not in one line.
For example:
Where is my problem in my code?
import base64
with open("out.txt","r") as file:
count = 0
while True:
count += 1
# Get next line from file
line = file.read()
# if line is empty
# end of file is reached
if not line:
break
message_bytes = line.encode('ascii')
base64_bytes = base64.b64encode(message_bytes)
base64_message = base64_bytes.decode('ascii')
print(base64_message.format(count, line.strip()), file=open("output.txt", "a"))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…