An Interactive Guide to DES

August 10, 20269 min read
computer-sciencecryptographyinteractive

Table Of Contents

  1. The block and the key
  2. The Feistel structure
  3. The Feistel function
  4. The key schedule
  5. Putting it together
  6. Small changes, big effect
  7. Why it stopped being safe

DES, the Data Encryption Standard, is where modern block ciphers start. IBM designed it in the early 1970s, the NSA reviewed it, and NIST standardized it in 1977. For nearly 20 years it was the default choice for encrypting sensitive data in banking, government, and early internet protocols.

Below I’ll walk through how DES scrambles a block using a structure called a Feistel network, the same structure that later showed up in Blowfish, Twofish, and plenty of other ciphers.

# The block and the key

DES encrypts data 8 bytes (64 bits) at a time, using a 64-bit key. That key isn’t really 64 bits of secret though. 1 bit in every byte is a parity bit, left over from a time when hardware needed a cheap way to detect transmission errors. So the real key space is 56 bits, 8 bytes with the low bit of each byte dropped.

Enter a plaintext block and a key below, both as hex. The key is hidden by default since it must stay secret. Click the eye icon to reveal it.

Plaintext and key

Plaintext, 64 bits
0000000100100011010001010110011110001001101010111100110111101111
Key, 64 bits (8 dropped as parity)
0001001100110100010101110111100110011011101111001101111111110001

# The Feistel structure

DES doesn’t transform its whole block at once. It splits the 64-bit block into 2 halves, L and R, each 32 bits, and only ever transforms 1 half per round.

In each round, the left and right halves are evolved as follows:

Li=Ri1Ri=Li1f(Ri1,Ki)L_i = R_{i-1} \qquad R_i = L_{i-1} \oplus f(R_{i-1}, K_i)

New left half is the old right half. New right half is the old left half XOR\text{XOR}ed with a function ff applied to the old right half and the round’s subkey.

This is a Feistel network, named after Horst Feistel, who developed the structure at IBM. Its appeal is that ff doesn’t need to be reversible at all. Whatever ff computes, decryption just runs the same rounds in reverse order with the same subkeys, and the XOR undoes itself. That freed the designers to make ff as messy and nonlinear as they wanted, without worrying about inverting it.

Before any of that, the block passes through an initial permutation (IP), which just reorders the 64 bits according to a fixed table. It has no cryptographic purpose. It exists to make the bit layout convenient for the hardware DES was designed to run on in the 1970s. At the end, an inverse permutation (FP) undoes it.

# The Feistel function

Everything that gives DES its security happens inside ff. It takes the 32-bit right half and that round’s 48-bit subkey, and produces a new 32-bit value in 4 steps.

# Expansion

The 32 bits of RR are expanded to 48 bits by duplicating some bits, using a fixed table EE. This is done to align RR with the 48-bit subkey for XOR\text{XOR}. And it also means each output bit depends on more than 1 input bit, an early step toward spreading influence across the block.

# XOR with subkey

Expanded 48 bits are XOR\text{XOR}ed with the round’s subkey. This is where the secret enters, the only place in ff that touches the key.

# Substitution

A substitution box (aka. S-box) is a fixed lookup table that maps a small input to a small output with no formula connecting the two. DES has 8 S-boxes. Each takes 6 input bits and produces 4 output bits. The first and last input bit select a row, the middle 4 bits select a column, and the value at that row and column is the output. The S-box is a lookup table of 4 rows and 16 columns with 4 bits per entry. The behavior of a single S-box is not linear and cannot be described by simple algebra.

The 48 bits coming out of the XOR step are split into 8 groups, 1 group per S-box. This is the only nonlinear step in the entire cipher. Without it, DES would just be a stack of XORs and permutations, solvable with linear algebra.

# Permutation

The 32 bits coming out of the S-boxes are shuffled by a fixed table called PP, spreading each S-box’s output bits across the positions the next round’s expansion will pick up.

Click a 6-bit group below to see exactly how its row and column pick a value out of that S-box.

The Feistel function f(R, subkey), round 1

R (32 bits)
11110000101010101111000010101010
↓ expand E
Expanded (48 bits)
011110100001010101010101011110100001010101010101
↓ XOR subkey 1
XOR result, click a 6-bit group to see its S-box lookup

Group 1, bits 011000. Outer bits (1st and 6th) pick row 0, middle 4 bits pick column 12, in S-box 1. That gives 0101.

↓ S-box substitution, 48 bits → 32 bits
S-box output (32 bits)
01011100100000101011010110010111
↓ permute P
f(R, subkey) output (32 bits)
00100011010010101010100110111011

# The key schedule

A single 56-bit key isn’t used directly. DES expands it into 16 subkeys, 1 per round, each 48 bits.

The 56-bit key (parity bits already dropped) splits into two 28-bit halves, CC and DD. Before each round, both halves rotate left by 1 or 2 bits, following a fixed schedule. The rotated halves are then combined and squeezed from 56 bits down to 48 through a second fixed table, PC-2PC\text{-}2, which also drops some bits permanently.

Because the rotation amounts are small and mostly 2, adjacent round keys share most of their bits. That’s a real weakness, and it’s part of why differential cryptanalysis, discovered publicly in the late 1980s, could be pointed at DES at all.

Key schedule, 16 round keys of 48 bits

Round 11b02effc7072
Round 279aed9dbc9e5
Round 355fc8a42cf99
Round 472add6db351d
Round 57cec07eb53a8
Round 663a53e507b2f
Round 7ec84b7f618bc
Round 8f78a3ac13bfb
Round 9e0dbebede781
Round 10b1f347ba464f
Round 11215fd3ded386
Round 127571f59467e9
Round 1397c5d1faba41
Round 145f43b7f2e73a
Round 15bf918d3d3f0a
Round 16cb3d8b0e17f5

# Putting it together

Run all 16 rounds and watch LL and RR evolve. After round 16, the halves are swapped back and passed through FPFP to produce the ciphertext.

After IP

1 / 17
Lcc00ccff
Rf0aaf0aa

# Small changes, big effect

A well-designed block cipher should turn a single flipped input bit into a completely different output. Flip 1 bit of the plaintext below and see how much of the 64-bit ciphertext changes.

Avalanche effect

Plaintext, click a bit to flip it (currently bit 1)

Flipping that single bit changes 33 of the 64 ciphertext bits.

Ciphertext85e813540f0ab405
Ciphertext, 1 bit flippedad9dfd6c35de8dec

# Why it stopped being safe

Nothing about the Feistel structure or the S-boxes was ever broken outright, but 2 academic attacks came close enough to matter, and a third, more boring problem is what actually finished DES off.

# Differential cryptanalysis

Published by Eli Biham and Adi Shamir in 1990, this attack takes pairs of plaintexts with a fixed difference between them. Encrypting both and tracking how that difference moves through each round exposes a bias in DES’s S-boxes, since some output differences occur more than 50% of the time. An attacker who knows the bias can work backward from enough ciphertext pairs to recover key bits. The method cuts the effective key search from 2562^{56} down to 2472^{47}.

# Linear cryptanalysis

Published by Mitsuru Matsui in 1993, this attack works differently. It builds a single linear equation, using only XOR\text{XOR}, over certain plaintext bits, ciphertext bits, and key bits. Across all 16 rounds combined, that equation holds true slightly more or less than half the time. That small bias, multiplied over enough samples, lets an attacker guess key bits faster than random guessing. This method cuts the search space to 2432^{43}.

Neither attack ever broke DES in practice. Differential cryptanalysis needs about 2472^{47} chosen plaintexts encrypted under the same key, and linear cryptanalysis needs about 2432^{43} known plaintexts under the same key. Real systems don’t encrypt anywhere near that much data with 1 key. Still, DES is vulnerable to both, since both reduced the key space well below the 56 bits it was supposed to offer, and that mattered even before brute force became feasible on its own.

# Brute force

56 bits means 2562^{56} possible keys, about 72 quadrillion. In 1977 that was outside anyone’s budget. By the 1990s, it wasn’t.

In 1998 the Electronic Frontier Foundation built a machine called Deep Crack, purpose-built hardware that did nothing but try DES keys. It cost about $250,000 and found a key in 56 hours. A year later, combined with a distributed network of computers, the same search took under 24 hours. Once a key search fits in a day on hardware anyone could plausibly build, the cipher is done, regardless of how sound its internal design is.

# The replacement

The stopgap was Triple DES (3DES), which runs the DES algorithm 3 times in a row, typically encrypt, decrypt, encrypt, with either 2 or 3 independent keys. That pushes the effective key strength up to 112 or 168 bits, and it bought the industry another decade. But it’s slow. Running the same cipher 3 times costs 3 times the compute, and DES’s 64-bit block size (shared with 3DES) has its own weaknesses at the volumes of data modern systems handle.

NIST ran an open competition in the late 1990s specifically to find a replacement, drawing on 20 years of cryptanalysis of DES to demand a bigger block, a bigger key, and a structure less prone to the weaknesses DES had accumulated. That competition ended in 2001 with a new standard.

DES is retired now. NIST withdrew its approval in 2005, and even 3DES is being phased out. But the Feistel network it introduced didn’t retire with it. Blowfish, Twofish, and large parts of modern block cipher design still lean on the same idea Horst Feistel had at IBM, that a function doesn’t need to be reversible if you’re clever about how you use it.