diff --git a/app/substitution-breaker/page.tsx b/app/substitution-breaker/page.tsx new file mode 100644 index 00000000..9e8c5f5e --- /dev/null +++ b/app/substitution-breaker/page.tsx @@ -0,0 +1,22 @@ +import type { Metadata } from "next"; +import SubstitutionBreaker from "../../components/cryptanalysis/SubstitutionBreaker"; +import Navbar from "../../components/layout/Navbar"; +import Footer from "../../components/layout/footer"; + +export const metadata: Metadata = { + title: "Substitution Cipher Breaker — Automated Cryptanalysis | CryptoViz", + description: + "Automatically crack monoalphabetic substitution ciphers using frequency analysis and hill climbing with simulated annealing. Interactive educational cryptanalysis tool.", +}; + +export default function SubstitutionBreakerPage() { + return ( +
+ {label} +
+ )} ++ Full Decrypted Text +
++ {result.plaintext} +
++ Cryptanalysis Tool +
++ Automatically crack monoalphabetic substitution ciphers using frequency analysis for the initial seed, then hill climbing with simulated annealing to refine the key mapping. Works on any fixed-letter-substitution cipher. +
++ How It Works +
++ The breaker maps the most frequent ciphertext letters to expected English frequencies, then iteratively improves the mapping by swapping letter assignments and scoring with quadgram log-likelihood. +
++ Paste a monoalphabetic substitution cipher for automated breaking. +
++ Initial Frequency Analysis Seed +
++ {initialPlaintext.slice(0, 120)} + {initialPlaintext.length > 120 ? "..." : ""} +
++ Score: {scoreKey(ciphertext, initialKey).toFixed(1)} +
++ {item.value} +
++ Quadgram fitness score over iterations (higher = more English-like) +
+Start Score
++ {convergenceHistory[0]?.score.toFixed(1) ?? "N/A"} +
+Final Score
++ {convergenceHistory[convergenceHistory.length - 1]?.score.toFixed(1) ?? "N/A"} +
+Improvement
++ {( + (convergenceHistory[convergenceHistory.length - 1]?.score ?? 0) - + (convergenceHistory[0]?.score ?? 0) + ).toFixed(1)} +
++ Ciphertext +
++ ABCDEFGHIJKLMNOPQRSTUVWXYZ +
++ Plaintext +
++ {result.best.key} +
++ {result.best.plaintext} +
++ A monoalphabetic substitution cipher replaces each letter with a fixed different letter. + Unlike Caesar ciphers, the mapping is arbitrary — A might become Q, B might become Z, etc. + The mapping is described by a 26-letter key showing what each ciphertext letter decrypts to. +
++ English has predictable letter frequencies (E≈12.7%, T≈9.1%, A≈8.2%...). By counting letter + frequencies in the ciphertext and mapping the most common cipher letters to the most common + English letters, we get a good initial approximation. +
++ The initial frequency seed is refined by hill climbing: randomly swap two letter assignments + in the key and keep the swap if the quadgram fitness score improves. Simulated annealing + occasionally accepts worse swaps at high temperatures to escape local optima, gradually cooling + to converge on the best solution. +
++ The fitness function scores candidate plaintext by summing log-likelihoods of every 4-character + sequence (quadgram). Natural English has high-probability quadgrams like "TION", "TING", "THAT" + while random text has low-probability quadgrams. Higher total score = more English-like. +
+