Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔐 Rail Fence Cipher Implementation (Python)

A complete and educational Python implementation of the Rail Fence Cipher encryption algorithm. This project demonstrates zigzag-based transposition encryption and decryption using structured logic.

It is created as a learning and academic project to understand how classical transposition cryptography works internally, not as a production-ready security system.


🧱 Project Structure

rail-fence-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

🔢 Rail-Based Zigzag Pattern

  • Uses a numerical key (number of rails)
  • Writes plaintext in a zigzag pattern
  • Rearranges characters without substitution
  • Demonstrates classical transposition technique

🔒 Encryption

  • Removes spaces before processing
  • Arranges characters across rails
  • Reads row by row to produce ciphertext
  • Maintains character order logic correctly

🔓 Decryption

  • Reconstructs zigzag pattern
  • Restores original message structure
  • Reverses encryption algorithm accurately

🎨 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 structured display

🧮 Educational Focus

  • Clean and readable logic
  • Modular encryption & decryption functions
  • Ideal for beginners in cryptography
  • No external dependencies

🛠 Technologies Used

Technology Role
Python 3 Core programming language
List Logic Zigzag rail structure handling
Rich Styled CLI, colors, panels

📌 Purpose of This Project

This project is built to:

  • Understand classical transposition ciphers
  • Learn zigzag-based encryption logic
  • Explore position-based cryptographic techniques
  • Study reversible transformation algorithms

⚠️ This project is intended strictly for learning and demonstration purposes.


▶️ How to Run

1️⃣ Clone the repository

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

2️⃣ Navigate to the project folder

cd rail-fence-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

  • Choose direction:
    • E → Encrypt
    • D → Decrypt
  • Enter your message
  • Enter number of rails
  • View the result

🔎 Example

Encryption :

Encrypt or Decrypt (E/D): E
Enter message:  MEET ME TOMORROW
Enter number of rails: 2

Encrypted message: MEMTMROETEOORW

Decryption :

Encrypt or Decrypt (E/D): D
Enter message: MEMTMROETEOORW
Enter number of rails: 2

Decrypted message: MEETMETOMORROW

⚠️ Limitations

  • Not secure for real-world use
  • Classical cipher (easily breakable)
  • Small key space (limited rails)
  • Removes spaces during processing
  • CLI-based interaction only

🌟 Future Improvements

  • Preserve spaces and formatting
  • Add brute-force rail testing mode
  • Add frequency analysis support
  • Add input validation for rail values
  • Create GUI version
  • Combine into a classical cryptography toolkit

⚠️ Disclaimer

This implementation is created for educational and learning purposes only. The Rail Fence Cipher is historically significant but cryptographically insecure and must not be used to protect real-world sensitive data.


📸 Preview

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 Rail Fence cipher with encryption and decryption support. Built for educational purposes to understand zigzag-based transposition and historical cryptographic techniques.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages