AES-128: key search, the round structure, and Grover's algorithm
AES (the Advanced Encryption Standard, chosen by the US standards agency NIST in 2001) is the lock on most of the data computers send and store: web pages, Wi-Fi, phone calls, the files on your phone. Unlike RSA and Diffie-Hellman, it has no clever math trick to attack: the only way in is to try keys. This guide shows how AES scrambles a message, how an eavesdropper searches for the key when she already knows most of it, and why quantum computers weaken AES but don't break it. Every example matches what you will see on the AES page in Redux.
How Redux's AES problem models a key search on AES-128: the instance formats, the reduced key space (k unknown key bits), the cipher round by round as Redux draws it, how the attacker recognizes the right key, the verifier, and where Grover's algorithm enters. Every number on this page comes from the default instance (2b7e151628aed2a6abf7158809cf4f3c,8,"Hello World"), whose key is the FIPS 197 example key.
Alice's message, locked with AES
One AES block: plaintext with padding, and its ciphertext
Top: the message, filled out to 16 places with padding. Middle: each character as a byte, written in hex (section 2). Bottom: what actually travels. Unlike RSA and Diffie-Hellman, the bottom row doesn't line up letter by letter: AES scrambles the whole block at once.
ASCII bytes plus PKCS#7 padding (five bytes of 05), encrypted as one 128-bit block under the 128-bit key. No byte of the ciphertext corresponds to a byte of the plaintext.
1
One key, shared by two people
The setting: a symmetric cipher and the attacker's view
RSA and Diffie-Hellman are slow, so computers use them only to agree on a secret key (the Diffie-Hellman guide shows how). From then on, Alice and Bob lock everything with AES, which is very fast. The same key locks and unlocks, so both of them hold a copy.
An AES key is 128 bits: 128 zeros and ones. Nobody can try that many keys (section 7). So that Eve has a chance, Redux gives her a head start: she knows the whole key except the last few bits. Real keys have no known bits; this is a shortcut to make the search small enough to watch.
AES is a symmetric block cipher: one key encrypts and decrypts, here AES-128 on a single 16-byte block. It has no algebraic weakness comparable to factoring or discrete logs; the best known attacks on the full cipher are barely better than exhaustive search. So Redux models the attack as a key search over a reduced key space: the attacker knows the key except its last k bits (1 ≤ k ≤ 20) and searches 2k candidates.
Two instance forms. Message mode (keyHex,k,"TEXT"): Redux pads and encrypts the text and keeps only the ciphertext and the known key bits; the attacker recognizes the right key because the decryption reads as a message. Eve's view (knownKeyHex,k,plaintextHex,ciphertextHex): a known-plaintext attack, where the last k bits of the known key must be zero.
Alice and Bob each hold the same secret key, 128 bits written as 32 hex symbols (section 2).Shared 128-bit key K = 2b7e1516 28aed2a6 abf71588 09cf4f3c (FIPS 197).Alice locks her message, filled out to 16 places, into 16 scrambled bytes.C = AES-128K(pad(M)), one block.Eve sees the scrambled bytes and every bit of the key except the last 8, shown as ??.Eve's knowledge: C and the known key bits K with the last k = 8 bits hidden.
2
Bits, bytes and hex
Bytes, the block, and XOR
Computers store everything as bits, zeros and ones. Eight bits make a byte, which can hold a number from 0 to 255. Each letter has a standard byte (its ASCII code): H is 72, E is 69, a space is 32.
Bytes are usually written in hex, which counts in sixteens using 0 to 9 and then a to f (a = 10, ..., f = 15). Every byte is exactly two hex symbols: H, 72, is 4 × 16 + 8, written 48. So a 128-bit key is 32 hex symbols.
AES always locks exactly 16 bytes, a block. A shorter message is filled out with padding: if 5 places are left, each holds the number 5. Type a message to see its block:
Message mode upper-cases the text, writes it as ASCII and pads it to 16 bytes with PKCS#7 (n missing bytes, each equal to n; at least one, so at most 15 characters). AES treats each byte as an element of GF(28), the field of polynomials over GF(2) modulo x8 + x4 + x3 + x + 1; addition is XOR.
Green: your characters, with their hex below. Gray: padding.Bytes in order; the state fills column by column (byte i goes to row i mod 4, column ⌊i/4⌋).
AES mixes the key in with XOR: line up two bytes bit by bit, and write 0 where the bits match and 1 where they differ. Doing it again with the same key byte undoes it, which is part of how Bob unlocks. Here is the very first thing AES does, character by character:
The first operation is AddRoundKey with round key 0, the key itself: byte by byte, state ⊕ K. Pick a position:
3
How AES scrambles the block
The round function, as Redux draws it
AES arranges the 16 bytes in a 4 × 4 grid and then does 10 rounds. Each round has four moves:
SubBytes: swap every byte for another, using a fixed table called the S-box.
ShiftRows: slide row 1 one place to the left, row 2 two places, row 3 three places.
MixColumns: stir each column, so every byte in it affects the other three.
AddRoundKey: XOR in a round key, a new 16 bytes made from the main key.
Below is exactly what Redux shows for Alice's message, all 41 steps. Changed bytes are blue; the last grid is the scrambled message Eve intercepts.
AES-128 is 10 rounds of SubBytes (each byte through the S-box: the inverse in GF(28) followed by an affine map), ShiftRows (row r rotated left by r), MixColumns (each column multiplied by the circulant matrix [2 3 1 1]; omitted in round 10) and AddRoundKey, after an initial AddRoundKey. The key schedule expands K into 11 round keys with RotWord, SubWord and round constants. The replay below is Redux's AES Round-by-Round Encryption visualization, frame by frame.
message→AddRoundKey→ rounds 1 to 9:SubBytesShiftRowsMixColumnsAddRoundKey→ round 10:SubBytesShiftRowsAddRoundKey→ciphertext
After ten rounds every byte depends on every byte of the message and of the key. Change one letter, or one bit of the key, and about half of the 128 bits of the result change. That is called the avalanche effect, and it is why Eve can't tell that a key is "close": a nearly right key gives complete gibberish. Try it:
Full diffusion after two rounds: each output bit depends on every input and key bit. Changing one plaintext or key bit flips each ciphertext bit with probability close to 1/2, so the ciphertext gives no gradient toward the key.
HELLO WORLD with the real key
AESK(HELLO WORLD)
Your version
AESK'(M')
4
Eve tries every ending of the key
The attack: AES Brute Force Key Search
Eve knows all of the key except the last 8 bits, the last two hex symbols. 8 bits can take 8 twos multiplied together = 256 different values, 00 to ff. So she tries them in order: complete the key, unlock the intercepted block, and look at the result. A wrong key gives gibberish; the right one gives letters and spaces followed by proper padding.
Redux's only solver (and its default). For x = 0, 1, ..., 2k − 1 it forms K' = known bits ‖ x, decrypts C, and accepts when the block parses as PKCS#7-padded upper-case letters and spaces (in Eve's view: when AESK'(P) = C). Up to 2k AES operations, about 3.6 µs each in Redux's Release build, which is why k is capped at 20 (a few seconds).
Here is Eve's notebook, the same table Redux shows, with Redux's own explanations.
The step table replays the solver's recorded steps for the default instance, with Redux's own text.
Reading Redux's shorthand.
Hex: two symbols per byte (section 2). ?? marks the hex symbols Eve doesn't know.
k: how many bits are missing. 2^8 means 8 twos multiplied together: 256.
3c (binary 00111100): the missing ending in hex, and the same 8 bits as zeros and ones.
One AES run: one unlocking attempt. Ciphertext means the locked block, plaintext the message.
Padding bytes: the filler at the end of the block (section 2).
Value
Contents
Can Eve see it?Visible to the attacker?
How Eve knows itHow the attacker knows it
Blue: the row Eve just worked out. Green: the message, the answer.Blue is ElementHighlight; green is Solution.
5
Run it in Redux
Here is the AES page in Redux, and what each part does.
The AES page (/AES in Redux_Frontend). The parts below map onto Redux's problem interface: the instance, the solver, the chosen visualization, and the verifier.
1234567
1Details.The problem in words. It uses some technical terms; this guide explains the same ideas in plain words. Close it with × for more room.problemDefinition, input and output descriptions, source and contributors.
2Instance.The puzzle: the key, how many of its bits Eve doesn't know, and Alice's message. Press Edit to type your own.(keyHex,k,"TEXT") or (knownKeyHex,k,plaintextHex,ciphertextHex). Edit to change it; it is checked as you type.
3Solver.Eve's attack. AES has just one: AES Brute Force Key Search. The small tags (like NP or Brute Force) and the Reduce button are for other parts of Redux; you can ignore them.One ISolver, AESBruteForceKeySearchSolver, tagged Brute Force and Exponential.
4Run solve.Runs the search.Runs the solver and records its steps for the picture.
5Visualization Type.AES has two pictures: the Attacker Knowledge Table (Eve's notebook) and AES Round-by-Round Encryption (section 3). Choosing a picture resets the page, so press Run solve again after switching.AES Attacker Knowledge Table (DynamicTable) and AES Round-by-Round Encryption (DynamicTable with per-cell colors). Switching resets the run.
6The picture.Before running, the table shows only what Eve sees.Public rows (known key bits, k, ciphertext); secret rows (missing bits, full key, message) shown as "?".
7Result.The answer, and a box where you can check any answer yourself.Answer (certificate), timing, and the verifier.
Attacker Knowledge Table
AES Round-by-Round Encryption
After Run solve, use the player under the picture: ▶ plays the steps, the arrows move one step, and the slider jumps. Its counter includes the starting picture, so it always reads one more than the picture's own step number.The player's count includes the initial frame (visualize), so it runs to 42 while the frame titles run to 41.
Checking an answer
The verifier
The Result panel shows the answer and lets you check any answer you type. Redux calls a proposed answer a certificate: here, the full key and the message, (2b7e151628aed2a6abf7158809cf4f3c,"HELLO WORLD"). Redux checks two things: the key agrees with every bit Eve already knew, and locking your message with it gives exactly the intercepted block.
The Default AES Verifier checks that the proposed key agrees with the known bits, then pads and encrypts the proposed message (in Eve's view, the known plaintext) and compares with C: one AES encryption. Checking is cheap, finding is 2k, so the problem is declared in NP: AES = {<K, k, P, C> | some key K' that agrees with K except in its last k bits has AES-128_K'(P) = C}.
The answer after Run solve.Key ending 3c: accepted.Key ending 3d, one bit off: rejected.
If Redux can't read the instance
The box turns red and Run solve is grayed out. A message may only use letters and spaces, so "Hi!" fails because of the "!". It must also fit in one block (at most 15 characters, because padding needs at least one place), the key must be 32 hex symbols, and Eve may be missing 1 to 20 bits.
A ProblemParseException (HTTP 400) disables Run. Backend reasons: '!' cannot be encrypted; the message must fit in one AES block: at most 15 characters, got 16; k must be 1 to 20, got k = 21; and in Eve's view, the last k = 8 bits of the known key must be zero.
6
How Eve knows she has the right key
Recognizing the key: false positives and known plaintext
A wrong key turns the block into 16 random-looking bytes. To fool Eve, those bytes would have to end in proper padding and have nothing but capital letters and spaces before it. The chance of that is about 1 in 100,000,000,000,000,000. Here is what three wrong keys give, next to the right one:
For a random 16-byte block, the probability of parsing as n bytes of padding after 16 − n allowed characters (27 of 256 byte values) is Σn=1..15 256−n (27/256)16−n ≈ 9.0 × 10−18, dominated by n = 1. Even at k = 20 the expected number of false keys is about 10−11. Decryptions under three wrong keys and the right one:
Sometimes Eve knows a piece of the message and its locked version, for example a standard greeting at the start of every file. Then she doesn't need to recognize letters: she locks the known piece with each candidate key and checks for an exact match. Redux calls this Eve's view and writes it with four values: the known key bits (with the unknown bits written as zeros), how many are unknown, the known message block and its locked block. Section 9 has an example from the official AES standard.
Eve's view is a known-plaintext attack: accept K' when AESK'(P) = C. For one block and k ≤ 20 the key is unique with overwhelming probability. The last k bits of knownKeyHex must be zero, otherwise the instance would contain its own answer. The example is FIPS 197 Appendix B: P = 3243f6a8885a308d313198a2e0370734, C = 3925841d02dc09fbdc118597196a0b32.
7
How many keys are there?
Key length and the cost of search
Each extra unknown bit doubles the number of keys. Redux stops at 20 unknown bits, about a million keys, which takes a few seconds. A real AES key has 128 unknown bits. Slide to see what that means for a computer trying a billion keys every second.
Exhaustive search costs about 2k AES operations; Grover's algorithm needs about (π/4)·2k/2 iterations, each evaluating AES (and its inverse, to uncompute) as a reversible circuit. The vertical axis is logarithmic. Grover's iterations are sequential, and splitting the search over M machines leaves each one about √(N/M) iterations, so the quantum speed-up parallelizes far worse than classical search.
Keys to try (worst case)
At a billion keys a second
Rounds of Grover's algorithm (section 8)
The old standard DES had 56-bit keys. In 1998 a special machine built by the Electronic Frontier Foundation found a DES key in 56 hours. That is one reason AES uses 128 bits or more.
DES (56-bit keys) fell to exhaustive search in 1998: the EFF's DES Cracker found a key in 56 hours. AES-128 and AES-256 are the usual choices today; against Grover's algorithm a 256-bit key keeps a margin comparable to a 128-bit key against classical search.
8
What a quantum computer can do
Grover's algorithm on the key search
For RSA and Diffie-Hellman, a big quantum computer would be a disaster. For AES it is only a speed-up. In 1996 Lov Grover found a quantum method for searching, now called Grover's algorithm, that needs only about the square root of the number of tries. For 256 keys the square root is 16, and in fact 12 rounds are enough, instead of up to 256 tries. That sounds huge, but for a 128-bit key it still leaves about 64 twos multiplied together, far too many. With a 256-bit key, AES stays out of reach even for Grover's algorithm.
Grover's algorithm finds the one candidate that passes the test among N = 2k with about (π/4)√N oracle calls instead of up to N classical tries: 12 for N = 256 (success probability 0.99995), about 1.45 × 1019 for k = 128. The oracle has to compute AES reversibly, which dominates the cost. The speed-up is quadratic, not exponential as Shor's algorithm is for RSA and Diffie-Hellman, so AES-256 keeps about 128 bits of security against it.
Quantum computer guides are in progress. They will cover Shor's and Grover's algorithms step by step.
9
Things to try in Redux
Exercises
Instances are written (key, bits Eve doesn't know, "message"). Copy an instance, press Edit on the AES page, paste it, then Run solve. Redux allows about 10 runs a minute; if it says "Too many runs in a row", wait a few seconds.
Lock your own name
(2b7e151628aed2a6abf7158809cf4f3c,8,"YOUR NAME")
Swap in your name (letters and spaces, up to 15). Is Eve's search any faster or slower than for HELLO WORLD?
Answer
Exactly the same: 61 tries. The search goes through key endings, not messages, and the right ending is still 3c.
Compare the ciphertext row with the one for HELLO WORLD. How much changed?
Answer
Everything: a38647f0... instead of 2a68e62d.... 64 of the 128 bits are different, half of them, as section 3 shows.
Catch a wrong answer
After running the starting instance (2b7e151628aed2a6abf7158809cf4f3c,8,"Hello World"), open Result and type (2b7e151628aed2a6abf7158809cf4f3d,"HELLO WORLD"), then press Check.
What happens
"Not a valid certificate." The key is one bit off (3d instead of 3c), so locking HELLO WORLD with it gives a completely different block.
Compare its ciphertext with the default's. The keys differ in one bit; how many ciphertext bits differ? And for the message HELLO WORLE under the original key?
Answer
Key bit: 62 of 128 (ee351e81... against 2a68e62d...). Message: 64 of 128 (a38647f0...). Both close to the 64 expected of a random permutation.
2. False positives
Derive the probability that a random block passes the message test, and the expected number of wrong keys that pass at k = 20.
Answer
Σn=1..15 256−n(27/256)16−n ≈ 9.0 × 10−18 (the n = 1 term is 8.7 × 10−18). Times 220 − 1 wrong keys: about 9.5 × 10−12.
At about 3.6 µs per candidate, how long can this take, and why does the page take about twice that?
Answer
220 × 3.6 µs ≈ 3.8 s worst case (this key's ending, f4f3c, is found on try 1,003,325). The page runs the attack twice: once for the answer and once for the picture's steps.
10
Words to know
Reference card
Bit, byte
A bit is a 0 or a 1. A byte is 8 bits, a number from 0 to 255.
Hex
Counting in sixteens with 0 to 9 and a to f. Each byte is two hex symbols: 48 is H.
Key
The secret Alice and Bob share: 128 bits, 32 hex symbols. The same key locks and unlocks.
Block
The 16 bytes AES locks at once.
Padding
Filler that completes the block: with 5 places left, five bytes of 5.
XOR
Comparing bits: 0 where they match, 1 where they differ.
Round
One pass of AES's four moves. AES-128 does 10.
Plaintext, ciphertext
The message before it is locked, and the locked block that travels.
Brute force
Trying every possibility in turn.
Solver
In Redux, a method for solving the problem. For AES, Eve's key search.
Certificate
In Redux, a proposed answer that can be checked. For AES, the key and the message.
Quantum computer
A computer that uses the rules of tiny particles. It speeds up searching, but only to about the square root of the number of tries.
Problem
AES (Problems/NPComplete/NPC_AES/), page /AES. Declared complexity class NP; problem type AlgebraAndNumberTheory.
Instance
(keyHex,k,"TEXT") (message mode, 1 to 15 letters and spaces) or (knownKeyHex,k,plaintextHex,ciphertextHex) (Eve's view, last k bits zero); keys and blocks 32 hex digits; 1 ≤ k ≤ 20. Default (2b7e151628aed2a6abf7158809cf4f3c,8,"Hello World").
Cipher
AES-128 from FIPS 197, one block; message mode pads with PKCS#7.
Certificate
The full key, agreeing with the known bits; in message mode (keyHex,"TEXT") (any case).
Solver
AES Brute Force Key Search: x = 0 ... 2k − 1, accept when the decryption parses as a padded message (or AESK'(P) = C); O(2k).
Visualizations
AES Attacker Knowledge Table (missing bits, full key, message); AES Round-by-Round Encryption (41 frames of the 4×4 state, changed bytes highlighted).
Verifier
Default AES Verifier: known bits agree, then one encryption compared with C.
Sources
NIST (2001, updated 2023). Advanced Encryption Standard (AES). FIPS PUB 197. Daemen, J., and Rijmen, V. (2002). The Design of Rijndael. Springer. Grover, L. K. (1996). A fast quantum mechanical algorithm for database search. Proc. 28th ACM STOC, 212–219.