Symmetric encryption from first principles: the threat model and Kerckhoffs's principle (with the Debian 2008 randomness failure and Kryptos K4), the one-time pad computed by hand with why it is perfectly secret and why key reuse and missing integrity make it impractical, block ciphers as key-chosen permutations, and DES traced on real values through its Feistel round, expansion and S-boxes, ending with why a 56-bit key killed it.
Subject: Computer Security · 64 slides · code lesson
Open the interactive version of this deck
Title
Crypto Lecture 4
Alice and Bob share a key. How does Alice send a message that nobody else can read?
Section
Confidentiality, given a shared key
Objectives
This lesson rebuilds part three of the cryptography lecture, symmetric encryption, up to and including DES. AES gets its own lesson next. Each new cipher arrives as the fix for the previous one's biggest practical problem.
Figure (svg): Three cards: the one-time pad, DES quickly, and AES in depth in the next lesson
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-sym-plan
Warm-up
The last part built MACs. A MAC guarantees integrity and authenticity, and it was careful to say what it does not do.
Discussion prompt
A MAC leaves one of the three classic goals completely unaddressed. Which one, and what would Alice and Bob need in order to provide it?
Hint: Integrity, authenticity, and one more.
Answer:
Confidentiality. A message with an HMAC tag travels in the clear; anyone on the network can read it. To keep its contents secret, Alice needs to encrypt it.
This part assumes, as the MAC part did, that Alice and Bob already share a secret key. How that key got there is the hardest problem of all, and it is postponed to the public-key part of the lecture.
Concept
The scenario is the same one as the MAC part, with a new goal. Alice and Bob share a key. Alice wants to send a message across a network that Mallory can read in full, and she wants only Bob to be able to understand it.
plaintext — the message Alice wants to send, P
ciphertext — what actually travels on the wire, C = E(K, P)
symmetric — Alice encrypts and Bob decrypts with the same key K; the public-key part of the lecture removes that requirement
The rest of this part looks at three ways to compute E: the one-time pad, DES and, in the next lesson, AES. Before any of them, we need to be precise about what Mallory knows and what she does not, because every cipher's security rests on that line.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-div-sym
Prediction
Mallory sees every byte on the wire. Assume she is also a competent engineer.
Predict first
Which of these can a careful designer realistically keep from Mallory?
Correct: The key and the random numbers Alice and Bob pick
Why: Code leaks, gets reverse-engineered from devices, or gets published by insiders, so the algorithm cannot be counted on to stay secret. The ciphertext is on the wire by definition. What remains is the key and the fresh randomness, and every secure cipher rests entirely on those.
Concept
A threat model is the explicit list of what the opponent can see and do. For encryption it splits cleanly into two columns.
| Mallory knows | Mallory does not know |
|---|---|
| the algorithm, in full detail | the key |
| every byte sent over the network | the random numbers Alice and Bob pick |
| the format of typical messages | which particular message was sent |
Students often put the algorithm in the right-hand column. Resist that. Every real cipher you will meet is public, and the ones that tried to stay secret were usually broken soon after they leaked. All of our security has to rest on the right-hand column, which is the principle on the next slide.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-basic-problem
Concept
In 1883 the Dutch linguist and cryptographer Auguste Kerckhoffs wrote down the rule that every modern cipher follows.
Kerckhoffs's principle — an encryption scheme should be secure even if the enemy knows everything about it except the key
The opposite approach, hoping nobody learns how your system works, is called security by obscurity. The practical case against it is about what happens after a leak.
| what leaks | what we must do | how long it takes |
|---|---|---|
| the key | generate a new key | minutes |
| a secret algorithm | replace every card, phone and player that runs it | years |
So everything rests on the key, and the key comes from a random number generator. That makes the random number generator the most important component of the whole system, as the next story shows.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-kerckhoffs
Sorting
Apply Kerckhoffs's principle to a real system: an HTTPS connection to your bank.
Sort into buckets
Under Kerckhoffs's principle, which items is it fine for an opponent to know?
Concept
In 2006 a debugging tool warned that OpenSSL read uninitialised memory, and a Debian maintainer commented out the line that triggered the warning. That line fed randomness into the key generator. Afterwards the only varying input left was the process ID, a number below 32,768.
/* OpenSSL, md_rand.c, as shipped by Debian 2006-2008 */
/* MD_Update(&m, buf, j); */ /* the entropy line, commented out */| intended | Debian, Sept 2006 to May 2008 | |
|---|---|---|
| inputs to the key generator | fresh random data | the process ID only |
| possible keys of each type | about 2 to the power 2000 | 32,768 |
| affected | every SSH and SSL key made on Debian and Ubuntu |
In May 2008 Luciano Bello found the bug. With only 32,768 possibilities for each key type, the entire list of keys could simply be generated in advance, so every affected key had to be thrown away and regenerated. Nothing was wrong with RSA, SSH or the key length. The algorithm was public and fine; the randomness was not.
Debian Security Advisory DSA-1571-1: openssl, predictable random number generator (May 13, 2008) CVE-2008-0166
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-rng-debian
Estimation
A modest laptop can generate and check thousands of keys per second.
Predict first
Roughly how long does it take to produce every key in a list of 32,768?
Correct: Seconds to minutes
Why: 32,768 is 2 to the power 15. Even at a few hundred keys per second that is a couple of minutes, and the work only has to be done once for everybody. Compare 2 to the power 128 keys later in this lesson, a number with 39 digits. The size of the space that a key really comes from is the security; the nominal key length means nothing if the randomness behind it is small.
Socratic
Kerckhoffs says only the key is secret. Debian's keys were generated by a public, correct algorithm.
Discussion prompt
Explain in two sentences how the Debian bug is Kerckhoffs's principle seen from the other side. What component turns out to carry the entire security?
Hint: Where does the key come from?
Answer:
If the algorithm is public, then the only thing standing between Mallory and the plaintext is her uncertainty about the key. The key is exactly as unpredictable as the random number generator that made it, so the generator carries all of the security.
Debian's generator had about 15 bits of uncertainty instead of thousands. Every other part of the system was perfect, and it did not matter.
Concept
In 1990 the artist Jim Sanborn installed Kryptos, a sculpture with four encrypted panels, at CIA headquarters. Panels K1 to K3 were solved in the 1990s. K4, only 97 letters long, stayed unsolved for 35 years because its method was never published.
# K4, as carved into the sculpture
OBKRUOXOGHULBSOLIFBBWFLRVQQPRNGKSSO
TWTQSJQSSEKZZWATJKLUDIAWINFBNYPVTTM
ZFPKWGDKZXTJCDIGKUHUAUEKCAR| ciphertext | Sanborn's published clue |
|---|---|
| FLRV | EAST |
| QQPRNGKSS | NORTHEAST |
| NYPVTT | BERLIN |
| MZFPK | CLOCK |
In 2025 two journalists found the plaintext in Sanborn's papers at a public archive, and the solution later sold at auction for 962,500 dollars. K4 fell to a leak, not to cryptanalysis. It is a wonderful puzzle and a perfect illustration of Kerckhoffs's point: the method will leak eventually, so it cannot be the secret.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-k4
Two truths and a lie
Two of these statements are true and one is a myth.
Eliminate the wrong options
Which statement is the myth?
Survives elimination: o1
Why: Real ciphers such as AES are designed and analysed in public, and their security is judged on the assumption that the algorithm is known. Secrecy of the method can delay an opponent, as K4 did, but no design is allowed to depend on it.
Section
The only provably perfect cipher, and why almost nobody uses it
Concept
The one-time pad is the only cipher that is provably perfect: a ciphertext tells Mallory nothing whatsoever about the plaintext, even with unlimited computing power. It is also almost never used. To see both facts we need a single operation, exclusive or, written XOR or as a circled plus.
XOR works one bit at a time. The output bit is 1 exactly when the two input bits differ.
| a | b | a xor b |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
For bytes and longer strings, XOR each bit position separately. In hex, xor each pair of nibbles: 6b xor 36 is 0110 1011 xor 0011 0110 = 0101 1101 = 5d.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp-intro
Concept
Five facts about XOR, each easy to check from the table on the previous slide. The last one is the whole one-time pad.
| property | in words |
|---|---|
| x xor 0 = x | XOR with zero changes nothing |
| x xor x = 0 | XOR with itself gives zero |
| x xor y = y xor x | the order does not matter |
| (x xor y) xor z = x xor (y xor z) | the grouping does not matter |
| (p xor k) xor k = p | XOR with the same key twice gives p back |
Why the last row holds
Why: (p xor k) xor k = p xor (k xor k) by grouping, = p xor 0 by the second row, = p by the first row.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-xor
Fill the middle
Work each one bit by bit. For hex, convert each digit to four bits first.
Fill in the blanks
1100 xor 1010 = 0110
1111 0000 xor 1010 1010 = 0101 1010
0x6b xor 0x5c = 0x37
0x37 xor 0x5c = 0x6b
Why: 1100 xor 1010: the bits differ in the middle two places, giving 0110. 11110000 xor 10101010 = 01011010. 6b is 0110 1011 and 5c is 0101 1100, which XOR to 0011 0111 = 37. And 37 xor 5c brings back 6b: XOR with the same value twice undoes itself, which is exactly the property the pad uses.
Concept
To encrypt, XOR the plaintext with a key of the same length. To decrypt, XOR the ciphertext with the same key. The key must be truly random, exactly as long as the message, and used only once.
Figure (svg): Bit boxes: plaintext 10111101 xor key 10001111 gives ciphertext 00110010; xoring the ciphertext with the same key gives the plaintext back
| encrypt | decrypt | |
|---|---|---|
| input | P = 10111101 | C = 00110010 |
| xor key | K = 10001111 | K = 10001111 |
| output | C = 00110010 | P = 10111101 |
Decryption works because of the last XOR property: C xor K = (P xor K) xor K = P. Encryption and decryption are literally the same operation.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp
Faded example
Plaintext P = 11001010 and a fresh random key K = 01101100. The first bit of each line is done for you.
Fill in the blanks
C = P xor K = 10100110
P = C xor K = 11001010
Why: 11001010 xor 01101100 = 10100110, so C = 10100110. Decrypting, 10100110 xor 01101100 = 11001010, the original plaintext. Same key, same operation, both directions.
Concept
Claude Shannon gave the precise condition for a cipher that leaks nothing at all.
perfect secrecy — seeing the ciphertext does not change the odds of any plaintext; Mallory learns nothing she did not already know
Shannon proved that perfect secrecy is possible if and only if there are at least as many possible keys as possible plaintexts and the key is chosen so that every possibility is equally likely. The one-time pad meets this exactly: for an n-bit message there are 2 to the power n keys, each equally likely.
| ciphertext seen | if the plaintext were | the key would have to be |
|---|---|---|
| 0110 | 1111 | 1001 |
| 0110 | 0000 | 0110 |
| 0110 | 1010 | 1100 |
Read the table: for the same ciphertext, every plaintext is possible, each matching exactly one key, and every key was equally likely. So the ciphertext gives Mallory no reason to prefer one plaintext over another, no matter how much computing power she has.
C. E. Shannon, Communication Theory of Secrecy Systems, Bell System Technical Journal 28(4), 1949 section 10, perfect secrecy
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp
Explain it to yourself
Mallory intercepts the 4-bit ciphertext 0110 from a one-time pad.
Discussion prompt
Explain why trying every possible key does not help Mallory here, even though there are only 16 keys.
Hint: What does the list of all 16 decryptions look like?
Answer:
Trying all 16 keys produces all 16 possible plaintexts, each exactly once. Mallory ends up with a list containing every 4-bit message, which she already had before intercepting anything.
Against other ciphers, brute force works because only one key gives a sensible-looking plaintext. Against a true one-time pad, every key gives a different plaintext and none is more likely than another, so there is nothing to recognise.
Socratic
Spies really used one-time pads printed on small sheets; the CIA has published one of its own. The mathematics is perfect.
Discussion prompt
So why does nobody protect a website with a one-time pad? Imagine Alice and Bob using one every day for a year. What would they need, and what could Mallory still do?
Hint: Think about the key, and think about the integrity goal from the MAC part.
Answer:
They would need a truly random key as long as everything they will ever send, delivered secretly in advance, and they could never use any part of it twice. That is limitation one.
And even with all that, Mallory can still change messages in transit without being detected. That is limitation two. The next slides take both in turn.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp-limits
Prediction
Alice encrypts two messages with the same key K. P1 = 00000000, P2 = 11111111, K = 00110010. Mallory sees both ciphertexts and XORs them together.
Predict first
What does Mallory get from C1 xor C2?
Correct: P1 xor P2, with the key gone completely
Why: C1 xor C2 = (P1 xor K) xor (P2 xor K) = (P1 xor P2) xor (K xor K) = P1 xor P2. Here C1 = 00110010 and C2 = 11001101, and their XOR is 11111111, which is exactly P1 xor P2. The key cancels out, so its perfect randomness no longer protects anything.
Concept
The two-time pad is the classic misuse of a one-time pad. Each ciphertext alone is still perfectly secret. Together, they leak the XOR of the two plaintexts.
| message 1 | message 2 | |
|---|---|---|
| plaintext | P1 = 00000000 | P2 = 11111111 |
| same key | K = 00110010 | K = 00110010 |
| ciphertext | C1 = 00110010 | C2 = 11001101 |
| C1 xor C2 | 11111111 = P1 xor P2 |
Is P1 xor P2 useful without the key? Very. Real messages are not random: text is mostly letters and spaces, files have fixed headers, and pictures have large flat areas. P1 xor P2 keeps all that structure, and the next slide shows how much of it survives.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp-reuse
Picture it
Make each pixel one bit, black or white, and encrypt two pictures with the same random key, one key bit per pixel.
Figure (svg): Five small pixel grids: P1 shows the letters OK, P2 shows a smiley face, C1 and C2 look like random noise, and C1 xor C2 shows the letters and the face overlaid
Discussion prompt
Before you look closely at the last panel: what should C1 xor C2 look like, and why?
Hint: Use the algebra from the previous slide.
Answer:
It shows both plaintexts on top of each other, because the key cancels: C1 xor C2 = P1 xor P2. Where exactly one picture has ink, the result is black; where both or neither do, it is white.
Each noisy panel alone really is perfectly secret. The leak comes entirely from using the key twice, which is why the pad is called one-time.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp-images
Estimation
Alice wants to send Bob 1 GB of video every day for a year, protected by a one-time pad.
Predict first
How much random key must Bob receive, secretly, before the year begins?
Correct: 365 GB
Why: The key must be as long as all the data and can never be reused, so 365 days of 1 GB each needs 365 GB of key. Reusing one day's key is the two-time pad from the last slides. Compression reduces the total a little, but the key still has to be as long as whatever is actually encrypted.
Concept
Look at what the estimate really says. To send 365 GB secretly, Alice must first deliver 365 GB of key secretly. If she had a way to send 365 GB secretly, she would not need the pad.
| what must be sent | how | |
|---|---|---|
| the data | 365 GB of video | over the open network, encrypted |
| the key | 365 GB of random bits | secretly, in advance |
That is why the pad survives only where a trusted courier already exists. The 1963 Washington-Moscow hotline ran on one-time key tapes carried through the embassies. For everyone else, the goal of the rest of this part is a short key, 16 bytes, that can safely protect terabytes.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp-cost
Prediction
Alice sends the 12-byte message pay Bob 100 dollars, encrypted with a fresh one-time pad. Mallory does not know the key, but she knows the message format, so she knows byte 9 (counting from 0) is the digit 1.
Predict first
Without the key, can Mallory make Bob decrypt the amount as 900?
Correct: Yes; flipping bits of C flips exactly the same bits of P
Why: Decryption XORs C with K bit by bit, so changing bit i of C changes bit i of P and nothing else. The digits 1 and 9 are 0x31 and 0x39, which differ by 0x08, so XORing byte 9 of C with 08 makes it decrypt to 9. Perfect secrecy says Mallory cannot read the message; it says nothing about whether she can change it.
Concept
This property has a name: the one-time pad is malleable. Here it is on real bytes.
P = "pay Bob $100" = 70 61 79 20 42 6f 62 20 24 31 30 30
C = P xor K = d4 7e 70 e3 35 31 49 b0 f5 5f 08 c4
C' = C, byte 9 xor 08 = d4 7e 70 e3 35 31 49 b0 f5 57 08 c4
C' xor K = "pay Bob $900"| byte 9 | meaning | |
|---|---|---|
| plaintext | 31 | the digit 1 |
| ciphertext on the wire | 5f | looks random |
| changed ciphertext | 5f xor 08 = 57 | one byte altered |
| Bob's decryption | 39 | the digit 9, and nothing looks wrong |
The general rule for any XOR-based cipher: C xor d decrypts to P xor d. Mallory needs to know the plaintext at one position, not the key. Bob decrypts cleanly and has no way to notice. The defence is the previous part of the lecture: every cipher in this part must be paired with a MAC.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp-integrity
Trap
A common belief: if Mallory cannot read a message, she cannot meaningfully change it either. Perfect secrecy sounds as if it should include tamper-proofing.
| claim | reality |
|---|---|
| the pad is perfectly secret | true |
| Mallory cannot learn the plaintext | true |
| so Mallory cannot change the plaintext | false: C xor d decrypts to P xor d |
Confidentiality and integrity are separate goals with separate tools. Encryption hides; a MAC detects changes. A message that must not be altered needs a MAC even when it is encrypted, and the lecture's later section on combining the two shows the right order to apply them.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-otp-integrity
Matching
Match each misuse or limitation to what it costs.
Match the pairs
Why: The pad's perfection holds only under all three conditions: truly random, as long as the message, used once. Even then it provides confidentiality only, so it still needs a MAC for integrity.
Pattern
The one-time pad in one slide, before we look for something practical.
Keep the last two points in mind. Key reuse comes back in CTR mode and bit flipping comes back with CBC, in the lesson on modes of operation.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-recap-otp
Section
One short key, reused safely
Socratic
We cannot pre-share 365 GB of random key. Suppose instead Alice and Bob share just 16 random bytes.
Discussion prompt
We already met one construction that runs a single fixed box over a message of any length, 64 bytes at a time. Which one, and how might the same idea give us a cipher with a short key?
Hint: Think of a box we opened up in the hash part of the lecture.
Answer:
MD5, and every Merkle-Damgard hash: one fixed compression box applied block after block. A cipher can work the same way: one fixed box, keyed by a short secret, applied to the message one block at a time.
Ciphers built this way are called block ciphers, and their cousins that generate a long key stream from a short key are stream ciphers. Either way, one short key is reused across the whole message, with some restrictions. The price is that we give up perfect secrecy: security now rests on the opponent's limited computing power.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-reduce-key
Concept
Take MD5's compression function and swap the roles of its inputs. The state being scrambled, A B C D, becomes the plaintext block. The message words that enter every one of the 64 operations become the key.
Figure (svg): Left: MD5's compression box with the state ABCD and message words M as inputs and a dashed feed-forward that adds the input back. Right: the same box relabelled with plaintext and key as inputs and ciphertext as output, with no feed-forward
| MD5 compress | block cipher | |
|---|---|---|
| the value being scrambled | chaining state ABCD | the plaintext block |
| mixed into every operation | message words M[0..15] | the key |
| after the 64 operations | add the input back (feed-forward) | nothing: output is the ciphertext |
The one real difference is the feed-forward. A hash must not run backwards, so MD5 adds its input back to destroy invertibility. A cipher must run backwards for anyone who holds the key, so it leaves the feed-forward out.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-md5-cipher
Discrimination
Both are fixed boxes that scramble a block. Their requirements differ in one crucial way.
Sort into buckets
Which construction needs each property?
Concept
A block cipher E takes a key and one fixed-size block, and produces a block of the same size. Decryption D with the same key takes it back. DES blocks are 64 bits; AES blocks are 128 bits. The same short key is used for every block.
$ echo 00112233445566778899aabbccddeeff | xxd -r -p |
openssl enc -aes-128-ecb -nopad -K 000102030405060708090a0b0c0d0e0f | xxd -p
69c4e0d86a7b0430d8cdb78070b4c55a
# same block, last key byte changed to 0e:
74db6c596f02c433989fb6c9cd317f15| 16 bytes, in hex | |
|---|---|
| plaintext block | 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff |
| key | 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |
| E(key, block) | 69 c4 e0 d8 6a 7b 04 30 d8 cd b7 80 70 b4 c5 5a |
| one key byte changed | 74 db 6c 59 6f 02 c4 33 98 9f b6 c9 cd 31 7f 15 |
These are the official AES test vector from the standard, and the next lesson traces this exact block through all ten rounds. Notice the last row: changing one key byte gives an unrelated block, not a slightly different one.
FIPS 197 — Advanced Encryption Standard (AES) (NIST, 2001), Appendix C.1 test vector Appendix C.1
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-block
Prediction
Keep the plaintext block fixed and change only the last key byte, from 0f to 0e.
Predict first
How many of the 16 ciphertext bytes do you expect to change?
Correct: About half of the bits, spread over essentially all 16 bytes
Why: 69c4e0d8... became 74db6c59...: every byte differs. A good block cipher behaves like an unrelated random table for each key, so neighbouring keys must give unrelated outputs. If a small key change caused a small output change, an opponent could home in on the key gradually.
Concept
Shrink the block to 2 bits. There are only four possible blocks, 00, 01, 10 and 11, so one key is simply a table saying where each block goes.
Figure (svg): Three tables mapping the four 2-bit values: key A and key B are one-to-one; a third table sends both 00 and 01 to 10 and is not allowed
| block size | possible blocks | possible one-to-one tables |
|---|---|---|
| 2 bits | 4 | 4 x 3 x 2 x 1 = 24 |
| 3 bits | 8 | 8! = 40,320 |
| 128 bits | 2 to the power 128 | (2 to the power 128)!, an unimaginable number |
permutation — a one-to-one table from blocks to blocks; every block cipher key must select one, or Bob could not decrypt
A good cipher's table, for a key you do not know, should look as if it had been picked at random from all the possible permutations. Keep the word codebook in mind: ECB mode, in the modes lesson, looks every block up in this one table.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-perm
Check
Each table maps the 2-bit blocks 00, 01, 10, 11 in that order.
Check your understanding
Which of these could be the table for some key of a 2-bit block cipher?
Answer: B
Why: Only B sends the four inputs to four different outputs, so it is a permutation and Bob can always decrypt. It happens to be XOR with 11.
Section
A real block cipher: 64-bit blocks, a 56-bit key, 16 rounds
Concept
DES, the Data Encryption Standard of 1977, splits each 64-bit block into a left half L and a right half R of 32 bits each, then runs 16 identical rounds, each with its own 48-bit round key derived from the 56-bit main key.
Figure (svg): One Feistel round. Encrypt: R0 goes through F with round key K1, the result is xored into L0 to give R1, and R0 becomes L1. Decrypt: the same picture upward, recomputing F of L1 and xoring it out of R1 to recover L0
| one encryption round | undoing it | |
|---|---|---|
| new left half | L1 = R0 | R0 = L1 |
| new right half | R1 = L0 xor F(R0, K1) | L0 = R1 xor F(L1, K1) |
| key order | K1, K2, ..., K16 | K16 first, K1 last |
This structure is called a Feistel network, after Horst Feistel of IBM. Its great trick is in the last column: to undo a round you recompute F and XOR it out again. F itself is never inverted.
FIPS 46-3 — Data Encryption Standard (DES) (NIST, 1999; withdrawn 2005) the DES specification, the cipher function
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-des
Ranking
Bob holds L1, R1 and the round key K1. Put the steps that recover L0 and R0 in order.
Put in order
Why: Because L1 = R0, Bob already has the input F was given. He recomputes F's output and XORs it out of R1, and the XOR property gives L0 back. Doing this for all 16 rounds with the keys in reverse order decrypts the block.
Explain it to yourself
In a Feistel cipher, F may throw information away; DES's F squeezes 48 bits down to 32.
Discussion prompt
Explain why the whole cipher is still one-to-one, a permutation, even though F is not invertible.
Hint: Does decryption ever need F's input from its output?
Answer:
Decryption never needs F run backwards; it only needs F run forwards again on a value Bob already has. Each round maps (L, R) to (R, L xor F(R)), and that map can always be undone by recomputing F(R) and XORing it out.
Every round is therefore one-to-one, and a chain of one-to-one steps is one-to-one. That is exactly the permutation property a block cipher key must have, and it lets the designer pick F purely for how well it scrambles.
Concept
F takes the 32-bit right half and the 48-bit round key, and returns 32 scrambled bits.
Figure (svg): Inside F: R of 32 bits is expanded to 48, xored with the round key, split among eight S-boxes S1 to S8 that each take 6 bits and give 4, and the 32 output bits are shuffled
| step | size | job |
|---|---|---|
| expand E | 32 to 48 bits | copy some bits so R matches the round key's size |
| xor round key | 48 bits | mix in the secret |
| eight S-boxes | 8 x 6 bits in, 8 x 4 bits out | small fixed tables that scramble non-linearly |
| shuffle P | 32 bits | move bits so each S-box feeds several S-boxes next round |
The shuffle sends S1's four output bits to four different places, and the same for every S-box, so after a few rounds every output bit depends on every input bit. The next slides open the expansion and one S-box.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-des-f
Concept
Split R into eight 4-bit groups by position: 1-4, 5-8, up to 29-32. Each group grows to 6 bits by borrowing the bit just before it and the bit just after it, wrapping around at the two ends.
Figure (svg): The eight 4-bit groups of R; the group at positions 5 to 8 becomes positions 4, 5, 6, 7, 8, 9, borrowing position 4 from its left neighbour and position 9 from its right neighbour
| group | positions in R | 6 bits sent to |
|---|---|---|
| 1 (wraps) | 32, 1, 2, 3, 4, 5 | S1 |
| 2 | 4, 5, 6, 7, 8, 9 | S2 |
| 3 | 8, 9, 10, 11, 12, 13 | S3 |
| 8 (wraps) | 28, 29, 30, 31, 32, 1 | S8 |
No bits are invented: 16 of the 32 bits are simply repeated. Because each shared bit lands in two neighbouring S-boxes, a single input bit influences two S-boxes at once, a major source of diffusion in DES.
FIPS 46-3 — Data Encryption Standard (DES) (NIST, 1999; withdrawn 2005) the E bit-selection table
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-des-expand
Worked example
A standard worked example (Grabbe, The DES Algorithm Illustrated) has right half R0 = F0AAF0AA in hex. Here is the expansion, group by group. Every value was checked with a DES implementation.
R0 = F0AAF0AA = 1111 0000 1010 1010 1111 0000 1010 1010
groups = 1111 | 0000 | 1010 | 1010 | 1111 | 0000 | 1010 | 1010
E(R0) = 011110 100001 010101 010101 011110 100001 010101 010101
= 7A15557A1555 (hex)| group | its 4 bits | borrowed: before, after | 6 bits out |
|---|---|---|---|
| 1 | 1111 | bit 32 = 0, bit 5 = 0 | 0 1111 0 = 011110 |
| 2 | 0000 | bit 4 = 1, bit 9 = 1 | 1 0000 1 = 100001 |
| 3 | 1010 | bit 8 = 0, bit 13 = 1 | 0 1010 1 = 010101 |
| 4 | 1010 | bit 12 = 0, bit 17 = 1 | 0 1010 1 = 010101 |
Figure (svg): The four 4-bit groups of F0AAF0AA, each widened to 6 bits by a borrowed bit on each side: 011110, 100001, 010101, 010101
Watch position from value
Why: The number in each borrowed slot is the bit's position in R; the digit after the equals sign is its value. Group 2 borrows position 4, whose value is the 1 at the end of 1111.
J. Orlin Grabbe, The DES Algorithm Illustrated (the worked example with R0 = F0AAF0AA) the expansion of R0
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-recap-des-expand
Verify: Groups 5 to 8 repeat the pattern
Why: R0's second 16 bits equal its first 16, so E(R0) is 7A1555 twice: 7A15557A1555, matching Grabbe's published value.
Fill the middle
R = 0F0F0F0F in hex, so its groups alternate 0000, 1111, 0000, 1111, ... Group 1 borrows bit 32 (the last bit, a 1) and bit 5 (the first bit of group 2, a 1).
Fill in the blanks
group 1: 1 0000 1 = 100001
group 2: 0 1111 0 = 011110
group 3: 100001
Why: Group 2 is 1111; it borrows bit 4, the last bit of group 1 (0), and bit 9, the first bit of group 3 (0), giving 011110. Group 3 is 0000 with neighbours bit 8 = 1 and bit 13 = 1, giving 100001. The pattern alternates all the way round, so E(0F0F0F0F) = 85E85E85E85E in hex.
Concept
Each S-box takes 6 bits and returns 4. The two outer bits pick one of 4 rows; the four inner bits pick one of 16 columns. The tables themselves were fixed by the DES designers and are printed in the standard.
| S1 | columns 0 to 15 |
|---|---|
| row 0 | 14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7 |
| row 1 | 0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8 |
| row 2 | 4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0 |
| row 3 | 15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13 |
Look up 011000
Why: Outer bits 0 _ _ _ _ 0 give row 00 = 0. Inner bits _ 1100 _ give column 12. S1 row 0, column 12 is 5, so the output is 0101.
Six bits in and four bits out means many inputs share each output, so an S-box cannot be inverted. That is fine: it lives inside F, and F never has to be undone. The S-boxes are the only non-linear part of DES; every other step is a copy, a shuffle or an XOR.
FIPS 46-3 — Data Encryption Standard (DES) (NIST, 1999; withdrawn 2005) the selection functions S1 to S8
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-des-sbox
Faded example
Use S1 from the previous slide. For the last line you need S2's row 1, which is 3 13 4 7 15 2 8 14 12 0 1 10 6 9 11 5 (columns 0 to 15).
Fill in the blanks
S1(011000): row 00 = 0, col 1100 = 12 -> 5 = 0101
S1(011001): row 01 = 1, col 1100 = 12 -> 9 = 1001
S2(010001): row 01 = 1, col 1000 = 8 -> 12 = 1100
Why: 011001 has outer bits 0 and 1, so row 01 = 1; the inner bits are still 1100 = 12. S1 row 1, column 12 is 9 = 1001. Flipping the last input bit changed two output bits, 0101 to 1001. For S2, 010001 has outer bits 0 and 1, row 1, and inner bits 1000 = 8; S2 row 1, column 8 is 12 = 1100, written C in hex.
Worked example
Continue Grabbe's example. The first round key is K1 = 1B02EFFC7072. XOR it into E(R0), cut the 48 bits into eight 6-bit pieces, and send one piece to each S-box.
E(R0) = 7A15557A1555
K1 = 1B02EFFC7072
E(R0) xor K1 = 6117BA866527
= 011000 010001 011110 111010 100001 100110 010100 100111
S-box output = 5 C 8 2 B 5 9 7
= 5C82B597 (32 bits, before the shuffle P)| S-box | 6 bits in | row, column | output |
|---|---|---|---|
| S1 | 011000 | 0, 12 | 5 = 0101 |
| S2 | 010001 | 1, 8 | 12 = C |
| S3 | 011110 | 0, 15 | 8 |
| S4 | 111010 | 2, 13 | 2 |
| S5 | 100001 | 3, 0 | 11 = B |
| S6 | 100110 | 2, 3 | 5 |
| S7 | 010100 | 0, 10 | 9 |
| S8 | 100111 | 3, 3 | 7 |
Figure (svg): Eight 6-bit inputs feeding S1 to S8, producing the hex digits 5, C, 8, 2, B, 5, 9, 7
The first two rows are the lookups you just did. The shuffle P then rearranges these 32 bits to give F(R0, K1), which is XORed into L0 to make R1. Fifteen more rounds like this, each with its own round key, give the ciphertext.
J. Orlin Grabbe, The DES Algorithm Illustrated (the worked example with R0 = F0AAF0AA) round 1, the S-box outputs
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-des-sbox
Verify: A DES implementation agrees
Why: Running the standard S-box tables on 6117BA866527 gives 5C82B597, the same 32 bits as Grabbe's published round 1.
Concept
A random table is not enough. A good S-box needs three properties, and all three can be checked directly on S1.
| property | meaning | checked on S1 |
|---|---|---|
| balanced | every output value is equally likely | each row holds each value 0 to 15 exactly once |
| avalanche | flipping one input bit changes at least 2 output bits | 011000 gives 0101 and 011001 gives 1001; all 64 inputs x 6 flips pass |
| not linear | S(a xor b) is not always S(a) xor S(b) | S(000011) = 15, but S(000001) xor S(000010) = 0 xor 4 = 4 |
Non-linearity matters most. If every S-box were linear, the whole cipher would be a big system of XOR equations, and the key could be solved for with algebra. Most attacks on DES aim at the S-boxes.
A historical twist: in 1994 Don Coppersmith of IBM revealed that the S-boxes had been designed in 1974 to resist differential cryptanalysis, an attack the public research community only discovered in 1990.
D. Coppersmith, The Data Encryption Standard (DES) and its strength against attacks, IBM J. Res. Dev. 38(3), 1994 the S-box design criteria
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-sbox-props
Check
Use S1's values: S1(000001) = 0, S1(000010) = 4, and S1(000011) = 15.
Check your understanding
What does this show?
Answer: B
Why: Linearity would require S(a xor b) = S(a) xor S(b) for every pair. Here a xor b = 000011, S of it is 15, while S(a) xor S(b) = 0 xor 4 = 4. One counterexample is enough to prove the box is not linear.
Concept
Nothing clever ever broke DES in practice. What killed it was arithmetic: 2 to the power 56 keys is about 72 quadrillion, and hardware kept getting cheaper.
Figure (svg): Log-scale chart of the cost of a DES-cracking machine: 20 million dollars estimated in 1977, 1 million designed in 1993, 250,000 built in 1998 as EFF Deep Crack, and 10,000 for COPACOBANA in 2006
| year | machine | cost | time |
|---|---|---|---|
| 1977 | Diffie and Hellman's estimate | 20 million dollars | about 1 day |
| 1993 | Wiener's design | 1 million dollars | 3.5 hours |
| 1998 | EFF Deep Crack, built | 250,000 dollars | 56 hours for a challenge key |
| 2006 | COPACOBANA (FPGAs), built | about 10,000 dollars | about 6 days |
After 2006 the time kept falling: RIVYERA (2008) needed under a day, and crack.sh (2012) offered the search as a web service in about 26 hours. Triple DES bought time, and NIST retired it after 2023. Hardware gets cheaper every year, but a 56-bit key stays 56 bits. AES starts at 128.
Electronic Frontier Foundation, Cracking DES: Secrets of Encryption Research, Wiretap Politics and Chip Design (1998) Deep Crack, 1998
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-des-dead
Estimation
Imagine one ordinary chip that tests one billion DES keys per second.
Predict first
Roughly how long does it take that one chip to try all 2 to the power 56 keys?
Correct: About two years
Why: 2 to the power 56 is about 7.2 times 10 to the 16. At 10 to the 9 per second that is 7.2 times 10 to the 7 seconds, about 834 days. On average the key turns up halfway, so about 14 months. A few hundred such chips in parallel finish in days, which is why a 250,000-dollar machine was enough in 1998.
Concept
A block cipher is not perfect like the one-time pad: with enough guesses, the key can always be found. The question is how many guesses. For AES-128, not DES, brute force takes up to 2 to the power 128:
2^128 = 340,282,366,920,938,463,463,374,607,431,768,211,456| quantity | value |
|---|---|
| guesses needed (worst case) | about 3.4 x 10 to the 38 |
| at 10 to the 18 guesses per second | about 3.4 x 10 to the 20 seconds, or 1.1 x 10 to the 13 years |
| compared with the age of the universe | about 780 times longer |
Then the twist. This is not a proof that AES is secure, only that guessing is hopeless. Nobody has proved that any one-way function exists at all, and hashes and block ciphers both rest on that unproven assumption. Proving it would also prove P is not equal to NP, one of the Clay Institute's Millennium Prize problems, worth a million dollars and still open.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-block-security
Socratic
The one-time pad has a proof; AES only has a track record.
Discussion prompt
What kind of evidence justifies trusting a cipher whose security has never been proved? And why is that not the same as security by obscurity?
Hint: Who has tried to break it, and did they know how it worked?
Answer:
The evidence is decades of public attack by the world's cryptanalysts, with the algorithm fully published. Every known attack technique, including the differential and linear attacks that target S-boxes, has been tried, and the best attacks remain far from practical.
That is the opposite of obscurity. Obscurity hides the design and hopes; public cryptanalysis exposes the design and lets everyone try. Confidence comes from many people failing in the open, and Kerckhoffs's principle is what makes that possible.
Pattern
DES in one slide.
The design itself has aged well; the key length has not. AES, in the next lesson, keeps the idea of rounds of substitution and mixing but uses 128-bit blocks and keys of at least 128 bits.
Security I, Lecture 2: Cryptography, part three (symmetric encryption) slide s-recap-des
Trade off
Fill in the blanks to compare the two kinds of cipher you met today.
Comparison matrix
| one-time pad | DES-style block cipher | |
|---|---|---|
| key length | as long as all the data | short and fixed |
| security | perfect, proved | computational, unproved |
| key reuse | fatal | allowed |
| integrity | none | none |
The block cipher trades a proof for practicality: a short key that can be reused, with security resting on the opponent's limited computing power. Neither one gives integrity, so both still need a MAC.
Check
Solve it on paper before you click.
Check your understanding
A company encrypts its backups with a one-time pad, using the same 1 TB random key file for every nightly backup. What is the biggest problem?
Answer: B
Why: A pad is only perfect if it is used once. Two backups encrypted with the same key give C1 xor C2 = P1 xor P2, and backups share huge amounts of structure. The fix is a modern block cipher with a fresh key or nonce per backup, plus a MAC.
Connect it up
Pull the lesson into one picture.
Draw it
Draw three boxes in a row: the one-time pad, the idea of a block cipher, and DES. Under each, write what it fixes and what problem it leaves. Add arrows for the two ideas that carry over: XOR, and one fixed box applied many times. Mark where Kerckhoffs's principle and the random number generator fit.
A complete picture shows: the pad is perfect but needs a huge, single-use key and gives no integrity; a block cipher reuses a short key at the cost of a proof; DES realises it with Feistel rounds and S-boxes but dies of a 56-bit key. Under all three: only the key is secret, so the randomness behind it is everything, and integrity still needs a MAC.
Exit ticket
One question to check the main idea stuck.
Predict first
Why can a DES round be undone even though its function F cannot be inverted?
Correct: Because decryption recomputes F on a value it already has and XORs the result out
Why: After a round, L1 is a copy of R0, so the decryptor already holds F's input. Recomputing F(R0, K1) and XORing it into R1 returns L0. F is only ever run forwards, which is why its S-boxes are free to squeeze 6 bits down to 4.
Recap
The thread of this lesson: only the key is secret, so randomness is everything; the one-time pad is perfect but impractical; block ciphers reuse a short key; DES showed how to build one, and how a short key kills it.
| idea | one-line summary |
|---|---|
| Kerckhoffs | everything public except the key |
| one-time pad | C = P xor K, perfect if K is random, as long as P, and used once |
| block cipher | one key picks one permutation of blocks |
| Feistel round | L1 = R0, R1 = L0 xor F(R0, K1); undo by recomputing F |
| DES | sound design, fatal 56-bit key |
Security I, Lecture 2: Cryptography, part three (symmetric encryption) part three: symmetric encryption
Want this taught 1-on-1? Alexander tutors Computer Security — $55/session, free consultation.