Semiprime Factorization with Discrete Diffusion and Beam Search: Scaling Laws

Brendan O Donoghue, Nenad Tomasev, Volodymyr Mnih, Timothy Nguyen, Dalin Guo, Arun Nair, Kenneth Yang, Alexandre Frechette, Jasper Xian, Jean Tarbouriech, Pavel Tyletski, Ingrid von Glehn, Johannes Bausch, Demis Hassabis, Raia HadsellarXiv 2026

TL;DR

Researchers at Google DeepMind have demonstrated that transformer-based discrete diffusion models, paired with guided beam search, can learn to factorize semiprime integers up to 68 bits. While this sets a new state-of-the-art for machine learning-based factorization, the study reveals that the approach scales exponentially with bit length, confirming that modern RSA cryptography remains secure against current AI methods.

What Problem Does This Paper Address?

Integer factorization—finding the prime factors $p$ and $q$ of a large number $n$—is a cornerstone of modern cryptography. The security of the RSA cryptosystem rests on the assumption that while multiplying two large primes is easy, reversing the process is computationally intractable.

Classical algorithms like the General Number Field Sieve (GNFS) are highly optimized but rely on deep number-theoretic insights. Previous attempts to use machine learning for factorization have struggled because the problem is "globally coupled" and "chaotic": a single bit flip in the input $n$ can lead to a completely different set of factors. This paper investigates whether generative AI, specifically discrete diffusion models, can learn the underlying "prior" of factorization directly from data without being programmed with domain-specific math.

Methods

The authors frame factorization as a conditional sequence generation task using a bidirectional transformer. Their pipeline involves several novel components:

  • Discrete Denoising Diffusion: Instead of adding Gaussian noise, the model is trained to "inpaint" masked bits.
  • Contiguous Blockwise Masking: Rather than masking random bits, the authors mask contiguous spans. This forces the transformer to resolve long-range carry propagation and global multiplicative constraints rather than just interpolating local bit patterns.
  • Self-Conditioning: The model passes its soft predictions (logits) from the previous step back into itself, allowing it to refine its "beliefs" over multiple iterations.
  • Guided Beam Search with Oracle Self-Conditioning: During inference, the model uses a two-level search. An outer loop commits to factor bits from Most Significant Bit (MSB) to Least Significant Bit (LSB). An inner loop uses "oracle self-conditioning," where bits already decided by the search are clamped to their exact values, preventing the model's internal priors from conflicting with the search path.
The oracle self-conditioning iteration. Decided bits are clamped to one-hot embeddings while masked positions receive soft logits.
  • Arithmetic Pruning: The search tree is pruned in real-time by checking if a partial bit assignment could even mathematically result in the target $n$.
Beam search expansion and feasibility pruning. Infeasible branches are removed based on arithmetic constraints.

Datasets

The models were trained on synthetically generated semiprimes.

  • Training Data: Generated on-the-fly by sampling primes $p, q < 2^k$ and calculating $n = p \cdot q$.
  • Evaluation: Fixed held-out test sets of 1,024 to 100,000 semiprimes were used to ensure the model wasn't simply memorizing specific factor pairs.
  • Scale: Experiments ranged from 30-bit ($k=15$) to 68-bit ($k=34$) integers.

Key Insights and Ideas

  • The "Local Arithmetic" Floor: The authors identified a theoretical validation loss floor (NLL $\approx 0.262$). Models above this floor have only learned "local" tricks, like the fact that primes are odd or how local carries work. Genuine "global" factorization only emerges once the model breaks through this threshold.
  • Learned Brute Force: Unlike language models that show smooth power-law scaling and "emergent" reasoning, factorization models behave like a "learned brute force search." They require seeing a significant fraction of the prime factor pool to generalize.
  • Scaling is Brutal: The most critical finding is that achieving fixed accuracy requires compute and data that scale exponentially with the bit length of the integer. This is in stark contrast to natural language, where models generalize across lengths much more efficiently.
  • Generative Priors: The diffusion model acts as a generative prior that identifies "promising" candidates. Even if the model isn't 100% accurate, getting the first half of the MSBs correct allows classical lattice-based methods (like Coppersmith’s algorithm) to finish the job in polynomial time.

Key Results

  • New ML State-of-the-Art: Successfully factored 68-bit integers using a 12B-parameter model, surpassing the previous 56-bit limit for learning-based methods.
  • MSB Accuracy: On 68-bit numbers, the model showed a 3x lift over uniform random bit-guessing for identifying the leading bits of factors.
  • Inference Scaling: For a 325M parameter model at $k=15$, increasing the number of denoising steps from 1,024 to 16,384 improved accuracy from 64.55% to 87.60%.
  • Security Confirmation: The empirical scaling laws project that factoring a 2048-bit RSA key would require more compute than is physically plausible, reaffirming that AI does not currently pose a threat to standard encryption.

Limitations and Future Work

  • Efficiency Gap: The proposed method is significantly less computationally efficient than specialized classical algorithms like GNFS.
  • Generalization Hurdles: The model struggles to generalize from $k$-bit problems to $k+1$-bit problems without a massive increase in training data.
  • Future Directions: The authors suggest exploring whether ML can be better integrated into the "sieving" phases of classical algorithms or if different architectures can better capture the "chaotic" global dependencies of multiplication.

Summary updated

Abstract

We demonstrate that transformer architectures trained with discrete denoising diffusion and decoded via guided test-time beam search can learn to recover the prime factors of semiprime integers directly from data. Our approach establishes a new frontier for learning-based semiprime factorization, successfully factoring 68-bit integers-a substantial advance over the prior 56-bit state of the art. While computationally less efficient than classical factoring algorithms, our model requires no domain-specific number-theoretic priors and learns purely from training examples. In practice, the diffusion model acts as a generative prior, identifying promising factor candidates where exact verification or lattice-based post-processing can complete the factorization. Furthermore, we derive empirical scaling laws relating approximation quality to training data volume, model size, and test-time computation. In contrast to language, problem size is the key driver of scaling behavior. Achieving a fixed accuracy on a held-out test set requires compute that scales exponentially with bit length. Consequently, our findings pose no threat to security, as the projected compute cost required to factorize cryptographically relevant integers remains prohibitive.
BibTeX
@misc{donoghue2026semiprime,
  author = {Brendan O Donoghue and Nenad Tomasev and Volodymyr Mnih and Timothy Nguyen and Dalin Guo and Arun Nair and Kenneth Yang and Alexandre Frechette and Jasper Xian and Jean Tarbouriech and Pavel Tyletski and Ingrid von Glehn and Johannes Bausch and Demis Hassabis and Raia Hadsell},
  title = {{Semiprime Factorization with Discrete Diffusion and Beam Search: Scaling Laws}},
  year = {2026},
  eprint = {2611.10202},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.10202},
}
Figure