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.
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- Tests all possible rail values from
2ton-1 - Displays all possible plaintext candidates
- Reconstructs zigzag pattern for each rail count
- Dynamically marks rail positions
- Fills matrix row-wise using ciphertext
- Re-traverses zigzag pattern to rebuild plaintext
- Demonstrates transposition cipher weakness
- Shows how unknown key (rail count) can be recovered
- Reinforces matrix-based algorithmic thinking
- Clean modular Python functions
- Clear separation between:
- Decryption logic
- Brute-force controller
- CLI-based execution
- 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 structured display
| 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 |
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.
git clone https://github.com/ShakalBhau0001/rail-fence-cipher-cryptanalysis-python.gitcd rail-fence-cipher-cryptanalysis-pythonpip install richOR
pip install -r requirements.txtpython app.pypython interactive.py- Provide any Rail Fence encrypted message (without spaces)
- View all possible plaintext outputs for different rail values
- Identify the most meaningful English result
Enter ciphertext: HOLELWRDLO
--- Brute Force Results ---
Rails = 2 โ HWORLDELLO
Rails = 3 โ HELLOWORLD
Rails = 4 โ HLWLREOLDO
...- 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
- Rank most probable plaintext automatically
- Add English-likelihood scoring system
- Add file input support
- Convert into reusable Python module
- Add visualization of zigzag pattern
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.
Shakal Bhau
GitHub: ShakalBhau0001
If you like this project, consider giving it a โญ on GitHub!
