11  Python for Cybersecurity

11.1 Encryption

11.1.1 Caesar Cipher and ROT13

11.1.2 Questions for Caesar Cipher

In this activity, answer the following questions. You can use an online Caesar Cipher disk such as http://inventwithpython.com/cipherwheel/ to help you.

  1. Using the Caesar Cipher Wheel, encode the name of your school. (THAAC)

  2. Use the wheel, encipher your name using three different keys.

  3. How many different keys are there with the Caesar cipher? Explain.

  4. Decode this message, which was enciphered using a Caesar Cipher with a shift of 7. nvvk nyhklz ahrl fvb mhy

  5. Can you figure out the key and decode this message? frpsxwhu vflhqfh urfnv

11.1.3 Coding Exercise

11.1.3.1 Code: Caesar Cipher Encryption

In this activity, we are going to create a program that can encrypt a message using a Caesar cipher.

Your program should prompt the user for a phrase and a shift amount, then return the encrypted text.

While there are several ways to make a Caesar cipher, we will be using an alphabet string. You will want to find the index of a letter in that string, then shift by the entered value to find the encoded letter.

Hint: Individual characters in a string can be accessed by specifying the string name followed by a number in square brackets [].

Sample output:

Please enter the message you would like to encode: Hello World!
Please enter the amount to shift: 5
Your encoded message:
MJQQT BTWQI!

Code here:

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

def encrypt(clear_text, shift):
    #Encrypt the clear text
    pass

# Prompt the user for a phrase and shift

11.1.3.2 Code: Caesar Cipher Decryption

In this activity, we are going to extend the program you made earlier to add a decryption feature. After prompting the user for the phrase and shift amount, ask them if they would like to encrypt or decrypt their message.

Your program should then perform the correct procedure and print the results.

Hint: Individual characters in a string can be accessed by specifying the string name followed by a number in square brackets [].

Sample Output:

Please enter the message you would like to encode: Hello World!
Please enter the amount you would like to shift: 8
Would you like to (e)ncrypt or (d)ecrypt? e
Your encoded message:
PMTTW EWZTL!
Please enter the message you would like to encode: PMTTW EWZTL!
Please enter the amount you would like to shift: 8
Would you like to (e)ncrypt or (d)ecrypt? d
Your decoded message:
HELLO WORLD!

Code here:

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

def encrypt(clear_text, shift):
    # Copy your code from the encryption activity
    pass

def decrypt(encrypted, shift):
    # Call your encryption function here
    pass


# Prompt the user for a phrase and shift

11.1.3.3 Break Caesar’s Cipher!

https://rakhqljlbf-2460056741-a.codehs.me/index.html

Refelction:

In the last lesson, you had a chance to break a Caesar Cipher. Based on that experience, reflect on he following questions:

  1. How did you go about breaking the message encoded with a Caesar Cipher?

  2. You had the use of a computer, which made this process easy. If you didn’t have a computer, how might your process for decoding the message change? Do you think you would still be able to break the message?

  3. What are some things that we could do to make the Caesar Cipher stronger?