0Pricing
Cryptology Academy · Lesson

XOR Inside AES & Stream Ciphers

Trace how XOR is used inside real encryption algorithms.

XOR Inside AES & Stream Ciphers is a free Cryptology Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome

XOR is a fundamental building block inside every modern cipher. In this lesson we trace how XOR appears in AES AddRoundKey and stream cipher keystream mixing.

XOR in AES: AddRoundKey

AES has 10–14 rounds. Every round starts with AddRoundKey: the 16-byte state is XORed with the 16-byte round key. This is the only step that actually introduces the secret key.

AES Round Key Derivation

The original 128/192/256-bit key is expanded into 11/13/15 round keys via the key schedule. Each AddRoundKey step uses a different derived round key.

Why XOR Works Inside AES

In AES, XOR occurs inside GF(2^8) arithmetic. The surrounding nonlinear operations (SubBytes, MixColumns) give XOR the diffusion and confusion properties Claude Shannon described.

Stream Cipher Keystream

A stream cipher generates a pseudorandom keystream from a key and nonce: keystream = CSPRNG(key, nonce) ciphertext = plaintext XOR keystream ChaCha20 produces keystream in 64-byte blocks using its quarter-round function.

ChaCha20 Quarter Round

ChaCha20's mixing function: a += b; d ^= a; d <<<= 16 c += d; b ^= c; b <<<= 12 a += b; d ^= a; d <<<= 8 c += d; b ^= c; b <<<= 7 XOR (^) and rotation (<<<) are the key operations.

Nonce & Counter in Stream Ciphers

ChaCha20 takes: 256-bit key + 96-bit nonce + 32-bit counter. Different counters produce different keystream blocks. Reusing (key, nonce) pair is catastrophic — never do it.

AES-CTR Mode: Block Cipher as Stream Cipher

AES-CTR encrypts successive counter values with AES, then XORs the result with plaintext. This turns AES (a block cipher) into a stream cipher, enabling arbitrary-length output.

XOR in OFB and CFB Modes

OFB: keystream = AES(AES(AES(IV)...)). Plaintext XOR keystream = ciphertext. CFB: ciphertext block = plaintext XOR AES(previous_ciphertext). Both use XOR as the mixing step.

Confusion & Diffusion via XOR + S-Box

Shannon's confusion: S-boxes (SubBytes) make key-ciphertext relationship complex. Diffusion: ShiftRows+MixColumns spread each byte's influence. XOR glues both with the key.

Never Roll Your Own Crypto

Understanding XOR's role teaches why amateur cipher designs fail: they use XOR without nonlinear layers. Without S-boxes and diffusion, XOR-based ciphers are algebraically trivial to break.

Quick Check

Which AES operation directly XORs the state with the round key?

Recap

You now understand XOR's role inside real ciphers. Next we study hash functions — starting from MD5 through SHA-256.

Frequently asked questions

Is the “XOR Inside AES & Stream Ciphers” lesson free?

Yes — the full text of “XOR Inside AES & Stream Ciphers” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “XOR Inside AES & Stream Ciphers”?

Trace how XOR is used inside real encryption algorithms. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “XOR Inside AES & Stream Ciphers” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Bitwise Operations Refresher
  2. XOR Encryption & the One-Time Pad
  3. Why XOR Alone Is Not Secure
  4. XOR Inside AES & Stream Ciphers
← Back to Cryptology Academy