Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 35

Factoring and Cryptography

Recommended resources

Welcome to Module 7. In our previous work on Grover's algorithm, we saw how a quantum computer could provide a quadratic speedup for unstructured search problems. We now shift our focus to a different, even more impactful application: integer factorization.

This lesson will introduce the problem that Shor's famous quantum algorithm was designed to solve. You will learn what the integer factorization problem is, why it is considered "hard" for even the most powerful classical supercomputers, and how this very hardness forms the bedrock of the cryptographic systems that protect our digital information. Understanding this problem is the essential first step before we can appreciate the revolutionary power of Shor's algorithm.


1. The Integer Factorization Problem

At its core, the integer factorization problem is straightforward to describe: given a composite number, find the prime numbers that multiply together to produce it.

For a small number, this is a simple exercise. For example, consider the number 21. A moment's thought tells you its prime factors are 3 and 7, since . We can visualize this process using a factor tree.

Prime Factorization of 210 by Factor Tree Method
This factor tree shows how the number 210 can be broken down into its unique prime factors: 2, 3, 5, and 7. The process involves repeatedly finding any two numbers that multiply to the number above, until only prime numbers remain at the ends of the branches.

The key insight is the asymmetry of the task:

  • Multiplying is easy: If I give you two large prime numbers, say p and q, you can use a computer to find their product N = p * q very quickly.
  • Factoring is hard: If I only give you the product N, finding the original p and q is extremely difficult, especially when N is very large.

This "one-way" nature—easy to do, hard to reverse—is the crux of the problem.



2. What Makes Factoring "Hard"?

In computer science, a problem is considered "hard" if the time it takes to solve it grows exponentially with the size of the input. Integer factorization is a classic example of such a problem for classical computers. While multiplying two 300-digit numbers takes less than a second, factoring the resulting 600-digit number could take a classical computer millions of years.

The following video provides an excellent visual explanation of this dramatic difference in computational difficulty, contrasting the "easy" problem of multiplication with the "hard" problem of factorization.

Public Key Cryptography: RSA Encryption

In this clip from "Public Key Cryptography: RSA Encryption" by Art of the Problem, the concepts of "easy" and "hard" problems are explained using the idea of time complexity.

Please watch the section that explains prime factorization as a hard problem. Pay close attention to the graphs that show how computation time explodes for factorization as the numbers get larger, while it remains manageable for multiplication.

As the video shows, the difficulty isn't about finding a clever trick; it's that for large numbers, the only known classical methods essentially boil down to a very time-consuming, trial-and-error process.



3. From a Hard Problem to a Secure Internet: RSA Encryption

This "hard" problem is not just a mathematical curiosity; it is the foundation of modern internet security. Most of the secure data transmitted online—from credit card numbers to private messages—is protected by a system called RSA encryption.

RSA is a public-key cryptosystem. The core idea is that everyone has two keys:

  • A Public Key, which they can share with anyone. This key is used for encryption.
  • A Private Key, which they must keep secret. This key is used for decryption.

This solves a major problem in historical cryptography: how to securely share a secret key in the first place. With public-key systems, you never need to.

The security of RSA relies on a mathematical "trapdoor"—a function that is easy to compute in one direction but hard to reverse without a secret piece of information. As you've probably guessed, that trapdoor is built using the integer factorization problem.

To understand how this works, let's return to the Art of the Problem video.

Public Key Cryptography: RSA Encryption

These segments from the video explain the concept of public-key cryptography and how RSA uses integer factorization as its security backbone.

Watch the following clips in order: First, watch the introduction to public-key cryptography to understand the "open lock" analogy. Next, learn about the trapdoor one-way function, the mathematical concept behind the lock. See how this is implemented by multiplying two huge prime numbers to create the public number n, while keeping the factors secret. Finally, the conclusion explicitly states how RSA's strength relies on the hardness of factorization.

In essence, the RSA algorithm works like this:

  1. You generate two very large, secret prime numbers, p and q.
  2. You multiply them to get a huge public number, n = p * q. This n becomes part of your public key.
  3. Your private key is derived from the original secret factors, p and q.
  4. Anyone can use your public key (containing n) to encrypt a message and send it to you.
  5. But only you, because you know the secret factors p and q, can derive the private key needed to decrypt the message.

An attacker who intercepts the message would know the public number n, but to break the encryption, they would need to find its prime factors p and q. And as we've established, that is a "hard" problem.

If you'd like to read a concise written summary of this process, the following article is a great resource.

What Is RSA Encryption? An Overview Of The RSA Algorithm

This article from Komodo Platform clearly explains how RSA uses prime numbers and the integer factorization problem.

Focus on the sections "How Does RSA Encryption Work?" and "Prime Numbers And The Integer Factorization Problem". These sections reinforce the connection between the difficulty of factoring and the security of the cryptosystem.



4. The Quantum Threat: "Store Now, Decrypt Later"

For over 40 years, the hardness of integer factorization has been a reliable assumption. However, the development of quantum computers changes this equation entirely. Shor's algorithm, which we will study in this module, can solve the integer factorization problem in a time that grows only polynomially with the size of the input, not exponentially. This means a sufficiently powerful quantum computer could factor large numbers that are classically infeasible to break.

This isn't just a future problem. It has implications today due to a strategy known as "Store Now, Decrypt Later" (SNDL).

The video below explains this pressing security threat.

What makes quantum computers SO powerful?

This opening segment from a Veritasium video vividly illustrates why the race to build a quantum computer has such high stakes for global security.

Watch the first part of the video on the SNDL threat. It explains how encrypted data is being harvested today with the expectation that it can be broken by quantum computers in the future.

This is precisely why Shor's algorithm is so famous. It doesn't just solve an abstract math problem; it provides a tool that could potentially break the encryption that underpins much of our global digital infrastructure.



Conclusion

In this lesson, we've established the critical context for Shor's algorithm. You now understand the problem it was designed to solve and why the solution is so significant.

Key Takeaways:

  • The integer factorization problem is the task of finding the prime factors of a large composite number.
  • For classical computers, this is a "hard" problem: the time required to solve it grows exponentially with the size of the number.
  • RSA encryption, a fundamental protocol for securing internet communications, derives its security directly from the difficulty of this problem.
  • Breaking RSA encryption is computationally equivalent to solving the integer factorization problem.
  • A quantum algorithm that can efficiently factor large numbers poses a direct threat to modern cryptography, motivating the development of new, "quantum-resistant" security standards.

Preview of the Next Lesson:
Now that we have a firm grasp of the problem, our next step is to explore the solution. We will begin to unpack Shor's algorithm by examining its high-level structure and the relationship between factorization and another problem: period-finding. This will lead us to the main quantum component of the algorithm, the Quantum Fourier Transform (QFT).