A complete and educational Python implementation of the Playfair Cipher encryption algorithm. This project demonstrates matrix generation, digraph processing, and classical substitution encryption & decryption using structured logic.
It is created as a learning and academic project to understand how classical digraph-based cryptography works internally, not as a production-ready security system.
playfair-cipher-python/
โ
โโโ assets/ # Screenshots
โโโ app.py # Basic CLI Version
โโโ interactive.py # Rich-powered CLI
โโโ requirements.txt # Dependencies
โโโ LICENSE # Project license
โโโ README.md # Project documentation- Generates a 5ร5 Playfair matrix using a keyword
- Merges
JintoI(standard academic convention) - Fills remaining alphabet in correct order
- Automatically removes duplicate letters
- Applies Playfair rules:
- Same row โ shift right
- Same column โ shift down
- Rectangle rule โ swap columns
- Produces correctly formatted ciphertext
- Reverses Playfair encryption logic:
- Same row โ shift right
- Same column โ shift down
- Rectangle rule โ swap columns
- Outputs decrypted plaintext (including padding if present)
- Clean and readable logic
- Modular and structured functions
- Ideal for beginners in cryptography
- No external dependencies
- Beautiful colored terminal UI using Rich
- Displays key matrix in a structured table
- Interactive prompts with validation
- Clean and readable output panels
- ๐งผ Basic CLI โ Lightweight, no dependencies
- ๐จ Rich CLI โ Enhanced UI with colors and panels
| Technology | Role |
|---|---|
| Python 3 | Core programming language |
| String Module | Alphabet handling |
| Matrix Logic | 5ร5 key table implementation |
| Rich | Styled CLI, colors, panels |
This project is built to:
- Understand classical Playfair cryptography
- Learn digraph substitution techniques
- Explore historical encryption algorithms
- Study matrix-based encryption systems
โ ๏ธ This project is intended strictly for learning and demonstration purposes.
git clone https://github.com/ShakalBhau0001/playfair-cipher-python.gitcd playfair-cipher-pythonpip install richOR
pip install -r requirements.txtpython app.pypython interactive.py- Enter a keyword
- Choose direction:
Eโ EncryptDโ Decrypt
- Enter your message
- View the result
Encryption :
Enter keyword: MONARCHY
Encrypt or Decrypt (E/D): E
Enter message: INSTRUMENTS
Encrypted: GATLMZCLRQXADecryption :
Enter keyword: MONARCHY
Encrypt or Decrypt (E/D): D
Enter message: GATLMZCLRQXA
Decrypted: INSTRUMENTSX(Note: Final padding letter may appear during decryption.)
- Not secure for real-world use
- Classical cipher (easily breakable)
- Does not automatically remove padding after decryption
- CLI-based interaction only
- Add automatic padding removal
- Add configurable I/J handling
- Add input validation for shift values
- Add file encryption support
- Create GUI version
- Combine into a classical cryptography toolkit
This implementation is created for educational and learning purposes only. The Playfair Cipher is historically significant but cryptographically insecure and must not be used to protect real-world sensitive data.
Shakal Bhau
GitHub: ShakalBhau0001
If you like this project, consider giving it a โญ on GitHub!

