1. Home
  2. Explore
  3. Computer Science
  4. RSA Public-Key Cryptography

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

RSA Public-Key Cryptography

Speaker 1Speaker 2

RSA Public-Key Cryptography

9:31
0:00-9:31
  1. Simon

    Today we’re looking at RSA, a beautiful and important application of number theory in computer science. RSA is a public-key cryptosystem: a receiver publishes information that anyone can use to send them an encrypted message, but the receiver keeps a separate secret that lets them decrypt it.

  2. Maria

    So a sender doesn’t need to meet the receiver first or arrange a secret password in advance. The sender can use publicly available information, and the message can still be read only by the intended receiver. That sounds almost paradoxical: how can a secret depend on information everybody knows?

  3. Simon

    That puzzle leads to one of the striking examples in the lecture: mental poker. Chess masters can play mental chess by keeping the board and moves in their heads, but how could two people play poker if one of them is allowed to deal? You’d expect the dealer to know everyone’s cards.

  4. Maria

    And yet the source describes a famous paper by Rivest and Shamir showing how public-key cryptography can make mental poker possible. The idea is startling because the players can deal and play without trusting the dealer with the other players’ secrets.

  5. Simon

    The deeper idea is that a function can be easy to compute but hard to invert. If a function is one-to-one, then its output has a unique input, but that doesn’t mean finding the input is practical. The search may take so long that, for real purposes, reversing the function is prohibitive.

  6. Maria

    The number-theory example is multiplication versus factoring. Multiplying two large primes is straightforward, but given their product, finding the original primes is believed to be extremely difficult in general. That gap—easy forward, hard backward—is the foundation RSA relies on.

  7. Simon

    It’s important to distinguish belief from proof here. Factoring is an open problem in computational complexity, and its relationship to the famous P-versus-NP question is related but not identical. It’s possible, for example, that factoring could be tractable while P still does not equal NP.

  8. Maria

    Even without a proof that factoring is hard, banks, governments, and businesses have relied on that difficulty. The RSA name comes from its inventors: Ron Rivest, Adi Shamir, and Len Adleman, who developed the ideas in the late 1970s.

  9. Simon

    Let’s build the system from the receiver’s point of view. The receiver chooses two large primes, called p and q. In practice, the source describes primes hundreds of digits long, chosen with as much randomness as possible so that an attacker can’t easily predict which primes were selected.

  10. Maria

    The receiver multiplies them to get n equals p times q. Multiplication is easy, so the receiver can publish n. But factoring n to recover p and q is the hard problem the system is designed to exploit.

  11. Simon

    Next, the receiver chooses a number e that is relatively prime to the product of p minus 1 and q minus 1. That product is Euler’s phi function of n, usually written phi of n, though you can follow the recipe without knowing the name.

  12. Maria

    The receiver publishes e and n as the public key. Anyone who wants to send a message can look them up. The receiver also finds a number d that is the modular inverse of e modulo phi of n: in other words, e times d leaves remainder one when divided by phi of n.

  13. Simon

    That inverse exists because e was chosen to be relatively prime to phi of n. The receiver can find d using the extended Euclidean algorithm, also called the Pulverizer in the source. The receiver keeps d private; it is the secret key.

  14. Maria

    Now the sender represents the message as a number m in the appropriate range, roughly from 1 to n. If the message is too large to fit, it can be split into smaller pieces. The sender uses the public key and computes m to the power e modulo n.

  15. Simon

    That result is the encrypted message, often written as m-hat. The sender can send m-hat openly: the important point is that seeing the public key and encrypted message does not give an attacker the private key.

  16. Maria

    When the receiver gets m-hat, they raise it to the power d modulo n. The result is the original m. The reason this works comes from Euler’s theorem, at least in the straightforward explanation when m is relatively prime to n.

  17. Simon

    The source also notes that RSA works for all messages m, not just those relatively prime to n, though that fuller result takes more argument. The chance of randomly choosing an m that shares a factor with n is negligible under the assumptions being discussed; in that unusual situation, it would also reveal information useful for factoring n.

  18. Maria

    So the full recipe is compact: publish e and n, keep d secret, encrypt by raising the message to e modulo n, and decrypt by raising the result to d modulo n. But for this to be practical, the receiver has to be able to generate the primes and perform the other calculations efficiently.

  19. Simon

    Finding candidate primes is feasible because primes are dense enough. The prime number theorem says that the number of primes up to a large number n is approximately n divided by the natural logarithm of n. That means that among numbers of a given size, a reasonable fraction are prime.

  20. Maria

    The source also mentions Chebyshev’s bound, a weaker result that can be proved with more elementary tools: the number of primes up to n is at least n divided by four times the natural logarithm of n. Even that bound suggests you don’t have to search very far before finding a prime-sized candidate.

  21. Simon

    For example, when searching among numbers with hundreds of digits, the source estimates that a prime is likely to appear after searching through a manageable number of candidates. A computer can try candidates quickly—but it still needs an efficient way to check whether each candidate is prime.

  22. Maria

    One simple approach is the Fermat test. Fermat’s theorem says that if n is prime, then for any nonzero a modulo n, a to the power n minus one is congruent to one modulo n. If a candidate fails that test, it definitely isn’t prime, so you discard it.

  23. Simon

    But passing doesn’t prove that n is prime. Some composite numbers also satisfy the test for particular choices of a. For most composite numbers, at least half the possible test values fail, so trying random values repeatedly makes a false acceptance increasingly unlikely.

  24. Maria

    If each trial has at least a one-half chance of catching a composite, then after 50 independent random trials, the chance of missing an ordinary composite of this kind is at most one in 2 to the 50th. That’s why repeated tests can be useful even though a single successful Fermat test is not a proof.

  25. Simon

    There is a complication: Carmichael numbers are composite numbers that can pass Fermat tests in a troublesome way, so the simple probability argument has exceptions. The source describes them as sparse and treats the chance of encountering one while choosing candidates randomly as small, making the Fermat test a pragmatic approach in its discussion.

  26. Maria

    The other setup calculations are also efficient. To find e, the receiver tries candidate numbers and uses the greatest common divisor to check whether each is relatively prime to phi of n. Euclid’s algorithm makes that check quick, and the source says a suitable e should be found after only a few tries.

  27. Simon

    Then the extended Euclidean algorithm finds d, the inverse of e modulo phi of n. So the receiver’s work—finding primes, checking that a candidate is prime, choosing e, and calculating d—can all be done with procedures that are manageable for a computer.

  28. Maria

    Now let’s return to security. If an attacker can factor n, they recover p and q. From those, they can calculate phi of n and use the same inverse-finding method to recover d. So factoring n is enough to break the system by recovering its private key.

  29. Simon

    The source also says that if someone can find d, then they can factor n. That links recovering the private key to factoring. But there’s a more subtle question: could someone decrypt messages by a different method without ever finding d?

  30. Maria

    That possibility is not ruled out by the argument. What we would ideally want is a theorem saying that any way of breaking RSA—any way of reading the messages—is as hard as factoring. The source says that this strongest kind of security guarantee is not known for RSA.

  31. Simon

    So RSA’s confidence comes from a combination of mathematical evidence and experience, not a complete proof of security. Mathematicians have searched for efficient factoring methods for a long time, and the source points to decades of attacks by cryptographers and powerful computers without a general break.

  32. Maria

    There have been glitches and weaknesses involving how primes or e were chosen, according to the source, but those problems were identified and addressed with added rules. The key lesson is that the system depends on careful choices as well as the underlying difficulty of factoring.

  33. Simon

    And that brings us back to the original paradox. Public information can be enough to lock a message, while a private mathematical key unlocks it. RSA makes this possible by using operations that are easy to perform in one direction—like multiplying primes—but believed to be prohibitively hard to reverse.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent