Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Caesar Cipher — Basic Encryption & Decryption

Project 2 | Cyber Security Track | DecodeLabs Industrial Training Kit (Batch 2026)

A Python implementation of the classic Caesar (shift) cipher, built to demonstrate the fundamental IPO model of cryptographic systems:

INPUT (Plaintext) → PROCESS (Algorithm + Key) → OUTPUT (Ciphertext)

Features

  • 🔐 Encrypt any text using a customizable shift key
  • 🔓 Decrypt ciphertext back to the original plaintext
  • 🔤 Handles uppercase and lowercase letters independently
  • 🔢 Leaves spaces, punctuation, and digits untouched
  • ➕➖ Supports negative and out-of-range shift keys (via modulo wraparound)
  • 🕵️ Bonus brute-force demo — shows all 25 possible shifts, illustrating why the Caesar cipher is a "lockbox, not a vault"
  • ✅ Includes a small test suite validating round-trip correctness

How It Works

The cipher shifts each letter's position in the alphabet by a fixed key n, wrapping around using modular arithmetic:

Encryption: E(x) = (x + n) % 26
Decryption: D(x) = (x - n) % 26

In Python, this is implemented using ord() (character → integer) and chr() (integer → character):

cipher_char = chr((ord(char) - 65 + shift) % 26 + 65)

Getting Started

Prerequisites

  • Python 3.7+

Run the program

python caesar_cipher.py

You'll be prompted for:

  1. The text you want to encrypt
  2. A shift key (integer, e.g. 3)

The program then prints the encrypted text, decrypts it back, and confirms the round-trip was successful.

Run the tests

python test_caesar_cipher.py

Example

Enter the text to encrypt: Attack at dawn!
Enter the shift key (e.g. 3): 3

--- Results ---
Plaintext : Attack at dawn!
Shift Key : 3
Encrypted : Dwwdfn dw gdzq!
Decrypted : Attack at dawn!
Round-trip Check: PASSED ✅

Project Structure

caesar-cipher-project/
├── caesar_cipher.py       # Core encryption/decryption logic + CLI
├── test_caesar_cipher.py  # Unit tests
└── README.md              # This file

Possible Extensions

  • Let the user pick a custom alphabet or symbol set
  • Implement a Vigenère cipher (multi-character key) for stronger security
  • Add frequency-analysis-based automatic decryption (no key needed)

Why This Matters

The Caesar cipher isn't secure by modern standards (only 25 possible keys, and it preserves letter-frequency patterns — making it vulnerable to frequency analysis). But it's the foundational building block for understanding how modern encryption (like AES) evolved: confusion, diffusion, and mathematical transformation of data to protect confidentiality.


Built as part of the DecodeLabs Industrial Training Kit — Cyber Security, Project 2.

About

A Python implementation of the Caesar Cipher for encryption and decryption — Cyber Security Project 2

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages