"""
cipher.py
A quick version of cryptographic stuff we did a few weeks ago.
(This is the "docstring", or interface spec :
what is this, and how do I use it?)
Jim M, Sep 30, GPL
"""
# (This is an implementation comment: what are the 'how' details?)
# I decided to use mod arithmetic
# to implement the encoding and decoding.
#
def main():
print "-- cipher ---\n"
key = int(raw_input("What is the key? (13) "))
word = raw_input("What is the word? (cat) ")
new_word = ""
for char in word:
crypt_char = chr(((ord(char) - ord('a') + key) % 26) + ord('a'))
new_word = new_word + crypt_char
print "'%s' encrypted is '%s' \n" % (word, new_word)
main()
syntax highlighted by Code2HTML, v. 0.93pm6