PYTHON
CRYPTOGRAPHY – CAESAR CIPHER

 

 

DESCRIPTION


You will write code related to the Caesar cipher that can be used in encrypting/decrypting messages.


THE CAESAR CIPHER

 

The Caesar cipher which was apparently used by Julius Caesar, is a subgroup of substitution ciphers.  A Caesar cipher is a cipher that shifts each letter in the plaintext by a shift_amount.   

 

For example, if we shift the letter A by 2, then we get the letter C.  If we shift the letter Z by 2, we wrap around the alphabet and we get the letter B.

 

Ceasar cipher
(shift by 2)

Ceasar cipher

(shift by 10)

 

A -> C

B -> D

C -> E

X -> Z

Y -> A

Z -> B

 

 

A -> K

B -> L

C -> M

X -> H

Y -> I

Z -> J

 

To decrypt a ciphertext, we can simply shift the by negative amount that we shifted initially.

 

For example, if we shift C by -2, we get A.

 

WORK

 

QUESTION 1

In a Python file called Caesar, write the enc and dec functions for Caesar ciphers.  They only need to work with lowercase letters.

 

enc (word, shift_amount)

dec (word, shift_amount)

 

Test your code.

 

QUESTION 2

 

One special case of the Caesar ciphers, is the one that shifts by 13.  Why is it special?

Hint: Try encrypting a plaintext twice.

 

QUESTION 3

 

The following sentence has been encrypted using the Caesar cipher with a shift of 16.  Use your program to decrypt it.

 

JXUIUQHUDJJXUTHEYTIOEKHUBEEAYDWVEH