Short answer: AES encrypts a 16-byte block. AES-128 expands a 16-byte key into eleven round keys and runs ten rounds. Each of the first nine rounds is SubBytes, ShiftRows, MixColumns, and AddRoundKey. The last round skips MixColumns. The FIPS 197 key 000102030405060708090a0b0c0d0e0f and plaintext 00112233445566778899aabbccddeeff encrypt to 69c4e0d86a7b0430d8cdb78070b4c55a.
What the problem actually asks
A block cipher has to be a keyed permutation of fixed-size blocks. AES fixes the block at 16 bytes. The public structure is a substitution-permutation network. The secret is the key. The 16 state bytes are stored in column-major order: index 4 * c + r is row r of column c. ShiftRows and MixColumns are defined on that layout. A message longer than 16 bytes is not one AES input. A mode of operation is what chains blocks, and an authenticator is what detects a changed ciphertext.
What the algorithm guarantees
For each 16-byte key, AES-128 is one permutation of the 16-byte strings. SubBytes applies an S-box that inverts the byte in GF(2^8), using the irreducible x^8 + x^4 + x^3 + x + 1, and then applies the AES affine map and the constant 0x63. ShiftRows rotates row r left by r bytes. MixColumns multiplies each column by the fixed polynomial whose bytes are 2, 3, 1, and 1, modulo x^4 + 1. The key schedule produces 176 bytes. None of that says two equal plaintext blocks hide their equality, and none of it rejects a modified ciphertext.
The working steps
- Build the S-box from the field inverse and the affine map.
- Expand the key. Every fourth word is rotated, passed through the S-box, and xored with the round constant. Xor it with the word 16 bytes earlier. The other words are the previous word xored with the word 16 bytes earlier.
- Xor the first round key into the state.
- Nine times, apply SubBytes, ShiftRows, MixColumns, and the next round key.
- Finish with SubBytes, ShiftRows, and the last round key. Read the state out in the same column-major order.
Approaches that look simpler and fail
| Approach | Why it fails for a message longer than one block |
|---|---|
| Encrypt each 16-byte piece on its own with the same key | Equal pieces stay equal. That is ECB, and it is not a message encryption. |
| Skip MixColumns on the early rounds | Column mixing is the step that spreads one byte across the other bytes of the column. Dropping it defines a different permutation. |
| Store the state row by row | ShiftRows and MixColumns index columns. The transposed state does not produce the FIPS ciphertext. |
| Treat the block permutation as a message format | A permutation has no nonce, no length, and no tag. A mode and an authenticator carry a message. |
Cipher block chaining, counter mode, and GCM are ways to use this permutation on more than one block. AES is the permutation.
A working example
This Python fragment builds the S-box, expands the FIPS 197 key, and encrypts the FIPS 197 block. It prints 69c4e0d86a7b0430d8cdb78070b4c55a.
def _xtime(a: int) -> int:
return ((a << 1) ^ 0x1B) & 0xFF if a & 0x80 else (a << 1) & 0xFF
def _gmul(a: int, b: int) -> int:
p = 0
for _ in range(8):
if b & 1:
p ^= a
a = _xtime(a)
b >>= 1
return p
def _sbox() -> list[int]:
box = []
for x in range(256):
inv = 0 if x == 0 else next(i for i in range(1, 256) if _gmul(x, i) == 1)
y = 0
for i in range(8):
bit = (inv >> i) ^ (inv >> ((i + 4) % 8)) ^ (inv >> ((i + 5) % 8))
bit ^= (inv >> ((i + 6) % 8)) ^ (inv >> ((i + 7) % 8)) ^ (0x63 >> i)
y |= (bit & 1) << i
box.append(y)
return box
_S = _sbox()
def aes128_encrypt(block: bytes, key: bytes) -> bytes:
words = list(key)
rcon = 1
while len(words) < 176:
t = words[-4:]
if len(words) % 16 == 0:
t = t[1:] + t[:1]
t = [_S[b] for b in t]
t[0] ^= rcon
rcon = _xtime(rcon)
earlier = words[-16:-12]
words.extend(earlier[i] ^ t[i] for i in range(4))
state = list(block)
def add(rnd: int) -> None:
rk = words[rnd * 16 : (rnd + 1) * 16]
for i in range(16):
state[i] ^= rk[i]
def sub() -> None:
for i in range(16):
state[i] = _S[state[i]]
def shift() -> None:
for r in range(1, 4):
row = [state[r + 4 * c] for c in range(4)]
row = row[r:] + row[:r]
for c in range(4):
state[r + 4 * c] = row[c]
def mix() -> None:
for c in range(4):
col = state[4 * c : 4 * c + 4]
state[4 * c] = _gmul(col[0], 2) ^ _gmul(col[1], 3) ^ col[2] ^ col[3]
state[4 * c + 1] = col[0] ^ _gmul(col[1], 2) ^ _gmul(col[2], 3) ^ col[3]
state[4 * c + 2] = col[0] ^ col[1] ^ _gmul(col[2], 2) ^ _gmul(col[3], 3)
state[4 * c + 3] = _gmul(col[0], 3) ^ col[1] ^ col[2] ^ _gmul(col[3], 2)
add(0)
for rnd in range(1, 10):
sub()
shift()
mix()
add(rnd)
sub()
shift()
add(10)
return bytes(state)
key = bytes.fromhex("000102030405060708090a0b0c0d0e0f")
block = bytes.fromhex("00112233445566778899aabbccddeeff")
cipher = aes128_encrypt(block, key)
assert cipher.hex() == "69c4e0d86a7b0430d8cdb78070b4c55a"
print(cipher.hex())
Where it is used
TLS, LUKS, BitLocker, and FileVault encrypt with AES. WPA2 and WPA3 use it as well. A message longer than one block uses a mode such as GCM; the ten-round map is only the permutation.
When you can drop this algorithm
Drop AES as a format for a message. Keep AES-128 as the 16-byte permutation inside a mode that uses each nonce once and, wherever a modified ciphertext must be rejected, an authenticator.
Why this stays published
We publish this so a search for AES returns the ten-round structure and the FIPS 197 ciphertext. AES-128 expands a 16-byte key into eleven round keys and encrypts one column-major block in ten rounds, skipping MixColumns only on the last round.
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
