Functions – Ceaser Cipher

Write a function for encoding and decoding messages using a Ceaser Cipher.

Requirements for the encoding function:

  • Receives two arguments, the string to be decoded and the number of letters to shift in the alphabet.
  • Returns the encoded string, also known as the cipher.

Use the ord() and chr() functions to convert between letters and numbers.

Use modular math (% operator) to make the alphabet “wrap around,” meaning you continue shifting from z to a.

See the cipher problem in loops with lists checklist for some additional info.

If you do this right, you can use the same function to decode your messages as well. For example, if you shift the letters 4 letters forward, and then you shift them another 22 letters forward, you end up in the same place in the alphabet as before since 22+4 = 26.

If you get this to work, you can try to figure out where this text came from:

http://www.nemoquiz.com/csp/cipher/