I built a simple message encoder and decoder. The encoder decrements each letter's value by 3. For example: A would be replaced by D, and B would become E. The decoder does the opposite. Is there a way to write the decoder with less code like I did it with the encoder? I tried to do it (I put in the code), but it doesn't work. Any suggestions?
import string
shift = 3 # a shift of 3 letters. for example: A would become D, B would become E...
# encoding message
encode = raw_input("Enter message to encode: ")
print "The encoded message is:",
for i in encode:
print int(ord(i))-shift, # convert characters to numbers
print
print
#decoding message
decode = raw_input("Enter message to decode: ")
message = ""
for numStr in string.split(decode):
asciiNum = eval(numStr) # convert digits to a number
message = message + chr(asciiNum+shift) # append character to message and add shift
print "The decoded message is:", message
"""
#decoding message
decode = raw_input("Enter message to decode: ")
decode = int(decode)
print chr(decode+shift) # only works for one number
# doesn't work
for i in range(decode):
print chr(decode+shift),
"""