In this lesson, students will learn about the Caesar cipher, a simple encryption technique. They will then implement their own Caesar cipher encoder and decoder using Python.
Discuss the logic:
def caesar_cipher_encrypt(text, shift):
encrypted_text = ""
for char in text:
if char.isalpha():
********* missing Code *************
Step 2: Writing the decryption function
def caesar_cipher_decrypt(text, shift):
return caesar_cipher_encrypt(text, -shift)
Step 3: Testing the functions
message = "Hello, World!"
shift_value = 3
encrypted_message = caesar_cipher_encrypt(message, shift_value)
*************** missing Code *********************
print(f"Decrypted: {decrypted_message}")
3. Enhancements & Challenges (15 min)
- Modify the function to allow for non-alphabetic character shifts.
- Add user input functionality.
- Create a function that brute-force decrypts a message (trying all 25 shifts).
- Implement a Caesar cipher using list comprehensions.
4. Q&A and Wrap-up (5 min)
- Review key concepts.
- Discuss real-world applications of simple ciphers.
- Homework: Research frequency analysis and how it can be used to break the Caesar cipher.
Assessment
*********
*********
You will drop off 4 files into Google Classroom:
• Your files will be: (Remember the python program is dropped off first.)
• PX_lastname_CeasarCipherPython.py (Actual Python code)
• PX_lastname_CeasarCipherPython.png (Screenshot in the Cyber Range)
• PX_lastname_CeasarCipherPython.txt (Source code as Text)
• PX_lastname_CeasarCipherPython.mp4 (Video running the program)