This repository contains a Jupyter notebook (main.ipynb) implementing cryptographic techniques to decipher substitution cipher messages. Starting with brute-force permutations, it advances to frequency analysis using Moby Dick text, bigram scoring, and culminates in the Metropolis algorithm for probabilistic optimization.
- Permutation Brute-Force: Tests all 27 rotations (A-Z + space) to identify viable decryptions.
- Frequency Analysis: Maps cipher letter frequencies to English norms from Gutenberg texts (Moby Dick); includes interactive swapping for refinement.
- Bigram Score Function: Computes log-probability of letter pairs against reference corpus for English-likeness evaluation.
- Metropolis Algorithm: MCMC optimization swaps letters probabilistically based on score improvements, annealing via T sequence (10.0 to 0.1); deciphers complex messages.
- Examples: Some example messages have been left in, change the message within the variable
message.
- Clone repo:
git clone https://github.com/MrRedIsBack/CodeBreaking_StatisticalPhysics - Open
main.ipynbin Jupyter:jupyter notebook main.ipynb - Run cells sequentially:
- Downloads Gutenberg texts (Moby Dick, etc.) automatically.
- Test permutations on sample messages.
- Refine via frequency mapping and manual swaps.
- Apply Metropolis for final decryptions.
MIT License – feel free to fork and extend for educational use.