Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Caesar Cipher — Encryption & Decryption

DecodeLabs Cyber Security Training Kit — Project 2

A simple, well-tested implementation of the classic Caesar cipher, available two ways: an interactive Python CLI and a browser-based tool with a live cipher-disk visualization.

What it does

  • Encrypts text using a Caesar cipher (letter-shift logic)
  • Decrypts ciphertext back to the original message
  • Handles spaces, punctuation, numbers, and shifts greater than 26 or negative
  • Displays both encrypted and decrypted output
  • Includes a browser version with a rotating cipher-disk visual that shows the letter mapping live as the shift changes

Files

File Description
caesar_cipher.py Main Python program with an interactive menu
test_cipher.py Automated tests to verify correctness, including edge cases
caesar_cipher.html Browser version with an interactive cipher disk — no install needed

Option 1: Run in Python (CLI)

Requirements

Python 3.6 or later. No external libraries needed.

How to run

  1. Download caesar_cipher.py and test_cipher.py into the same folder.
  2. Open a terminal in that folder.
  3. Run the main program:
    python caesar_cipher.py
    
    (On some systems use python3 caesar_cipher.py)
  4. You'll see a menu:
    1. Encrypt a message
    2. Decrypt a message
    3. Encrypt then decrypt (verify round-trip)
    4. Exit
    
    Type a number and press Enter, then follow the prompts.

Example

Enter choice (1-4): 3
Enter your message: Hello, World!
Enter shift key (e.g. 3): 3

Original Text : Hello, World!
Encrypted Text: Khoor, Zruog!
Decrypted Text: Hello, World!
Matches original: YES ✅

Run the tests (optional but recommended)

python test_cipher.py

This runs several pre-built cases (including edge cases like shift > 26 and negative shifts) and confirms every message decrypts back to its original form.

Option 2: Run in the Browser

caesar_cipher.html runs the same encrypt/decrypt logic directly in the browser — no Python required. It includes:

  • Encrypt, Decrypt, and Round-trip Verify modes
  • A live shift slider with a numeric input
  • An animated cipher disk that rotates to visualize the letter shift
  • A copy-to-clipboard button on each output

How to run

Simplest way — just open the file directly:

  1. Double-click caesar_cipher.html, or drag it into any browser tab.

To run it via localhost instead:

python -m http.server 8000

Then open http://localhost:8000/caesar_cipher.html in your browser.

Next steps (bonus, from the training deck)

  • Let the user pick their own shift key (already supported here)
  • Try building a Vigenère cipher, where the shift changes per letter based on a keyword instead of one fixed number

About

A Python implementation of the classic Caesar cipher with an interactive CLI for encrypting and decrypting text, plus a browser-based version with a live cipher-disk visualization. Built as Project 2 of the DecodeLabs Cyber Security Training Kit.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages