Crypto Lecture 4 · Symmetric Encryption: One-Time Pad to DES

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

What this lesson covers

The lesson, slide by slide

1. Symmetric Encryption: One-Time Pad to DES

Title

Crypto Lecture 4

Alice and Bob share a key. How does Alice send a message that nobody else can read?

2. Part 1 — The problem, and what must stay secret

Section

Confidentiality, given a shared key

3. What you will be able to do

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

4. Warm-up: what did a MAC not give us?

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.

5. The goal: a secret over an open network

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

6. What is left that Mallory does not know?

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?

  • The encryption algorithm, if it is never published
  • The key and the random numbers Alice and Bob pick
  • The ciphertext, if it is sent quickly
  • Nothing at all; encryption is hopeless against such an opponent

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.

7. The threat model, written down

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 knowsMallory does not know
the algorithm, in full detailthe key
every byte sent over the networkthe random numbers Alice and Bob pick
the format of typical messageswhich 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

8. Kerckhoffs: only the key should be secret

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 leakswhat we must dohow long it takes
the keygenerate a new keyminutes
a secret algorithmreplace every card, phone and player that runs ityears

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

9. Public or secret?

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?

may be public
That the connection uses AES-128; The full source code of the TLS library; The exact format of the bank's login request
must stay secret
The 16-byte session key; The random numbers chosen during the handshake
pub
The algorithm, the code and the message format are all assumed known. A design that breaks when they leak was never secure.
sec
The key and the fresh randomness are the only secrets. Everything else is designed to be safe in the open.

10. Weak randomness broke Debian's keys in 2008

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 */
intendedDebian, Sept 2006 to May 2008
inputs to the key generatorfresh random datathe process ID only
possible keys of each typeabout 2 to the power 200032,768
affectedevery 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

11. How small is 32,768?

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?

  • Seconds to minutes
  • About a year
  • Longer than the age of the universe
  • It cannot be done without the source code

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.

12. What does Debian teach about Kerckhoffs?

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.

13. Kryptos K4: a secret method, kept just for fun

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
ciphertextSanborn's published clue
FLRVEAST
QQPRNGKSSNORTHEAST
NYPVTTBERLIN
MZFPKCLOCK

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

14. Two truths and a myth about obscurity

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?

  • o1. Keeping the algorithm secret adds a useful extra layer that real ciphers rely on
  • o2. A leaked key can be replaced in minutes, but a leaked algorithm in hardware can take years to replace
  • o3. A cipher with a public algorithm can still be broken by a bad random number generator

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.

15. Part 2 — The one-time pad

Section

The only provably perfect cipher, and why almost nobody uses it

16. The one-time pad needs one tool: XOR

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.

aba xor b
000
011
101
110

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

17. The XOR properties the pad is built from

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.

propertyin words
x xor 0 = xXOR with zero changes nothing
x xor x = 0XOR with itself gives zero
x xor y = y xor xthe order does not matter
(x xor y) xor z = x xor (y xor z)the grouping does not matter
(p xor k) xor k = pXOR 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

18. Your turn: XOR by hand

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.

19. The one-time pad: XOR with a random key

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

encryptdecrypt
inputP = 10111101C = 00110010
xor keyK = 10001111K = 10001111
outputC = 00110010P = 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

20. Encrypt and decrypt with a pad

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.

21. Why the pad is perfect: Shannon, 1949

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 seenif the plaintext werethe key would have to be
011011111001
011000000110
011010101100

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

22. Explain perfect secrecy in your own words

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.

23. The pad is perfect. What is the catch?

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

24. What if the key is reused?

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?

  • Random-looking bits, because both ciphertexts are random-looking
  • The key K
  • P1 xor P2, with the key gone completely
  • Nothing, because she does not know K

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.

25. Limitation 1: a key used twice cancels out

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 1message 2
plaintextP1 = 00000000P2 = 11111111
same keyK = 00110010K = 00110010
ciphertextC1 = 00110010C2 = 11001101
C1 xor C211111111 = 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

26. Limitation 1: two pictures under one pad

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

27. How much key does Bob need?

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?

  • 16 bytes
  • 1 GB, reused every day
  • 365 GB
  • It depends on how much the videos compress

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.

28. Limitation 1: the key problem is the original problem

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 senthow
the data365 GB of videoover the open network, encrypted
the key365 GB of random bitssecretly, 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

29. Limitation 2: can Mallory turn 100 into 900?

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?

  • No; without the key every change is random
  • No; the pad is perfectly secret, so it is tamper-proof too
  • Yes; flipping bits of C flips exactly the same bits of P
  • Only if she can see many messages encrypted under the same key

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.

30. Limitation 2: secrecy is not integrity

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 9meaning
plaintext31the digit 1
ciphertext on the wire5flooks random
changed ciphertext5f xor 08 = 57one byte altered
Bob's decryption39the 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

31. Trap: “it is encrypted, so nobody can change it”

Trap

The 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.

claimreality
the pad is perfectly secrettrue
Mallory cannot learn the plaintexttrue
so Mallory cannot change the plaintextfalse: C xor d decrypts to P xor d

The fix

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

32. The pad's limitations and their consequences

Matching

Match each misuse or limitation to what it costs.

Match the pairs

  • l1. the same key used for two messages
  • l2. key as long as all the traffic
  • l3. no integrity
  • l4. a key that is not truly random
  • r1. C1 xor C2 = P1 xor P2, and the structure shows through
  • r2. delivering the key is as hard as delivering the data
  • r3. flipping bits of C flips the same bits of P undetected
  • r4. Shannon's condition fails, so perfect secrecy is lost

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.

33. Recap: the one-time pad

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

34. Part 3 — From pads to block ciphers

Section

One short key, reused safely

35. How can a short key protect a long message?

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

36. MD5's box is almost a block cipher

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 compressblock cipher
the value being scrambledchaining state ABCDthe plaintext block
mixed into every operationmessage words M[0..15]the key
after the 64 operationsadd 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

37. Hash box or cipher box?

Discrimination

Both are fixed boxes that scramble a block. Their requirements differ in one crucial way.

Sort into buckets

Which construction needs each property?

hash compression box
nobody at all can run it backwards; its output is shorter than its input
block cipher
anyone holding the key can run it backwards; different inputs must give different outputs, always
hash
A compression box squeezes state plus a block down to a new state, and must be one-way. Many inputs share each output; collisions exist but must be hard to find.
ciph
Decryption must recover the exact plaintext, so the cipher must be one-to-one for each key and efficiently invertible with the key.

38. A block cipher encrypts one block at a time

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 block00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
key00 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 changed74 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

39. One key byte changes. What happens to the ciphertext?

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?

  • Only the last byte
  • About half of the bits, spread over essentially all 16 bytes
  • None; the key only matters for decryption
  • Exactly one bit

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.

40. A block cipher is a table chosen by the key

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 sizepossible blockspossible one-to-one tables
2 bits44 x 3 x 2 x 1 = 24
3 bits88! = 40,320
128 bits2 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

41. Checkpoint: which table can be a key?

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?

  • A. 00, 00, 11, 11
  • B. 11, 10, 01, 00 (correct)
  • C. 01, 10, 01, 10
  • D. 10, 11, 11, 00

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.

Why A tempts people
00 and 01 both map to 00, so a ciphertext of 00 could mean either plaintext.
Why C tempts people
Only two outputs are ever used; half the information is destroyed.
Why D tempts people
01 and 10 both map to 11.

42. Part 4 — DES, quickly

Section

A real block cipher: 64-bit blocks, a 56-bit key, 16 rounds

43. DES: scramble half, XOR it in, swap

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 roundundoing it
new left halfL1 = R0R0 = L1
new right halfR1 = L0 xor F(R0, K1)L0 = R1 xor F(L1, K1)
key orderK1, K2, ..., K16K16 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

44. Undo one round, in order

Ranking

Bob holds L1, R1 and the round key K1. Put the steps that recover L0 and R0 in order.

Put in order

  1. Read off R0, because L1 is just a copy of R0
  2. Recompute F(R0, K1) using the same round key
  3. XOR that value into R1
  4. The result is L0, since R1 = L0 xor F(R0, K1)

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.

45. Why can F be any function at all?

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.

46. What is F? Four steps on 32 bits

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

stepsizejob
expand E32 to 48 bitscopy some bits so R matches the round key's size
xor round key48 bitsmix in the secret
eight S-boxes8 x 6 bits in, 8 x 4 bits outsmall fixed tables that scramble non-linearly
shuffle P32 bitsmove 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

47. How expand turns 32 bits into 48

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

grouppositions in R6 bits sent to
1 (wraps)32, 1, 2, 3, 4, 5S1
24, 5, 6, 7, 8, 9S2
38, 9, 10, 11, 12, 13S3
8 (wraps)28, 29, 30, 31, 32, 1S8

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

48. Worked example: expand a real half-block

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)
groupits 4 bitsborrowed: before, after6 bits out
11111bit 32 = 0, bit 5 = 00 1111 0 = 011110
20000bit 4 = 1, bit 9 = 11 0000 1 = 100001
31010bit 8 = 0, bit 13 = 10 1010 1 = 010101
41010bit 12 = 0, bit 17 = 10 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.

49. Your turn: expand two groups

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.

50. An S-box is a fixed lookup table

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.

S1columns 0 to 15
row 014 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7
row 10 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8
row 24 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0
row 315 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

51. Look up two more S-box inputs

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.

52. Worked example: one full pass through F

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-box6 bits inrow, columnoutput
S10110000, 125 = 0101
S20100011, 812 = C
S30111100, 158
S41110102, 132
S51000013, 011 = B
S61001102, 35
S70101000, 109
S81001113, 37

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.

53. What makes a good S-box?

Concept

A random table is not enough. A good S-box needs three properties, and all three can be checked directly on S1.

propertymeaningchecked on S1
balancedevery output value is equally likelyeach row holds each value 0 to 15 exactly once
avalancheflipping one input bit changes at least 2 output bits011000 gives 0101 and 011001 gives 1001; all 64 inputs x 6 flips pass
not linearS(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

54. Checkpoint: is this S-box linear?

Check

Use S1's values: S1(000001) = 0, S1(000010) = 4, and S1(000011) = 15.

Check your understanding

What does this show?

  • A. S1 is linear, because 000001 xor 000010 = 000011
  • B. S1 is not linear, because S1(000011) = 15 but S1(000001) xor S1(000010) = 4 (correct)
  • C. Nothing; linearity needs every input checked
  • D. S1 is not balanced

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.

Why A tempts people
The inputs XOR correctly, but the outputs do not, which is exactly what non-linear means.
Why C tempts people
Proving linearity needs every pair; disproving it needs only one.
Why D tempts people
Balance is a separate property, and S1 does have it.

55. DES died because its 56-bit key is too short

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

yearmachinecosttime
1977Diffie and Hellman's estimate20 million dollarsabout 1 day
1993Wiener's design1 million dollars3.5 hours
1998EFF Deep Crack, built250,000 dollars56 hours for a challenge key
2006COPACOBANA (FPGAs), builtabout 10,000 dollarsabout 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

56. How long to try every DES key?

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?

  • About a minute
  • About two years
  • About a million years
  • Longer than the age of the universe

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.

57. How secure is a block cipher?

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
quantityvalue
guesses needed (worst case)about 3.4 x 10 to the 38
at 10 to the 18 guesses per secondabout 3.4 x 10 to the 20 seconds, or 1.1 x 10 to the 13 years
compared with the age of the universeabout 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

58. If nothing is proven, why trust AES?

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.

59. Recap: DES, a Feistel cipher

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

60. One-time pad or block cipher?

Trade off

Fill in the blanks to compare the two kinds of cipher you met today.

Comparison matrix

one-time padDES-style block cipher
key lengthas long as all the datashort and fixed
securityperfect, provedcomputational, unproved
key reusefatalallowed
integritynonenone

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.

61. Checkpoint: spot the real weakness

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?

  • A. 1 TB is too short for a one-time pad key
  • B. Reusing the key means two backups XOR to the XOR of their plaintexts, which leaks heavily (correct)
  • C. XOR is a weak operation and should be replaced with addition
  • D. There is no problem; the one-time pad is perfectly secret

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.

Why A tempts people
Length is fine if each night's backup is under 1 TB; the problem is using the same bytes again.
Why C tempts people
XOR is exactly right for a pad; the operation is not the weakness.
Why D tempts people
Perfect secrecy requires the key to be used only once.

62. Draw the path from the pad to DES

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.

63. Exit ticket

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?

  • Because F is a permutation in disguise
  • Because decryption recomputes F on a value it already has and XORs the result out
  • Because the S-boxes are invertible
  • Because DES uses the one-time pad internally

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.

64. What you can do now

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.

ideaone-line summary
Kerckhoffseverything public except the key
one-time padC = P xor K, perfect if K is random, as long as P, and used once
block cipherone key picks one permutation of blocks
Feistel roundL1 = R0, R1 = L0 xor F(R0, K1); undo by recomputing F
DESsound design, fatal 56-bit key

Security I, Lecture 2: Cryptography, part three (symmetric encryption) part three: symmetric encryption

Sources

  1. Security I, Lecture 2: Cryptography, part three (symmetric encryption)
  2. C. E. Shannon, Communication Theory of Secrecy Systems, Bell System Technical Journal 28(4), 1949
  3. FIPS 46-3 — Data Encryption Standard (DES) (NIST, 1999; withdrawn 2005)
  4. FIPS 197 — Advanced Encryption Standard (AES) (NIST, 2001), Appendix C.1 test vector
  5. Debian Security Advisory DSA-1571-1: openssl, predictable random number generator (May 13, 2008)
  6. D. Coppersmith, The Data Encryption Standard (DES) and its strength against attacks, IBM J. Res. Dev. 38(3), 1994
  7. Electronic Frontier Foundation, Cracking DES: Secrets of Encryption Research, Wiretap Politics and Chip Design (1998)
  8. J. Orlin Grabbe, The DES Algorithm Illustrated (the worked example with R0 = F0AAF0AA)

Want this taught 1-on-1? Alexander tutors Computer Security — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108