TL;DR
Integer factorization asks for the prime factors of a whole number: given , find primes whose product is . Multiplying a few primes together is quick. Running the process backwards, from a large product to its primes, has no known fast method, and nobody has proven that none exists. The RSA scheme for digital signatures and public-key encryption relies on that gap.
Where you'll see it: in any public-key system where the public number is built from two secret primes, and in the background of every discussion of why some computations are considered hard.
This lesson explains a mathematical problem and why it is believed to be hard. It is not advice about key sizes or about using cryptographic software.
Intuition
Multiplying is easy, splitting takes a search
Take two primes, 53 and 61. Multiplying them takes a minute by hand and gives 3233. Now reverse the question. Someone gives you 3233 and asks which two whole numbers multiply to make it. There is no formula to read off the answer. You have to search: test small divisors until one divides evenly. For 3233 that search is short. The question this lesson answers is what happens to the search when the number has 100 digits instead of four.
flowchart LR A["53 and 61"] -->|"multiply: quick"| B["3233"] B -->|"factor: a search"| A
Why primes are the target
Every whole number above 1 is a product of primes in exactly one way, apart from the order of the factors. Primes are the irreducible pieces, so factoring means finding them. Once you have the primes of , you know every divisor of . A number with exactly two prime factors, like 3233, is the case that matters most for cryptography.
The asymmetry is the point
The defender builds a public number by multiplying two secret primes. Multiplying is cheap for the defender. The attacker has to undo the multiplication to recover the secret, and that must be expensive. This is the same shape as a one-way function: the forward direction is easy, the reverse is hard, and the security is the gap between the two costs.
Measure the cost in digits
A method's cost should be measured against the length of its input, which is the number of digits, not the size of the value. Adding one digit to makes the input one symbol longer, but for the search it multiplies the work by about 3.16 (the square root of 10). Doubling the number of digits squares the work. That kind of growth is what big-O analysis is built to describe.
The math
Definition
Given an integer , find primes , repetition allowed, with . The product on the right is the product of all the primes in the list, and is how many there are. By the fundamental theorem of arithmetic the list is unique up to order, so the answer is well defined. A weaker version asks for one nontrivial divisor , meaning and , where means for some whole number . Finding one such splits the problem in two, and applying the same search to each piece recovers the full list.
Trial division needs only the square root
Claim: if is not prime, it has a divisor with .
Proof: write with . Then , so . The smaller factor is always at most the square root.
Trial division uses this claim. Test up to , and stop at the first that divides . Testing a composite is wasteful but harmless, since its prime factors would already have been caught. The worst-case cost is therefore about divisions.
A number with digits satisfies , so
Trial division takes at most about divisions for a -digit number. The input has symbols, but the work is ten raised to a power proportional to .
- worst-case trial divisions
Better methods
Trial division is the simplest method, and several faster ones exist. Each one exploits a different structure.
Fermat's method. Write . Start at and check whether is a perfect square . If it is, and are factors. If with and close together, the value is reached within a few steps.
Pollard's rho. Finds a prime factor in roughly steps. Its cost depends on the smallest prime factor, not on the size of , so it is fast when has a small factor.
The quadratic sieve and the number field sieve. These are the fastest known general methods for large numbers with no small factors. Their running time is subexponential:
where is the exponential function, is the natural logarithm, and is a constant (about 1.9 for the number field sieve). In terms of the digit count , this grows faster than any fixed power of but slower than any fixed base raised to . It is far better than trial division, and still far too slow to factor a random well-chosen number of several hundred digits.
No classical algorithm is known to factor in time that is a polynomial in . This is an open question, not a theorem.
Quantum computers
In 1994 Peter Shor gave an algorithm that factors in time polynomial in , provided it runs on a sufficiently large quantum computer. Current machines are far too small for that. The possibility is the reason cryptographers are developing post-quantum schemes whose security does not rest on factoring.
Worked examples
The square root of 91 is about 9.5, so test divisors up to 9.
- Divide 91 by 2. The remainder is 1, so no.
- Divide 91 by 3. The digit sum is , which is not a multiple of 3, so no.
- Divide 91 by 5. The last digit is 1, so no.
- Divide 91 by 7. , so yes.
Interpretation: 7 and 13 are both prime, so is the full factorization. Four tests were enough.
The square root of 3233 is about 56.9, since and . Only primes need testing up to 56, because a composite divisor always has a prime factor that was already tested. Those primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 and 53, which is 16 primes.
- Divide 3233 by each of the first 15 primes. None leaves remainder 0.
- Divide by the 16th prime, 53. The quotient is 61, so .
- Check the product: .
Interpretation: 53 and 61 are both prime, so they are the factorization. The search took 16 divisions. For a 100-digit number the same method would need about divisions, because the square root of is .
Use Fermat's method on the same , starting at .
- Compute .
- Since is a perfect square, take .
- Then .
Interpretation: one step was enough. The reason is that 53 and 61 are close: their average, 57, is already the first candidate. Two primes chosen independently at random from a large range are almost never this close, but a key generator that picks primes carelessly can produce exactly this pattern, and then the public number is easy to split.
Public-key systems use numbers with hundreds of digits. Consider trial division on three sizes, assuming a machine that tests a billion divisors per second.
- A 30-digit number: divisions. At per second that is seconds, or about 12 days.
- A 60-digit number: divisions, which takes seconds. A year is about seconds, so this is about years.
- A 617-digit number, the size of a 2048-bit RSA modulus: up to divisions, roughly .
Interpretation: adding 30 digits multiplies the time by . Trial division is hopeless at 60 digits. The better methods above reach much larger sizes, which is why the sizes used in practice are chosen with the best known algorithms in mind, not with trial division in mind.
Tradeoffs and failure modes
Factoring's difficulty is an assumption supported by decades of failed attempts to find a fast method. It is not a proof. The practical cost depends on the size of the number, the structure of its factors, and the algorithm used, and all three change over time.
| Situation | Problem | Better choice |
|---|---|---|
| The number is small, below about | Trial division finishes in seconds | Just divide |
| The number has a small prime factor | Trial division finds it, but the rest of the search is still hard | Strip small primes first, then try Pollard's rho |
| The two primes are close together | Fermat's method splits the number in a few steps | Choose primes that are far apart and independently random |
| Large product of two big primes, classical computer | Best known methods are subexponential but still very long | Use the modulus size that current cryptographic guidance recommends |
| A large quantum computer exists | Shor's algorithm runs in polynomial time | Post-quantum schemes |
Some practical points:
- Hardness is conjectural. Factoring is not known to be NP-complete, and no proof of its hardness exists. Its security rests on the absence of a known fast method.
- Prime choice matters as much as size. A large modulus built from badly chosen primes can be split by Fermat's method or by a small-factor search.
- A record is a data point, not a threshold. A record factorization shows what a large computation achieved on one number. It does not measure the risk to a particular key, which depends on the algorithm and the computing power available.
- Discrete logarithms are an alternative. The discrete logarithm problem is a different hard problem that underlies Diffie–Hellman key exchange and some signature schemes. It does not reduce to factoring, and Shor's algorithm also breaks it on a large quantum computer.
History
Trial division is as old as the idea of primes. Fermat described his factoring method in letters in the 1600s, around the time of his work on number theory. In the Disquisitiones Arithmeticae (1801), Gauss treated factoring as an important and difficult problem and discussed methods for it.
Factoring became a practical research field in the 1970s. John Pollard published his rho method in 1975. The quadratic sieve appeared in the early 1980s, and the number field sieve in the early 1990s became the fastest known general method.
In 1978 Rivest, Shamir and Adleman published the RSA scheme. It made factoring the basis of public-key encryption and signatures, and it turned a classical question into a security assumption. In 1994 Shor showed that a quantum computer could factor in polynomial time. In 2020 a 250-digit RSA challenge number was factored after a large distributed computation, a record that shows how far the best methods have come.
The problem caught on because decades of attacks failed to find a polynomial-time method, and each improvement needed deeper mathematics rather than a simple shortcut. That record of resistance is why it became a standard assumption.
Recap
Every whole number is a product of primes in exactly one way, so factoring means finding those primes. Multiplying is quick. Trial division needs about steps, which is exponential in the digit count. Better methods help in special cases (Fermat for close primes, Pollard's rho for small factors) and in general (the number field sieve, subexponential but still very slow for well-chosen large numbers). The gap between multiplying and factoring is the basis of Public-Key Cryptography, and the same kind of asymmetry appears in the One-Way Function and the Discrete Logarithm Problem.
Check yourself
QuestionWhy does trial division only need to check divisors up to the square root of n?Show answer
Suppose has a divisor with , and write . Then is also a divisor in that range. If both and were larger than , their product would be larger than , which is impossible. So at least one of them is at most , and the search can stop there.
QuestionA number has 40 digits. Roughly how many divisions does worst-case trial division need?Show answer
Since , we get . Worst-case trial division needs about divisions, which is 100 quintillion.
QuestionFermat's method splits in one step. What property of the two primes makes this possible, and why should an RSA key avoid it?Show answer
The primes are close together. Their average, 57, is the first square-root candidate , so is a perfect square right away. An RSA key should avoid this, because an attacker who can see that the primes are close can factor the public modulus quickly, however large it is.
QuestionSomeone says: a 250-digit number was factored in 2020, so a 617-digit RSA modulus is safe forever. What is wrong with this reasoning?Show answer
Two things. A factoring record shows what one large computation achieved on one number, and it does not measure the risk to a particular key, which depends on the algorithm and the computing power available. And "forever" ignores Shor's algorithm: a sufficiently large quantum computer would factor a 617-digit number in polynomial time, so the long-term risk is a different question from today's record.
Sources
- Integer factorization (Wikipedia): https://en.wikipedia.org/wiki/Integer_factorization
- Trial division (Wikipedia): https://en.wikipedia.org/wiki/Trial_division
- General number field sieve (Wikipedia): https://en.wikipedia.org/wiki/General_number_field_sieve
- Shor's algorithm (Wikipedia): https://en.wikipedia.org/wiki/Shor%27s_algorithm
- Rivest, Shamir and Adleman, A Method for Obtaining Digital Signatures and Public-Key Cryptosystems (1978): https://doi.org/10.1145/359340.359342
- Peter Shor, Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer (1994): https://arxiv.org/abs/quant-ph/9508027