Seyed Masoud Hosseini · Overview · Study log · Weekly summaries · Ideas · Search · Transcript · RSS feed
Design & Analysis of Algorithms · Lecture 31 of 34 · 1:24:14
22. Cryptography: Encryption
Study guide
What this lecture covers
Following the previous lecture on hash functions, this lecture turns to encryption itself: how two parties encrypt and decrypt messages, and how they agree on a secret key in the first place. It moves from symmetric key encryption (a single shared secret) through the Diffie-Hellman key exchange protocol, into asymmetric (public-key) encryption and a full derivation of why RSA works. It closes by asking a deeper question: why RSA's security assumption, factoring, has held up for decades while public-key schemes built on other NP-complete problems, like knapsack, were quickly broken.
This is the second of two cryptography lectures in the course. After watching, you should be able to explain the difference between symmetric and asymmetric encryption, walk through the Diffie-Hellman key exchange and why it's vulnerable to a man-in-the-middle attack, derive why RSA encryption and decryption recover the original message, and explain why worst-case hardness (as in NP-completeness) is not the same as the average-case hardness cryptography actually needs.
Key ideas
- Symmetric key encryption: both parties share one secret key
K; encryption and decryption (E(K,M)andD(K,C)) are often nearly identical operations built from reversible steps like permutation, addition/negation, and XOR (as in AES). - Key exchange problem: symmetric encryption requires a secure way to share
Kfirst; the lecture illustrates this with a "pirate puzzle" solved by locking a box twice, in both orders, and unlocking one lock at a time - which requires the locks to commute. - Diffie-Hellman key exchange: the mathematical analog of the pirate puzzle, using
g^a mod pandg^b mod p; security rests on the discrete logarithm problem and the Diffie-Hellman problem both being computationally hard. - Man-in-the-middle attack: Diffie-Hellman alone doesn't authenticate who you're exchanging keys with; an adversary can substitute their own exponent and intercept the "secure" channel unless public keys are certified by a trusted authority.
- Public-key (asymmetric) encryption: each party has a public key and a private key; anyone can encrypt with the public key, but only the holder of the private key can decrypt, and knowing the public key should not reveal the private key.
- RSA: built from two large secret primes
p, q, withN = pqpublic along with an encryption exponente; the decryption exponentdsatisfiesed = 1 mod (p-1)(q-1), and Fermat's little theorem is used to proveM^(ed) = M mod N. - RSA's hardness assumptions: factoring
Nintopandqmust be hard, and recoveringMfromC = M^e mod Nwithout the private key (the "RSA problem") must be hard. - Average-case vs. worst-case hardness: NP-complete problems like three-colorability and knapsack are hard in the worst case but easy on average (e.g. a random large graph almost always contains an easy-to-spot four-clique), which is why crypto systems built directly on them were broken, while factoring stays hard on average for large numbers.
Walkthrough
Symmetric key encryption (3:04)
The lecture defines symmetric key encryption: a shared secret key K, plaintext M, ciphertext C = E(K,M), and decryption M = D(K,C). Unlike the one-way hash functions from the previous lecture, encryption must be reversible, so it's built from reversible primitives - permutation, XOR, and modular addition - which is roughly how AES works. The open question this raises is how Alice and Bob can share K securely in the first place.
The pirate puzzle and Diffie-Hellman key exchange (12:12)
The lecture poses a puzzle: Alice and Bob want to exchange a secret using boxes and padlocks carried by curious but non-destructive pirates who will steal any visible key but deliver any locked box. The solution - Alice locks the box and sends it, Bob adds his own lock and sends it back, Alice removes her lock and sends it again, then Bob removes his lock and reads the message - requires the two locks to commute, which rules out simply nesting one lock inside another. This maps directly onto Diffie-Hellman key exchange, where Alice and Bob each pick a secret exponent, exchange g^a mod p and g^b mod p, and each compute the same shared key g^(ab) mod p, relying on exponentiation's commutativity and the hardness of the discrete logarithm problem.
The man-in-the-middle attack (30:34)
The lecture identifies the protocol's weak point: nothing authenticates who is actually on the other end. An adversary who can generate their own exponent can intercept and substitute values in both directions, ending up sharing a key separately with Alice and with Bob while each thinks they're talking to the other. The fix requires authenticated, certified public keys (via a trusted authority) rather than Diffie-Hellman alone.
Public-key encryption and RSA setup (36:39)
The lecture formalizes public-key encryption: a message plus a recipient's public key produces ciphertext, and only the recipient's private key can recover the message, with the requirement that the public key reveal nothing about the private key. RSA's key generation is walked through step by step: Alice picks two large secret primes p and q, computes N = pq, chooses a small public encryption exponent e relatively prime to (p-1)(q-1), and derives the private decryption exponent d via the extended Euclidean algorithm so that ed = 1 mod (p-1)(q-1).
Proving RSA works (48:53)
Using Fermat's little theorem (M^(p-1) = 1 mod p for prime p), the lecture proves that encryption followed by decryption, M^(ed) mod N, recovers the original message M, handling the two cases where M is or isn't a multiple of p, then combining the results for p and q via the Chinese remainder-style argument to get the result mod N. It then states RSA's two hardness assumptions: factoring N into p and q must be hard, and recovering M from a given ciphertext without the private key (the RSA problem) must be hard.
Why average-case hardness matters (1:07:07)
The lecture closes by comparing factoring to other NP-complete problems like graph three-colorability and knapsack, both of which were tried as a basis for public-key crypto systems and broken. The key insight is that NP-completeness only guarantees worst-case hardness: a large random graph is almost always trivially provable as non-three-colorable by spotting a small clique, and early knapsack-based cryptosystems (like Merkle-Hellman, which disguises an easy "super-increasing" knapsack as a hard one) were broken because the disguised problem turned out to be easy on average. Factoring large numbers, by contrast, has remained hard in the average case, which is why RSA has survived for decades while those alternatives did not.
Before you watch
- Watch the previous lecture on cryptographic hash functions, since this one builds directly on the public/private key vocabulary and security mindset introduced there.
- Review modular arithmetic and the extended Euclidean algorithm, both used throughout the RSA derivation.
- Basic familiarity with NP-completeness from earlier in the course helps with the closing discussion of worst-case versus average-case hardness.
Check your understanding
- Why must the two locks in the pirate puzzle commute, and what does this correspond to mathematically in Diffie-Hellman key exchange?
- How can an adversary carry out a man-in-the-middle attack against plain Diffie-Hellman key exchange, and what stops it?
- Walk through why
M^(ed) mod NequalsMin RSA, using Fermat's little theorem. - Why were knapsack-based public-key cryptosystems broken even though the general knapsack problem is NP-complete?
Vocabulary
- encryption (noun)
- The process of turning a message into a secret form that hides its meaning.
This lecture turns from hash functions to encryption itself. - symmetric key (noun)
- A single secret key shared and used by both sides of a conversation.
Symmetric key encryption uses one shared secret for both parties. - ciphertext (noun)
- The scrambled, unreadable form of a message after encryption.
The ciphertext looks random to anyone without the key. - plaintext (noun)
- The original readable message before it is encrypted.
Bob decrypts the ciphertext back into the plaintext. - reversible (adjective)
- Able to be undone and returned to the original state.
Encryption must be built from reversible operations. - permutation (noun)
- A rearrangement of the order of a set of items.
AES uses permutation as one of its reversible steps. - key exchange (noun)
- A method for two parties to agree on a shared secret over an insecure channel.
Diffie-Hellman is a famous key exchange protocol. - commute (verb)
- To give the same result regardless of the order the operations are done in.
The two locks in the puzzle need to commute. - discrete logarithm (noun)
- The hard problem of finding the exponent used to produce a given result in modular arithmetic.
Diffie-Hellman's security relies on the discrete logarithm problem. - man-in-the-middle attack (noun)
- An attack where someone secretly intercepts and alters communication between two parties.
A man-in-the-middle attack can break plain Diffie-Hellman. - authenticate (verb)
- To confirm that someone or something really is who or what it claims to be.
Public keys must be authenticated by a trusted authority. - public-key encryption (noun)
- A scheme where anyone can encrypt with a shared public key, but only one person can decrypt with a matching private key.
RSA is a well-known public-key encryption scheme. - asymmetric (adjective)
- Using two different keys instead of one shared key.
Asymmetric encryption uses a public key and a private key. - prime number (noun)
- A whole number greater than one that has no divisors other than one and itself.
RSA is built from two large secret prime numbers. - modular arithmetic (noun)
- A system of arithmetic where numbers wrap around after reaching a fixed value.
RSA computations are all done using modular arithmetic. - exponent (noun)
- The power a number is raised to.
Alice picks a public encryption exponent for RSA. - extended Euclidean algorithm (noun)
- A method for finding numbers that combine to produce the greatest common divisor of two numbers.
The private key is derived using the extended Euclidean algorithm. - Fermat's little theorem (noun)
- A mathematical rule about how numbers behave when raised to powers modulo a prime.
Fermat's little theorem is used to prove RSA is correct. - factoring (noun)
- Breaking a number down into the smaller numbers that multiply together to make it.
RSA's security depends on factoring being hard. - worst-case hardness (noun)
- Difficulty that only appears in the rarest, hardest possible inputs, not typical ones.
NP-completeness only guarantees worst-case hardness. - average-case hardness (noun)
- Difficulty that holds for typical, randomly chosen inputs, not just rare ones.
Cryptography needs average-case hardness to be secure. - clique (noun)
- A group of vertices in a graph that are all connected to each other.
Spotting a clique makes a random graph easy to prove non-colorable. - knapsack problem (noun)
- A problem of choosing items with given weights to hit an exact target sum.
Knapsack-based cryptosystems were broken because they were easy on average. - disguise (verb)
- To hide the true nature of something so it looks different.
The scheme disguises an easy knapsack as a hard one.
From the YouTube description
MIT 6.046J Design and Analysis of Algorithms, Spring 2015
View the complete course: http://ocw.mit.edu/6-046JS15
Instructor: Srinivas Devadas
In this lecture, Professor Devadas continues with cryptography, introducing encryption methods.
License: Creative Commons BY-NC-SA
More information at http://ocw.mit.edu/terms
More courses at http://ocw.mit.edu
← 21. Cryptography: Hash Functions · R11. Cryptography: More Primitives →
