I have recently written a program that reads information from a CSV file and puts it into lists. An encryption sub procedure converts the characters to ASCII, adds 2 then converts them back to characters.
import csv
ifile = open("messages.csv","rb")
reader= csv.reader(ifile)
plain_text= []
plain_ascii= []
encrypted_ascii= []
encrypted_text= []
latitude= []
longitude= []
for row in reader:
latitude.append(row[0])
longitude.append(row[1])
plain_text.append(row[2])
encrypted_text=[''.join(chr(ord(ch)+2) for ch in string) for string in
plain_text]
print plain_text
print encrypted_text
count=0
print ""
while True:
print ""
response=int(raw_input("Enter 1 to see the next record, 2 to see the
previous record or 3 to end the program:"))
print""
if response > 3 or response < 1:
print ("Please respond with one of the set responses.")
elif response == 3:
print "Process ended"
break
else:
if response==1:
count += 1
if count >= len(plain_text):
count = 0
elif response==2:
count -= 1
if count < 0:
count = len(plain_text) - 1
print ""
print("Record {0}:".format(count))
print ""
print("Latitude: {0} Longitude: {1} Unencrypted Text: {2}
Encrypted Text: {3}".format(latitude[count],longitude[count],
plain_text[count], encrypted_text[count]))
ifile.close()
Is there any way to make the entirety of this much more precise or simpler, and possibly any way to restructure this?
An encryption sub procedure
? \$\endgroup\$encrypted_text=[''.join(chr(ord(ch)+2) for ch in string) for string in plain_text]
, but that is a list comprehension. \$\endgroup\$