Skip to content

ShakalBhau0001/playfair-cipher-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Playfair Cipher Implementation (Python)

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.


๐Ÿงฑ Project Structure

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

โœจ Features

๐Ÿ”‘ Key Matrix Generation

  • Generates a 5ร—5 Playfair matrix using a keyword
  • Merges J into I (standard academic convention)
  • Fills remaining alphabet in correct order
  • Automatically removes duplicate letters

๐Ÿ”’ Encryption

  • Applies Playfair rules:
    • Same row โ†’ shift right
    • Same column โ†’ shift down
    • Rectangle rule โ†’ swap columns
  • Produces correctly formatted ciphertext

๐Ÿ”“ Decryption

  • Reverses Playfair encryption logic:
    • Same row โ†’ shift right
    • Same column โ†’ shift down
    • Rectangle rule โ†’ swap columns
  • Outputs decrypted plaintext (including padding if present)

๐Ÿงฎ Educational Focus

  • Clean and readable logic
  • Modular and structured functions
  • Ideal for beginners in cryptography
  • No external dependencies

๐ŸŽจ Rich CLI (Interactive Mode)

  • Beautiful colored terminal UI using Rich
  • Displays key matrix in a structured table
  • Interactive prompts with validation
  • Clean and readable output panels

โšก Dual Mode Support

  • ๐Ÿงผ Basic CLI โ†’ Lightweight, no dependencies
  • ๐ŸŽจ Rich CLI โ†’ Enhanced UI with colors and panels

๐Ÿ›  Technologies Used

Technology Role
Python 3 Core programming language
String Module Alphabet handling
Matrix Logic 5ร—5 key table implementation
Rich Styled CLI, colors, panels

๐Ÿ“Œ Purpose of This Project

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.


โ–ถ๏ธ How to Run

1๏ธโƒฃ Clone the repository

git clone https://github.com/ShakalBhau0001/playfair-cipher-python.git

2๏ธโƒฃ Navigate to the project folder

cd playfair-cipher-python

3๏ธโƒฃ Install Dependencies

pip install rich

OR

pip install -r requirements.txt

4๏ธโƒฃ Running the Project

๐Ÿงผ Basic CLI Version

python app.py

๐ŸŽจ Rich Interactive Version

python interactive.py

5๏ธโƒฃ Follow the prompts for Basic CLI Version

  • Enter a keyword
  • Choose direction:
    • E โ†’ Encrypt
    • D โ†’ Decrypt
  • Enter your message
  • View the result

๐Ÿ”Ž Example

Encryption :

Enter keyword: MONARCHY

Encrypt or Decrypt (E/D): E
Enter message: INSTRUMENTS

Encrypted: GATLMZCLRQXA

Decryption :

Enter keyword: MONARCHY

Encrypt or Decrypt (E/D): D
Enter message: GATLMZCLRQXA

Decrypted: INSTRUMENTSX

(Note: Final padding letter may appear during decryption.)


โš ๏ธ Limitations

  • Not secure for real-world use
  • Classical cipher (easily breakable)
  • Does not automatically remove padding after decryption
  • CLI-based interaction only

๐ŸŒŸ Future Improvements

  • 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

โš ๏ธ Disclaimer

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.


๐Ÿ“ธ Preview

1. Encryption

Rich CLI Preview

2. Decryption

Rich CLI Preview


๐Ÿชช Author

Shakal Bhau

GitHub: ShakalBhau0001


โญ Support

If you like this project, consider giving it a โญ on GitHub!


About

A Python implementation of the classical Playfair cipher with encryption and decryption support. Built for educational purposes to understand digraph substitution and historical cryptographic techniques.

Topics

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages