CPSC120A
Fundamentals of Computer Science I

Lab 22

Encryption

Use the command line to create a new directory called lab22 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.

Ceasar Cypher

Create a Python function called ceasar_cypher(text, shift) in a file called cypher.py. The function should have two parameters, text, a string of any length, and shift, an integer. The function should return a string that has been modified according to the Ceasar cypher encryption algorithm. The Ceasar cypher algorithm shifts all alphabetic characters in a string by a specified number of places. That is, each letter in text is replaced with the letter that is shift places over in the alphabet. For example:

>>> ceasar_cypher("duck", 1)
>>> 'evdl'
>>> ceasar_cypher("evdl", -1)
>>> 'duck'

Letters that are shifted beyond the range of the alphabet are wrapped. For example:

>>> ceasar_cypher("zebu", 1)
>>> 'afcv'
>>> ceasar_cypher("afcv", -1)
>>> 'zebu'

Characters that are not lowercase letters are left unchanged. For example:

>>> ceasar_cypher("Duck!", 1)
>>> 'Dvdl!'

Submission

Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.