Skip to content

ShakalBhau0001/rail-fence-cipher-cryptanalysis-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Rail Fence Cipher Cryptanalysis (Python)

An educational Python implementation of Rail Fence Cipher brute-force cryptanalysis.

This project demonstrates how classical transposition ciphers can be broken using systematic rail reconstruction and exhaustive search.

It is designed strictly as a learning and academic project to understand the structural weaknesses of classical ciphers โ€” not as a real-world attack tool.


๐Ÿงฑ Project Structure

rail-fence-cipher-cryptanalysis-python/
โ”‚
โ”œโ”€โ”€ assets/             # Screenshots
โ”œโ”€โ”€ app.py              # Clean CLI 
โ”œโ”€โ”€ interactive.py      # Rich-powered CLI
โ”œโ”€โ”€ requirements.txt    # Dependencies
โ”œโ”€โ”€ LICENSE             # Project license
โ””โ”€โ”€ README.md           # Project documentation

โœจ Features

๐Ÿ” Full Brute-Force Rail Search

  • Tests all possible rail values from 2 to n-1
  • Displays all possible plaintext candidates
  • Reconstructs zigzag pattern for each rail count

๐Ÿ” Zigzag Pattern Reconstruction

  • Dynamically marks rail positions
  • Fills matrix row-wise using ciphertext
  • Re-traverses zigzag pattern to rebuild plaintext

๐Ÿง  Structural Cryptanalysis Focus

  • Demonstrates transposition cipher weakness
  • Shows how unknown key (rail count) can be recovered
  • Reinforces matrix-based algorithmic thinking

๐Ÿงฎ Educational Focus

  • Clean modular Python functions
  • Clear separation between:
    • Decryption logic
    • Brute-force controller
  • CLI-based execution

๐ŸŽจ 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

๐Ÿ›  Technologies Used

Technology Role
Python 3 Core programming language
2D Lists (Matrix) Rail pattern simulation
Control Flow Logic Zigzag traversal and reconstruction
Brute Force Search Exhaustive rail testing
Rich Styled CLI, colors, panels

๐Ÿ“Œ Purpose of This Project

This project is built to:

  • Understand Rail Fence Cipher weaknesses
  • Learn brute-force cryptanalysis for transposition ciphers
  • Explore zigzag matrix reconstruction logic
  • Simulate attacker perspective ethically
  • Strengthen Python control-flow and indexing skills

โš ๏ธ This project is intended strictly for educational and cybersecurity learning purposes.


โ–ถ๏ธ How to Run

1๏ธโƒฃ Clone the repository

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

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

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

  • Provide any Rail Fence encrypted message (without spaces)
  • View all possible plaintext outputs for different rail values
  • Identify the most meaningful English result

๐Ÿ”Ž Example

Enter ciphertext: HOLELWRDLO

--- Brute Force Results ---

Rails = 2 โ†’ HWORLDELLO
Rails = 3 โ†’ HELLOWORLD
Rails = 4 โ†’ HLWLREOLDO
...

โš ๏ธ Limitations

  • Does not automatically score English likelihood
  • Outputs all possible rail reconstructions
  • Manual inspection required to identify correct plaintext
  • Inefficient for very large inputs (O(nยฒ) behavior)
  • CLI-based interaction only

๐ŸŒŸ Future Improvements

  • Rank most probable plaintext automatically
  • Add English-likelihood scoring system
  • Add file input support
  • Convert into reusable Python module
  • Add visualization of zigzag pattern

โš ๏ธ Disclaimer

This project is created for educational and cybersecurity learning purposes only. It demonstrates the inherent weakness of classical transposition ciphers such as the Rail Fence Cipher. It must not be used for unauthorized access, malicious activity, or real-world security attacks.


๐Ÿ“ธ 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 brute-force cryptanalysis for the Rail Fence Cipher. This project systematically tests all possible rail values to demonstrate structural weaknesses in classical transposition-based cryptographic systems.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages