Part 2: Breaking RSA and Synchronizing

Transformers with the Same Clocks

Imagine a watchmaker's bench holding three kinds of clocks.

First come the prime clocks from Part 1. Their hands turn at speeds $\log 2, \log 3, \log 5, \ldots$, oblivious to one another and incapable of sharing a common beat. Because they never repeat and never interact, their chained arrows drift evenly across every angle, scattering the branch points of $P(s) = \tfrac14$ across a band while obeying an exact statistical density law.

Once you have built a physical picture that simple, a physicist's instinct is to reach for the knobs and break one rule at a time. First, break the lack of rhythm: put clocks on the bench that do repeat after a finite number of ticks, and watch ergodic drift collapse into sharp constructive wave interference. That is Shor's quantum factoring algorithm. Second, break their isolation: wire the clocks together so each hand feels where the others are pointing, and watch drifting arrows pull one another into synchronized factions. That is self-attention inside deep transformers.

In this second part, we follow what happens when those turning arrows repeat, when they couple to one another, and what all three cases say about the history ordinary numbers are built to erase.

Factoring as a hidden seam

Every time your browser opens an encrypted connection, modern public-key cryptography leans on an asymmetry you can already feel on a wooden ruler. In RSA encryption, you pick two large primes $p$ and $q$, keep both secret, and publish only their product $N = pq$. Anyone can lock a message using $N$ (together with a public exponent), while unlocking it requires private keys built from $p$ and $q$.

Picture that product on the logarithmic ruler from Part 1. Multiplying $p$ by $q$ lays two sticks of length $\log p$ and $\log q$ end to end to reach $\log N$. Publishing $N$ hands the world a single unmarked bar of total length $\log N$ with the joint painted over (Figure 1). Breaking the key by factoring means finding the hidden seam inside that bar. For $N = 15$, tapping every candidate joint takes a blink. For an RSA-2048 key, each prime runs roughly 300 decimal digits long, and no known classical algorithm locates the seam in practical time. (To be exact, nobody has proved that breaking RSA is strictly equivalent to factoring $N$, only that factoring $N$ is enough to break it.)

A logarithmic ruler from 1 to 20. Top: sticks of length log 3 and log 5 laid end to end reach the mark 15. Bottom: a blank bar from 1 to 15 with every possible joint marked and the two lengths unknown.
Figure 1. A key on the logarithmic ruler. Top: multiplying 3 by 5 lays sticks of length $\log 3$ and $\log 5$ end to end to reach 15. Bottom: the published product shows only the total length; factoring means locating the hidden joint.

Shor's algorithm: clocks that repeat

In 1994, Peter Shor showed that a quantum computer does not hunt for the hidden seam at all. Instead, it listens for a chord.

Pick a base $a$ that shares no factor with $N$ (if it happens to share one, $\gcd(a, N)$ hands you the answer immediately) and track the remainders $a, a^2, a^3, \ldots \pmod N$. Because only finitely many remainders exist, the sequence must loop back with some smallest period $r$. On a classical machine, finding $r$ still requires stepping through exponentially many powers. On a quantum machine, $r$ is a frequency waiting to be heard by interference.

Watch it happen on $N = 15$ with base $a = 2$. The remainders modulo 15 march $2, 4, 8, 1, 2, 4, 8, 1, \ldots$, repeating every $r = 4$ ticks. The Chinese remainder labels from my grandfather's wine riddle in Part 1 reveal the clockwork inside: write each remainder modulo 15 as its pair of remainders modulo 3 and modulo 5.

step $x$$2^x \bmod 15$$\bmod 3$$\bmod 5$
1222
2414
3823
4111

Inside multiplication modulo 15 tick two independent gears: a mod-3 clock repeating every 2 steps, and a mod-5 clock repeating every 4 steps. The combined period $r = 4$ is simply their least common multiple, the first tick where both gears strike 1 together.

Now put that rhythm on a quantum register. Eleven qubits carry one complex arrow (amplitude) for each of $Q = 2^{11} = 2048$ ticks $x = 0, 1, \ldots, Q - 1$, all initialized equally. In one coherent pass, the computer evaluates $a^x \bmod N$ into a second register, entangling every tick with its remainder. Measuring that remainder register collapses the tick register onto only the ticks that produced the observed value (say remainder 2), leaving a clean periodic comb spaced exactly $r$ ticks apart: $x = 1, 5, 9, \ldots$.

Next comes the quantum Fourier transform (QFT), an interferometer acting as a tuning fork over the surviving comb. For each candidate frequency $k \in \{0, \ldots, Q - 1\}$, the QFT chains one arrow per tooth of the comb, rotating each successive arrow by $kr/Q$ of a full turn. By Feynman's rule, the probability of reading out frequency $k$ is the squared length of that arrow chain. Whenever $k$ is an integer multiple of $Q/r$, every step is a whole number of full turns: the arrows lock head to tail, stretch across the plane, and build a tall probability spike. At every other frequency, the arrows curl into a closed polygon and erase themselves.

k = 0
Figure 2. live The quantum Fourier transform as a chain of arrows. At multiples of $Q/r$ the arrows align, the chain runs out in one direction, and a sharp peak stands in the spectrum; elsewhere the chain closes and cancels. Shown for $r = 4$ (the $N = 15$ example) with $Q = 256$ for visual clarity; the numerical runs below use $Q = 2048$.

In my $Q = 2048$ simulation for $N = 15$ and $a = 2$, four sharp peaks rise at $k = 0, 512, 1024, 1536$, each carrying exact probability $0.25$ while every other bin drops to zero. Compare that to the prime clock shop of Part 1: the mathematics of chained rotating arrows is identical, yet because modular clocks share a finite period, constructive interference replaces random drift with four clean resonant lines.

Measuring a lucky spike like $k = 512$ returns $k/Q = 512/2048 = 1/4$, whose denominator hands you $r = 4$. From that moment on, the quantum machine is done; the finish is pure classical arithmetic. Because $2^4 \equiv 1 \pmod{15}$ and $r = 4$ is even, $15$ divides $2^4 - 1 = (2^2 - 1)(2^2 + 1) = 3 \times 5$. Computing $\gcd(3, 15) = 3$ and $\gcd(5, 15) = 5$ breaks the key open. After all the superposition and wave interference, a billion-dollar quantum factoring machine hands its final verification to Euclid's greatest common divisor, the exact same rule that governed my grandfather's 8-5-3 wine riddle.

Under the hood: Euler's totient, failed bases, and N = 21

Why did $2^2 - 1 = 3$ split 15 cleanly? Look back at the table at half-period $x = r/2 = 2$: there $2^2 \equiv 1 \pmod 3$ while $2^2 \equiv -1 \pmod 5$. The two prime clocks are caught out of step, so $2^2 - 1$ is divisible by 3 and not by 5. Two bad-luck traps require drawing a fresh random base $a$: either $r$ is odd (no integer half-period exists), or $r$ is even yet $a^{r/2} \equiv -1 \pmod N$, meaning both prime clocks land on $-1$ together (as for $N = 15, a = 14$, where $r = 2$ and $14^1 \equiv -1$). For any odd composite with at least two distinct prime factors, at least half of all coprime bases avoid both traps.

Shor's modular clocks also stay close to Euler's product from Part 1. For $N = pq$, the period $r$ always divides Euler's totient $\varphi(N) = (p - 1)(q - 1) = N(1 - 1/p)(1 - 1/q)$, the inverted Euler factors of $\zeta(1)$ kept only for the primes dividing $N$ (for $N = 15$, $\varphi(15) = 8$, and $r = 4$ divides 8). Dirichlet fused both kinds of clock in 1837 inside his $L$-functions, twisting $n^{-s}$ by periodic modular characters; those are the functions covered by the generalized Riemann hypothesis.

Finally, stepping up to $N = 21$ with $a = 2$ shows finite-grid leakage when $r$ does not divide $Q$. Here $r = 6$, so target spikes fall at multiples of $2048/6 \approx 341.33$: only $k = 0$ and $k = 1024$ land cleanly on the grid (probability $0.167$ each), while the four off-grid peaks smear across neighboring bins (peak height $0.114$). My first simulated draw landed on $k = 1024$, where $1024/2048$ reduces to $1/2$ instead of $3/6$ because 3 and 6 share a factor. Even that reduced guess $r' = 2$ happened to yield $\gcd(2^1 + 1, 21) = 3$, though in practice one simply re-runs or uses continued fractions on off-grid peaks.

Of course, real hardware remains far behind the blackboard. Experimental quantum chips have run heavily compiled versions of Shor's circuit on tiny composites like 15 and 21, and today's processors hold roughly a thousand noisy physical qubits. Resource estimates for breaking RSA-2048 have fallen sharply, from about 20 million noisy qubits over eight hours (Gidney and Ekerå, 2019) to under one million noisy qubits over roughly a week (Gidney, 2025), yet fault-tolerant machines at that scale are still years away. Even so, the contrast with Part 1 is already clear. Switch the clocks from incommensurable to periodic, and the same turning arrows trade ergodic scatter for resonant factoring.

Attention in motion: clocks that talk to each other

Now go back to the prime clocks and break the other rule.

In Part 1, every prime hand in $P(s) - \tfrac14$ rotated in complete solitude: the 2-hand never tugged on the 3-hand, which is why Weyl's theorem held and the density formula came out exact. We also noticed that static softmax inside a transformer is a Boltzmann distribution over scores, with inverse temperature $\beta = 1/\sqrt{d}$.

In a real deep transformer, though, attention does not happen once and freeze. It runs layer after layer, dozens of times in a row, and at every layer the tokens move. After leaving crystal thermal transport to lead AI teams, I found it impossible to look at stacked self-attention without recognizing an old friend from condensed-matter physics: an interacting many-body system.

Treat layer depth as continuous time and place each token on a circle (the two-dimensional toy version of the high-dimensional sphere on which normalized embeddings live). At each step in depth, every token shifts slightly toward the softmax-weighted average of all tokens, with inverse temperature $\beta$ tuning how selective the pull is. Turn $\beta$ down (hot attention) and every token listens broadly across the whole circle; turn $\beta$ up (cold attention) and each token listens almost exclusively to its closest neighbors.

At that point the clocks behave as coupled oscillators pulling one another into alignment, a close relative of the Kuramoto model physicists use for flashing fireflies, phase-locking Josephson junctions, and ordering spins in a magnet. Mathematicians (including Borjan Geshkovski, Cyril Letrouit, Yury Polyanskiy, and Philippe Rigollet) have formalized self-attention in this exact language, proving that tokens cluster spontaneously as depth grows.

β = 2.0 depth = 0 clusters: 1
Figure 3. live Tokens as interacting particles on a circle, with layer depth as time. Each dot drifts toward the softmax-weighted average of all dots. Small $\beta$ (hot attention) collapses everyone rapidly into one consensus cluster; large $\beta$ (cold attention) freezes long-lived metastable factions that merge only slowly.

Watch the temperature knob in Figure 3. Start 24 tokens nearly evenly around the circle with a whisper of random jitter and let depth run to 20. At $\beta = 0.5$ (hot), everyone blurs rapidly into a single consensus cluster, erasing every distinction. At $\beta = 2$, the circle splits cleanly into two opposing camps. At $\beta = 9$ (cold), the tokens freeze into roughly four sharp clusters that linger for a long time before eventually merging.

That separation of timescales is where real computation lives. Wait for infinite depth and even cold factions eventually collapse into one point, a phenomenon known in deep learning as oversmoothing. At finite depth, however, high $\beta$ holds distinct concepts apart as long-lived metastable islands, exactly the way a supercooled liquid or a glass holds structural domains long enough to remember its shape.

What the floor remembers: slicing history without infinite loops

One question still hangs over both parts: how much of a construction history can survive inside a finished object, and when does keeping history stop making sense?

In Part 1, we turned unevaluated multiplication into a wooden-tile workshop: a product $r \times c = n$ becomes a rectangle $(r, c)_n$, horizontal glue $+$ joins two equal-height blocks side by side, and a transpose $T$ flips rows and columns, $(r, c)_n^T = (c, r)_n$. Vertical stacking needs no extra symbol, because $(A^T + B^T)^T$ turns both blocks, glues them sideways, and turns the finished slab back upright.

Now lay three strips of height 3 side by side: $A = (3, 1)_3$, $B = (3, 2)_6$, and $C = (3, 3)_9$. Compare two assembly recipes:

$$(A + B) + C \qquad \text{and} \qquad A + (B + C).$$

Look at the finished $3 \times 6$ tiled floor. Every unit square lands at the exact same coordinate; both vertical seams fall in the exact same places. Even inspecting the floor with a microscope cannot tell you which recipe the builder followed. Yet the workshop history was genuinely different: the first builder first created a $3 \times 3$ square of area 9, while the second first created a $3 \times 5$ slab of area 15. Just like the parenthesizations $(2 \cdot 3) \cdot 5$ and $2 \cdot (3 \cdot 5)$ in Part 1, the slicing tree preserves that unseen intermediate state, assigning the two recipes distinct addresses.

There is, however, one subtle trap when you try to count all histories of a given area $n$. If every written move counted as new history, you could flip a single tile over twice, four times, six times ($A^{TT}, A^{TTTT}, \ldots$) and generate infinitely many histories without ever adding a piece. The configurational entropy would blow up immediately.

The fix is as clean as a physical symmetry rule: declare that two consecutive transpositions cancel, $(A^T)^T = A$. Watch what that rule remembers and what it erases in a nested build:

$$(A^T + B)^{TT} = A^T + B.$$

The outer double-flip disappears because turning a finished slab over and right back leaves no physical mark in the world. The inner flip on $A$ survives, because $A$ had to be rotated before the glue met $B$; you can still see its scar in the seam. Because every join strictly increases area and every subassembly carries at most one uncancelled outer flip, every area $n$ suddenly has a finite count of histories $g_{\mathrm{slice}}(n)$, and as we saw in Part 1, that count cleanly separates primes (which build only 1D strips) from composites (which open 2D interiors).

Three regimes, one shop of clocks

Putting both parts side by side collects all three systems into one table. Analytic number theory, quantum factoring, and deep attention models differ by just two physical knobs: whether the clock frequencies share a common beat, and whether the arrows interact.

regimephysical rulewhat the arrows dowhat emerges
Prime clocks (Part 1)uncoupled, incommensurable speeds ($\log p$)wander the dial evenly forever (Weyl equidistribution)scattered branch points of $P(s) = \tfrac14$, exact density $D(\sigma)$, composite quasicrystal diffraction
Shor's modular clocks (Part 2)uncoupled, commensurable finite period $r$lock head-to-tail at multiples of $Q/r$ and cancel elsewheresharp QFT interference peaks that hand $r$ to Euclid's gcd to factor $N$
Transformer attention (Part 2)coupled via softmax at inverse temperature $\beta$pull neighbors toward a weighted mean (Kuramoto-like flow)spontaneous clustering and long-lived metastable concept islands across depth

All three regimes, and my grandfather's wine cellar before them, circle around the same trade-off in statistical physics: remembering a path versus summarizing an outcome.

Ordinary arithmetic, like equilibrium thermodynamics, is built to forget. It collapses twelve assembly trees into the bare integer 30, flattens two distinct tilings into one $3 \times 6$ rectangle, and summarizes trillions of molecular collisions with a single temperature. That compression is why arithmetic and thermodynamics work at all.

When you hold on to the history instead, familiar numbers open up into physical systems. Keep multiplication's binary trees, and the primes stop behaving like a harmonic crystal and act as a glassy bootstrap gas with a Hagedorn wall, composite quasicrystal Bragg peaks, and branch points crossing into Riemann's critical strip. Give the clocks a finite period, and the same turning arrows run a quantum factoring interferometer that still hands its last check to the cellar's greatest common divisor. Wire the clocks together with softmax weights, and tokens synchronize into metastable clusters across transformer depth.

I started this project as a condensed-matter physicist tinkering with a puzzle from number theory, using multiple AI systems alongside my own calculations and code to test every guess against computation. What stuck with me is how far the bench tools of statistical mechanics travel once you carry them next door: partition functions, phase transitions, diffraction, and coupled oscillators showed up under every floor we lifted.

Return to Part 1: A Wine Riddle, Riemann's Line, and the Quasicrystal in the Primes. Full paper: Prime-Leaf Tree Theory. Code and data (v0.3.0): github.com/gbarbalinardo/primeleaf.