Simple Caesar Cipher Python assignment

Your assignment is create a simple caesar cipher program in python. You will need to submit pseudocode along with the assignment, so please make sure you do not just copy code from somewhere because you will need to be able to write the pseudocode for your program as well. If you do not wish to write pseudocode, I will accept a Snap! program in addition to your python code.

Requirements:

  • Create a user menu that asks the user if they want to encrypt, decrypt, or quit (use the code from your dice roller game).
  • Must take user input for the phrase to be encrypted or decrypted
  • Must ask the user for a key that will be the shift for the caesar cipher to encrypt or decrypt
  • Do not encrypt or decrypt any non-alphabetic characters (eg. 123, ‘, ~, {…), leave them as they are. Check for uppercase characters and convert everything to lowercase.
  • After successful encryption/decryption, output the result and then go back to the menu to ask the user if they want to encrypt, decrypt, or quit.
  • You must use a python function for encrypt, and a separate python function for decrypt (go back to the website to see how to do functions).

Here are some hints for your assignment.

Define a variable called alphabet:

alphabet = ‘abcdefghijklmnopqrstuvwxyvz’

Get each letter, one at a time, and compare it to the variable alphabet above, to find the position of the letter in the alphabet (eg. ‘h’ would be alphabet[7]).

 

Then use the following algorithm (and a for loop) inside your encrypt and decrypt functions to find the cipher alphabet given a letter from the above string:

Encrypt (x) = (x + n) % 26
Decrypt (x) = (x – n) % 26

Or another way would be to create a shift_alpha variable that has all the letters shifted by the key (key = 3 in the eg. below), then look for shift_alpha[7]:

shift_alpha = ‘defghijklmnopqrstuvwxyzabc’

As usual, please submit your .py file along with your pseudocode document on the server when you are done. This assignment is due on Wed Apr 19.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s