# cipher.py # # Convert a word to a code word # by adding a constant to each letter. # # Now with way to much debugging output!! # # Jim Mahoney | September 2014 def main(): print " -- seekrit codes !!! -- " word = raw_input(" What is the word? ") offset = input(" What is the offset? ") print code_word = "" # (accumulator pattern: build answer in code_word) for letter in word: print " -"*20 print " DEBUG: working on letter '{}' ".format(letter) letter_as_int = ord(letter) print " DEBUG: letter_as_int is {}".format(letter_as_int) letter_0_to_25 = letter_as_int - ord('a') print " DEBUG : letter_0_to_25 is {}".format(letter_0_to_25) code_0_to_25 = (letter_0_to_25 + offset) % 26 print " DEBUG : code_0_to_25 is {}".format(code_0_to_25) code_letter = chr(code_0_to_25 + ord('a')) print " DEBUG: code_letter is '{}' ".format(code_letter) code_word = code_word + code_letter print " DEBUG: code_word has grown to '{}' ".format(code_word) print print " The final code word is '{}' ".format(code_word) main()