
Hi there, argmin readers. Today’s post is about my favorite computational complexity class and how it relates to cryptography. Like my previous posts on complexity theory, it’s pretty technical. I again tried to make it as accessible, but let me know in the comments which parts are confusing.
Thanks to some irresponsible rumor-mongering by another blogger, whispers are making the rounds that RSA encryption has been broken. I didn’t realize how seriously people were taking these rumors, so I playfully tweeted over the weekend about why I wouldn’t be surprised if this were true. But the Twitterati took my shitpost too seriously, and I was inundated with bots asking grok to allay their fears. My bad. But there was a kernel of fun truth to my post, and let me make amends by explaining why factoring numbers is one of the most perplexing puzzles in complexity theory.
The classic problem in complexity theory is P vs. NP. There are very technical definitions of what P and NP are, and you should go elsewhere for those technicalities. For our purposes, P is the set of problems you can solve efficiently on a computer. NP is the set of problems where if someone gives you the answer, you can check if the answer is right on the computer. The central question of complexity theory is: “Does P=NP?” That is, do all of the problems with simple checks admit simple solutions?
Answering this question is absurdly hard. Fifty years of evidence suggests they are not equal. No matter how hard people try, plenty of problems in NP don’t seem to admit efficient algorithms. Still, no one knows for sure, and the big AI companies are all spending millions to figure it out. Let me not dwell on this question today, as the security of public-key encryption does not rest on this daunting challenge. Indeed, that security depends on a much simpler complexity question with almost no evidence to the contrary.
Both P and NP are technically classes of decision problems. This just means they are problems where the goal is to write a computer program to answer a yes/no question. “Is there a path through this maze?” “Can I fit all of my souvenirs in my suitcase without going over the weight limit?” “Does this equation have a solution?” “Is this logical formula true?” “Is this number prime?”
Complexity theorists spend most of their time worrying about these yes/no decision problems. It might feel like restricting attention to decision problems is too narrow, but you can transform any efficient algorithm into a decision problem with some logical contortions. For example, you can turn multiplying two integers into a decision problem by giving a potential answer: “Does a × b = c?” You can solve this by computing a times b and then seeing if it equals c.
So now, with slightly more technical precision, the class P is the set of decision questions we can answer by running an efficient computer algorithm. “Does this list have duplicates?” is a simple example of such a problem. You can just compare all pairs (in time quadratic in the list length), or build a clever hash table and look for duplicates (roughly linear time in the list length). Other problems from the list above that are in P are determining if there’s a path through a maze and solving a system of equations. Perhaps less intuitively, “Is this number prime?” is in P, proved only in 2002 by Agrawal, Kayal, and Saxena.
NP is the class of decision problems where we might not have an algorithm, but we have an efficient way to check if the answer is yes. All of the problems in P are in here. For example, if someone gives you a path through a maze, you can easily check if it works. But those other questions I asked about logical formulas or suitcase packing are also in here, even though we don’t (yet) have efficient algorithms to solve them. These are examples of questions in NP where we don’t know whether they are in P.
Now let me add a third complexity class to the mix: coNP is the class of decision problems where answering no is easy to verify. This is the “complement of NP” and is weirdly very different than NP. “Does this logical formula have a solution?” has an easy proof for yes: the solution itself. But how would you come up with a certificate to convince me the answer is no? You’d have to prove to me that no solution exists. I have no idea how to prove that.
Here’s a fun problem that’s obviously in coNP but not in NP: “Does this logical formula have a unique solution?” Proving no is easy because you just have to give me two solutions.
But proving yes is hard because you’d have to somehow rule out all other assignments.
We’re pretty sure that coNP and NP are different, but again, we have no idea.
Problems that are in coNP and NP, where it’s easy to answer both yes and no, tend to be easy. One of the more plausible conjectures in complexity theory is that P is the set of decision problems that are in both NP and coNP. In compact form, the conjecture is “P = NP ∩ coNP.” Once again, we have no idea if this conjecture is true. However, in mathematical optimization, one of our most powerful paths to efficient algorithms is sandwiching problems into NP ∩ coNP.
Here’s a high-level explanation of the technique. First, there’s a universal way to turn an optimization problem into a decision problem. You change “Find the minimum value of f” to “Does there exist some point x where f(x) is less than or equal to some threshold?” “What is the shortest path to the airport” becomes “Does there exist a route from my house to the airport that’s less than 30 miles?” If you have an efficient way to solve the optimization problem, you can use it to answer the decision question. Conversely, if you have an algorithm for the decision version, you can turn it into an efficient algorithm for the optimization problem through binary search.1
All optimization problems that you could hope to solve are in NP because checking whether a point is feasible and has an objective value below a threshold is usually easy. Proving there is no solution less than a threshold is generally much harder, but we use various forms of duality to construct optimization problems that provide lower bounds. If an optimization problem has strong duality, then it is in NP ∩ coNP, and this usually means local search heuristics can find the optimal solution. Mathematical optimizers have curated a huge toolkit to build dual problems, and duality was a central tool in efficient algorithm design for decades before NP and coNP were even conceived.
Up until last week, there were a few edge-case optimization problems from game theory that were proven to be in NP ∩ coNP, but for which we didn’t have efficient algorithms. But in one of the latest math slop dumps from OpenAI, a result shows these problems are in P, as they should be.
Here’s where we finally get to the bizarre intersection of complexity theory and cryptography. I now know only three problems in NP ∩ coNP without efficient algorithms: factoring integers, discrete logarithms, and string unknotting.2
Let me only focus on the first one, factoring. We all learn in elementary school that any integer can be written as a product of its prime factors. The factoring decision problem is “Does there exist a prime factor of the integer N that is less than k?” To verify yes, you just need a candidate factor f. You can check that it’s less than k, then divide N by f and make sure there’s no remainder. To verify there is no factor less than k, someone can present the true prime factorization of N. In this case, you can check that all of the factors are greater than k and prime, and that multiplying them together gives you N. And just like in optimization, you can turn an efficient algorithm for this decision problem into a factorization algorithm by applying binary search.3
However, unlike in optimization, membership in NP ∩ coNP alone doesn’t give us enough structure to find prime factors. We think prime factorization is really hard! And we put a lot of trust in its hardness. Many popular encryption systems like RSA use public keys that are products of two prime factors. If you could factor them, you could find the private key. And that’s why people have been freaking out about these blog rumors about AI and cryptography.4
There is no good reason that factoring and discrete logarithm are hard. They are aberrantly difficult problems in the complexity theory zoo. I would not be at all surprised if someone came up with a clever hack that made factoring easy. But it could also be that some natural problems are hard to solve for no good reason whatsoever. We’ll have to stay tuned to find out.
Establish upper and lower bounds for the optimal value of f, ask whether the optimum is less than the midpoint between the bounds, and then use the answer to update the search bounds.
Let me clarify for the complexity theorists: there are other problems in NP ∩ coNP that can be reduced to factoring or discrete logarithms. I’m leaving these out. And I’m not even sure the knot theory problem is true, as the proof is over one hundred pages. I’m taking the author at his word here. If someone has some spare credits to run it through GPT Astra to get a lean verification, be my guest. Update: I dug in a bit, and there’s a much simpler proof since the generalized Riemann Hypothesis is true, and the complementary question is also fairly straightforward. The knot theory problem intrigues me. I wonder if you can use knots for cryptography. I also wonder if this means there’s a straightforward unknotting algorithm.
Set the initial bounds to be [2, √N] and then in log(N) steps you will find a factor.
Yes, it’s true that we have efficient algorithms for factoring and discrete logarithm on quantum computers, but quantum computers don’t exist.

This is not reassuring, honestly. Selling all my cryptokitties
It's interesting that knowing a particular prime isn't a factor tells us almost nothing about where to look next. I wonder if getting prime factorisation into P would involve some clever relaxation that makes local information useful in finding the global solution, much like in convex optimisation.