# Caesar cipher

An encryption utility.

## Try

Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.

Note this is an advanced Caesar cipher that also encrypts punctuation and some special characters, including space. A standard Caesar cipher would only encrypt the letters A-Z.

Watch this video to learn about the new concepts shown in the program:

## Investigate

Outline the relationship between the number 65 and the letter A, explaining why “A” != “a” and also why when sorted, “103” is before “23”.

Every character is stored as a number by the computer. The letter “A” is the number 65. “a” is 97, so “A” and “a” are not the same because 65 is not 97.

The alphanumeric character “1” is stored as the number 49 and “2” is stored as 50, so 49 is before 50. Each character is taken in turn when data is sorted in a simplistic way.

Explain why using `ord` and `chr` in lines 10 and 14 is the easiest way to approach this program.

The key requires a shift of five characters. It is much easier to convert a character to a number, add five and then convert it back again. Otherwise you would need a very long program with lots of conditions, or an array to hold the data. Using the built-in ASCII table is a simple solution.

## Make

### Success Criteria

Change the program so that it:

1. Has a `dedecrypt_message` function that takes an encrypted message and returns the plain text message.
2. Outputs a decrypted message in plain text.

#### Typical inputs and outputs from the program would be:

Enter a message: Hello World

Message to send: Mjqqt%\twqi

Message is decrypted to: Hello World

Enter a message: The weather is cloudy with a small chance of rain.

Message to send: Ymj%|jfymjw%nx%hqtzi~%|nym%f%xrfqq%hmfshj%tk%wfns3

Message is decrypted to: The weather is cloudy with a small chance of rain.

#### Knowledge Organiser

Use these resources to learn about new commands for this level and to help you meet the success criteria.

###### Notes:

x = ord(y)

x is assigned to be the ASCII code for character y.

x = chr(y)

x is assigned to be the character for the ASCII code y.

## Evaluate

Run the unit tests below to check that your program has met the success criteria.

Enter a message: The quick brown fox jumps over the lazy dog.

Message to send: Ymj%vznhp%gwt|s%kt}%ozrux%t{jw%ymj%qf ~%itl3

Message is decrypted to: The quick brown fox jumps over the lay dog.

Craig ‘n’ Dave

In partnership with