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/
│
├── app.py # Rail Fence brute-force cryptanalysis tool (CLI based)
├── 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
| 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 |
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-pythonpython app.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
- Integrate into a Classical Crypto Toolkit
- 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