Keys, Brute Force and AES
See why key length decides brute-force resistance, calculate search times, and learn how block ciphers like AES and stream ciphers like ChaCha20 work.
Welcome back!
Step 1 of 13Learn
One key, both directions
In symmetric encryption, the same secret key encrypts and decrypts. Alice and Bob share a key; Alice encrypts with it, Bob decrypts with it. Every cipher in the previous lesson was symmetric, and so are the workhorses of modern computing: AES and ChaCha20.
Symmetric ciphers are fast. A modern laptop with hardware AES support can encrypt several gigabytes per second per core, fast enough that full-disk encryption on phones and laptops costs almost nothing noticeable. That speed is why symmetric encryption carries virtually all bulk data: your HTTPS traffic, your encrypted disk, your VPN tunnel, your messaging app's messages.
The big limitation is key distribution. Both sides need the same secret key before they can talk securely, and they can't send it over the insecure channel they're trying to protect. For governments, that once meant couriers with locked briefcases. On the internet, where you want to talk securely to a website you've never visited, it's solved by public-key techniques covered later in this course, which set up a fresh symmetric key for each session.
A modern symmetric cipher has a precise goal: as long as the key is secret and random, an attacker who sees ciphertexts, and even gets to choose plaintexts to be encrypted, should learn nothing about other plaintexts and should have no better way to find the key than trying every possibility.
Step 2 of 13Learn
Key length and brute force
If the best attack is trying every key, security depends on how many keys there are. A key of n bits has 2n possible values. On average an attacker finds the right key after searching half the space, 2^(n−1) tries.
Each extra bit doubles the work. That exponential growth is what makes modern keys safe:
- 56 bits (the old DES standard): 256 ≈ 7.2 × 1016 keys. In 1998, the Electronic Frontier Foundation built a machine called Deep Crack for about $250,000 that found a DES key in 56 hours. Today such a search is routine for well-equipped attackers.
- 128 bits (AES-128): 2128 ≈ 3.4 × 1038 keys. At a trillion (1012) guesses per second, a full search would take about 1019 years, roughly a billion times the age of the universe. Even a million such machines change nothing meaningful.
- 256 bits (AES-256): 2256 ≈ 1.2 × 1077, a number comparable to the count of atoms in the observable universe.
For a sense of scale, there's also a physical limit: simply counting through 2256 values would need more energy than the Sun will ever produce, under known physics.
So for well-designed ciphers, 128-bit keys are beyond brute force. AES-256 is used when a wider safety margin is wanted, including against future quantum computers, as you'll see in the final lesson. In practice, attackers don't brute-force AES keys; they steal keys, guess weak passwords that keys are derived from, or exploit implementation mistakes.
Step 3 of 13Practice · Chart
Each extra bit doubles the key space
Going from 4 to 8 bits does not double the work: it multiplies it by 24 = 16.
Which key length has exactly twice as many keys as 6 bits?
Tap the bar that answers the question, then press Check.
Step 4 of 13Explore
Brute-force time vs. key length
The curve shows log10 of the years needed to try every key of x bits. A value of 9 means a billion years. Change the attacker's speed.
- log10(years) for a 56-bit key
- -2.6
- log10(years) for a 128-bit key
- 19
- log10(years) for a 256-bit key
- 57.6
Step 5 of 13Practice · Work it out
A key is extended from 64 bits to 80 bits. By what factor does the number of possible keys increase?
Step 6 of 13Learn
Block ciphers and AES
A block cipher encrypts fixed-size chunks of data. Given a key, it acts like a giant scrambled lookup table that maps each possible input block to a unique output block, and decryption reverses it.
AES, the Advanced Encryption Standard, is by far the most widely used. It was selected by the US National Institute of Standards and Technology (NIST) in 2001 after an open, five-year international competition; the winning design, Rijndael, came from two Belgian cryptographers. AES has:
- A block size of 128 bits (16 bytes).
- Key sizes of 128, 192 or 256 bits.
- 10, 12 or 14 rounds, depending on the key size.
Each round mixes the data through simple steps: substituting bytes using a fixed table (to create non-linearity), shifting rows and mixing columns (to spread each byte's influence across the block), and XORing in a round key derived from the main key. After all rounds, changing a single bit of plaintext or key changes about half of the output bits, unpredictably. This is called diffusion, and it's what defeats the pattern-based attacks that broke classical ciphers.
More than two decades of intense public analysis have found no practical attack on full AES. Most modern processors include special AES instructions (AES-NI on x86, cryptography extensions on ARM) that make it both fast and resistant to some timing attacks.
Step 7 of 13Diagram
One AES round
AES repeats the same four operations many times. AES-128 uses 10 rounds, AES-192 12 and AES-256 14.
Tap a shape with to see more.
- SubBytes
Each byte is replaced through a fixed lookup table (the S-box). This is the non-linear step.
- ShiftRows
The rows of the 4×4 byte grid are rotated by different amounts, spreading bytes across columns.
- MixColumns
Each column is mixed so every output byte depends on all four input bytes. Skipped in the last round.
- AddRoundKey
The block is XORed with a round key derived from the main key.
Step 8 of 13Practice · Fill in the blanks
Fill in the blanks
AES always encrypts data in blocks of bits, and it supports key sizes of 128, 192 and bits.
Step 9 of 13Learn
Stream ciphers and ChaCha20
A stream cipher works differently. From the key and a unique number called a nonce (number used once), it generates a long keystream of pseudorandom bits. Encryption is simply plaintext XOR keystream; decryption is ciphertext XOR the same keystream. It's like a one-time pad, except the pad is generated from a short key instead of being truly random.
The most important modern stream cipher is ChaCha20, designed by Daniel J. Bernstein. It's built only from additions, XORs and bit rotations, so it runs fast in software even on devices without AES hardware, such as many older or low-cost phones. HTTPS and many VPNs offer it as an alternative to AES.
Stream ciphers have one rule that must never be broken: never reuse a key-nonce pair. If two messages are encrypted with the same keystream, then C1 XOR C2 = P1 XOR P2: the keystream cancels out, exactly as with a reused one-time pad. If an attacker knows or guesses one plaintext, such as a standard header, they immediately recover the other.
This isn't a theoretical worry. The original Wi-Fi security protocol, WEP, used the RC4 stream cipher with a nonce of just 24 bits, so nonces repeated within hours on a busy network. Combined with other weaknesses, this let attackers recover keys in minutes. WEP was replaced by WPA and then WPA2 and WPA3.
Step 10 of 13Practice · Diagram
How a stream cipher encrypts
Which input must never repeat with the same key?
Tap the shape that answers the question, then press Check.
- Key + nonce
The secret key and a never-repeated nonce go into the generator.
- Keystream generator
ChaCha20 turns them into a long pseudorandom keystream.
- XOR with plaintext
Each plaintext bit is XORed with one keystream bit.
- Ciphertext
Decryption runs the same generator and XORs again.
Step 11 of 13Compare
Block ciphers vs. stream ciphers
| Aspect | Block cipher (e.g., AES) | Stream cipher (e.g., ChaCha20) |
|---|---|---|
| Unit of work | Fixed-size blocks, 128 bits for AES | A keystream XORed with data of any length |
| Needs a mode of operation? | Yes, to handle messages longer than one block | No, but it needs a unique nonce per message |
| Speed | Very fast with hardware AES instructions | Very fast in plain software |
| Critical rule | Use a secure mode with fresh IVs or nonces | Never reuse a key and nonce combination |
| Common use | Disk encryption, HTTPS, VPNs | HTTPS on phones, VPNs such as WireGuard |
Step 12 of 13Practice · True or false
Encrypting two different messages with the same stream cipher key and the same nonce is safe as long as the key stays secret.
Step 13 of 13Practice · Choose one
A security report says a legacy system uses a 56-bit DES key. What is the main problem?
Lesson complete!