# lowercase_word_cipher.py # encode a word by shifting the letters along the alphabet # word = raw_input("What is the word to encode? (lowercase a-z only) ") cipher_key = input("What is the secret key? (-25 to 25) ") code_word = "" # initialze accumulator for letter in word: char_number = ord(letter) - ord('a') # number is from 0 to 26 code_number = (char_number + cipher_key) % 26 # shift, wrapping around at 'z' code_letter = chr(code_number + ord('a')) # convert back to a letter code_word = code_word + code_letter # grow answer in accumulator print "The coded word is '{}'.".format(code_word)