Day 008 of the 100 Days of Python challenge creates a Caesar Cipher encoder and decoder. Each letter is shifted through the alphabet by a user-selected amount.
Project Overview
The core function accepts the original text, shift amount, and whether the user wants to encode or decode. Decoding reverses the shift by multiplying it by -1.
shifted_position = alphabet.index(letter) + shift_amount
shifted_position %= len(alphabet)
output_text += alphabet[shifted_position]
The modulo operation wraps positions around the end of the alphabet. Spaces and punctuation are preserved because characters that are not in the alphabet are added to the output unchanged.
The program repeatedly asks whether the user wants to run another message through the cipher. It also validates the encode or decode choice before continuing.
What This Project Teaches
Day 008 introduces function parameters, reusable functions, list indexing, modulo arithmetic, loops, input validation, and preserving non-letter characters. It is a compact example of turning a mathematical rule into a practical text transformation.
A Caesar Cipher is educational rather than secure encryption because its small key space can be guessed easily. The project is best understood as an introduction to algorithms and string processing.
Running the Project
cd 100daysofpython/day008
python main.py
The project also imports its logo from the folder’s art.py file. View the Day 008 source code on GitHub.
