-
-
Notifications
You must be signed in to change notification settings - Fork 89
Caesar Cipher
CarterPerez-dev edited this page Feb 11, 2026
·
1 revision
Classical encryption tool with brute-force cracking and frequency analysis.
A CLI tool implementing the Caesar cipher with encrypt, decrypt, and crack commands. The crack feature uses chi-squared frequency analysis to automatically determine the shift key by ranking all 26 possible decryptions against English letter frequency distributions.
Status: Complete | Difficulty: Beginner
| Technology | Version | Purpose |
|---|---|---|
| Python | 3.12+ | Core language |
| Typer | - | CLI framework |
| Rich | - | Terminal formatting and tables |
- Encrypt text with a given shift key
- Decrypt text when the key is known
- Brute-force crack by trying all 26 shifts
- Chi-squared frequency analysis for ranking results
- File I/O support
- ROT13 is still used in forums and email
- Frequency analysis applies to other substitution ciphers in CTF challenges
- Brute-forcing small key spaces applies to weak passwords and short PINs
- Foundation for understanding why simple substitution ciphers fail
User Command
↓
main.py (Typer CLI: encrypt, decrypt, crack)
↓
┌──────────────┬──────────────┬──────────────┐
│ cipher.py │ analyzer.py │ constants.py │
│ Encrypt/ │ Frequency │ English │
│ decrypt │ analysis + │ letter │
│ logic │ chi-squared │ frequencies │
└──────────────┴──────────────┴──────────────┘
↓
utils.py (File I/O, input validation)
cd PROJECTS/beginner/caesar-cipher
# Install dependencies
uv sync
# Encrypt
caesar-cipher encrypt "HELLO WORLD" --key 3
# Output: KHOOR ZRUOG
# Decrypt
caesar-cipher decrypt "KHOOR ZRUOG" --key 3
# Output: HELLO WORLD
# Crack without knowing the key
caesar-cipher crack "KHOOR ZRUOG"
# Shows ranked table of all 26 possible decryptionscaesar-cipher/
├── src/caesar_cipher/
│ ├── cipher.py # Core encryption/decryption logic
│ ├── analyzer.py # Frequency analysis for cracking
│ ├── constants.py # English letter frequencies, alphabet
│ ├── main.py # CLI commands
│ └── utils.py # File I/O and input validation
├── tests/
└── pyproject.toml
# Run tests
uv run pytest tests/ -v
# Linting
uv run ruff check .
# Format
uv run ruff format .©AngelaMos | CertGames.com | CarterPerez-dev | 2026