"Poulet" means chicken in French. In computational number theory, a Poulet number is a liar - a composite integer that passes Fermat's primality test and masquerades as prime until you dig into its factors. A composite number that survives Fermat's test is the closest thing cryptography has to a wolf in sheep's clothing, and the gap between "probably prime" and "definitely prime" is where real-world security incidents quietly unfold.

article

I first hit a Poulet number the hard way. In production environments, we found a legacy service that checked RSA candidate primes with a single base-2 Fermat test. Every key it generated looked valid. Every key it generated was, for a subset of cases, mathematically rotten. The service never failed in staging. It just issued keys that a patient attacker could factor faster than a coffee break takes.

You don't need to be a number theorist to feel this problem. The same pattern shows up in CI pipelines, certificate issuance, and bootstrapped microservices: a check that passes most of the time, built on a foundation that nobody verified.

What Is a Poulet Number? The Math Behind the Name

Fermat's Little Theorem states that if p is prime, then for any integer a not divisible by p, a^(p-1) โ‰ก 1 (mod p). The theorem is elegant, cheap to compute, and 100% reliable for actual primes. The trap is the converse - it doesn't hold.

A Poulet number, also called a Fermat pseudoprime to base 2, is a composite number n for which 2^(n-1) โ‰ก 1 (mod n). The smallest Poulet number is 341, which factors as 11 ร— 31. Yet 2^340 leaves a remainder of exactly 1 when divided by 341. Run that through a naive isPrime implementation and you'll get a false positive every time.

Paul Poulet, a Belgian mathematician, published one of the first systematic tables of these pseudoprimes in 1926, which is why the sequence carries his name. The sequence is catalogued as OEIS A001567, and it includes luminaries you might recognize: 341, 561, 645, 1105, 1387, 1729, 1905, 2047. The number 1729, famous as the Hardy-Ramanujan taxi-cab number, is also a Poulet number - mathematical trivia with real security consequences.

Why Fermat's Test Lets Composite Numbers Slip Through

A single base-2 Fermat test is fast. Modular exponentiation with bit-shifting takes microseconds for 2048-bit numbers. That speed tempts engineers into using it as the sole gate for "good enough" primality checks, especially in embedded devices and prototype tooling.

Poulet numbers are rare relative to primes. So a base-2 false positive feels like a one-in-a-million event. That intuition breaks down when you widen the test. Some composite numbers pass Fermat's test for every base coprime to the number itself - those are Carmichael numbers, first described by Robert Carmichael in 1910. The smallest is 561. Carmichael numbers are pseudoprimes to every base, and Alford, Granville, and Pomerance proved in 1994 that infinitely many exist.

Your test suite can rotate bases all day and never catch a Carmichael number with pure Fermat-style logic. That's not a flaw in the arithmetic. It's a flaw in the mental model that says "passes a few checks" equals "true. "

Poulet Numbers in the Wild: Cryptographic Failure Modes

RSA key generation depends on finding two large primes. If one of those "primes" is actually a Poulet number, the entire keypair is compromised. The public exponent is effectively constructed from known factors, and an attacker can walk straight through the back door.

This isn't a theoretical corner of the threat model. In 2008, the infamous Debian OpenSSL incident (CVE-2008-0166) produced predictable keys because of a weak random number generator - entropy failures, not primality failures, but the outcome was the same: keys that looked cryptographically sound and behaved like cardboard. A Poulet number slipping past a lazy primality check produces a similar illusion: the key structure looks valid, the certificate chains, the TLS handshake completes, and the private key is still worthless.

Hardware wallets and IoT devices are the most exposed. Flash memory constraints push developers toward minimal implementations. And a single-base Fermat test is the smallest thing that "works" in demos. We found in our own audits that the failure mode is silent right up until someone runs a factor test or hits a dataset like factorable.net, a study of weak RSA keys that documented millions of real-world moduli with shared factors.

The Chicken-and-Egg Problem in Bootstrapping Secure Systems

Poulet numbers and the chicken-and-egg problem share a core mechanic: both are about getting fooled by something that looks complete from the outside. In systems engineering, the chicken-and-egg problem shows up whenever a system needs a seed to bootstrap itself. Certificate authorities are the canonical case - trust starts somewhere, and that somewhere is a root certificate you either ship or pin.

Think about TOFU (trust on first use), the model used by SSH. The first time you connect to a host, you blindly accept its host key. That's not a mathematical pseudoprime; it's a bootstrapping lie that becomes truth through convention. If an attacker intercepts that first connection, your trust store just ingested a "Poulet" - something that passes the acceptance test but isn't what it claims to be.

The software engineering version is more mundane. A new GraphQL federation service depends on a schema registry that needs the service to be live. The service can't go live without the registry, and the registry needs at least one service to populate its schema. You end up hand-seeding data, pinning a host, or shipping a static bootstrap file - each choice a calculated act of trust-in-the-absence-of-evidence.

How Modern Libraries Handle Primality: Miller-Rabin and Witnesses

The standard answer to Poulet's trickery is the Miller-Rabin test, a probabilistic primality test that refuses to be fooled by base-2 charm. Miller-Rabin works by finding at least one "witness" - a base revealing that a candidate is composite. For any odd composite number, at least 3/4 of the bases are witnesses. Run enough rounds and the false-positive probability collapses to (1/4)^k.

Practical libraries bake this in. Go's math/big.ProbablyPrime runs a Baillie-PSW test combined with Miller-Rabin rounds; for inputs under 2^64, the result is effectively deterministic. OpenSSL's key-generation path uses multiple Miller-Rabin rounds where the count scales with key size. Python's sympy.isprime similarly layers a deterministic base set with a BPSW-style check for larger inputs.

The determinism you can actually rely on is documented: for n

Designing an API That Says "Prime" - Without Lying

A function named isPrime() that returns true for 341 is a contract violation. The failure isn't in the mathematics - it's in the API promise. Naming a probabilistic test as if it were a deterministic predicate hands that lie to every downstream consumer.

Go gets this right with ProbablyPrime. The name carries the uncertainty in the signature. When we designed a primality-checking service for a certificate toolchain, we matched that honesty: the API returned a PrimalityResult with a verdict, a confidence bound, and the number of rounds executed. Callers who wanted a hard guarantee could request the deterministic path for 64-bit inputs; callers handling 4096-bit candidates got a documented probability bound instead of a silent boolean.

That pattern transfers to any system that emits a conclusion from probabilistic evidence. Fuzzers report bug density, not bug absence. Coverage tools report line execution, not correctness. The engineering discipline is the same: expose the uncertainty, document the bound, and force the caller to decide what level of risk their use case tolerates.

Poulet-Style False Confidence in Your Build Pipeline

Your build pipeline has its own Poulet numbers - tests that pass while the system they protect is broken. A green CI run on a single browser version, a smoke test that never exercises the error path, a unit suite that covers the happy flow and nothing else - each one is a base-2 Fermat test for "works. "

Property-based testing is the Miller-Rabin of the testing world. Instead of hand-picking examples, tools like Hypothesis and QuickCheck generate adversarial inputs, exploring a space far larger than any human-written test suite. The analogy holds at the practical level too: property tests increase confidence; they don't deliver proof. A green property-based run across millions of generated cases still isn't a formal verification of your core logic.

The honest way to treat a "green" pipeline is the way Go treats ProbablyPrime: as a claim of confidence with stated bounds, not a certificate of truth. When we moved our release gates to include mutation testing - deliberately injecting faults to see which tests catch them - we stopped calling anything "done" based on coverage percentage alone.

Verifying Pseudoprimes in Your Own Codebases

Start by auditing the primality checks you already ship. Grep for custom isPrime implementations, especially in key-generation paths. Replace any single-base Fermat test with a tested library path, even if that costs a few extra microseconds.

Add a regression suite with 341, 561, 1105, and 1729 in it. These numbers are cheap to test and they'll catch a naive implementation on the first run. If your platform checks primality at all, the spec is straightforward: RFC 8017, the RSA PKCS#1 v2.2 specification, explicitly requires that prime generation be "with overwhelming probability" prime - a probabilistic allowance, not a free pass.

Beyond primality, question every "pass" your systems trust without scrutiny. The certificate that sailed through validation on a single CA, the dependency that has never been pinned, the test that has never seen a fuzzer - each is a candidate Pourlet waiting to flip your confidence on its head. Run the equivalent of Miller-Rabin on your own processes: introduce chaos, inject failures, break the happy path on purpose. Read the math/big source documentation, and then rewrite the tests that pretend certainty where your code only has probability.

FAQ: Poulet Numbers and Primality Testing in Production

What exactly is a Poulet number in software engineering terms?
A Poulet number is a composite integer that passes Fermat's primality test for base 2. In practice, it's a number your isPrime() function might incorrectly accept if you use a single-base Fermat test.

Is the Miller-Rabin test deterministic for all integers?
No. Miller-Rabin is probabilistic for full integers, but it becomes deterministic for inputs below certain bounds. Below 3,317,044,064,679,887,385,961,981, testing the first 12 prime bases is provably sufficient.

Can a Carmichael number break my RSA key generation?
Yes, if your primality test is Fermat-based. Carmichael numbers pass Fermat's test for every coprime base, so rotating bases doesn't help. Use Miller-Rabin rounds or a Baillie-PSW implementation from a maintained library.

How many Miller-Rabin rounds should I run for a 2048-bit RSA key?
The OpenSSL defaults are a good baseline; the round count scales with key size. As a rule, running at least 40+ rounds for 2048-bit candidates puts the false-positive probability well below 2^-80, which is comfortably beyond practical attack range.

What's the fastest way to test my system against these edge cases?
Add a test that runs primality checks on known pseudoprimes like 341, 561, 1105, and 1729. If your implementation returns true for any of them, you have a bug. Then layer in property-based testing with generated random numbers and a trusted reference library as the oracle.

What do you think?

Have you ever found a false "prime" in a production codebase - or a build that passed while the system underneath was quietly broken?

Should API names like isPrime() be forced by convention to reflect their probabilistic nature, or is that a documentation problem rather than a naming problem?

Where else in your stack does the Poulet pattern lurk - a check that looks like proof but is really just confidence with a low bound?

Want to harden your crypto, audit your key generation, or rebuild that shaky validation layer? Talk to us about a cryptographic or systems engineering review - we'll bring the witnesses.

Need a Custom App Built?

Let's discuss your project and bring your ideas to life.

Contact Me Today โ†’

Back to Online Trends