[Tutor] How do I save the output of the rotor module?

Mike Faire mikef at formostpkg.com
Thu Nov 6 12:52:36 EST 2003


Hi everyone!

I wrote a simple script to get acquainted with the rotor module.
Encrypting and decrypting was simple enough.
However, once I save the encrypted list to a file,
it will not decrypt correctly beyond the first newline.

Here is the code:

#!/usr/bin/env python

import rotor

contents = ["This is a line of text\n", "including newlines\n", "for 
rotor testing."]
print contents   # shows a list of three strings
encon = []
rt = rotor.newrotor('606')
for item in contents:
     encon.append(rt.encrypt(item))
print encon

# at this point, print encon shows a list of three strings, encrypted

fh = open('text.txt', 'w')
fh.writelines(encon)          # write to a file
fh.close()
fh = open('text.txt', 'r')
incoming = fh.readlines()     # read from a file
fh.close()
print incoming

# after writing the strings to disk and then reading them back in
# again, print incoming shows a list comprised of one large string

after = []
for item in incoming:
     after.append(rt.decrypt(item))
print after

# the one large string will only decrypt correctly as far as the
# first newline

Do I need to use pickle for that list?
If they are strings, why does it matter that
they happen to contain representations of binary data?

TIA

Mike






More information about the Tutor mailing list