Every symmetric cipher scrambles data with a key. The difference between a stream cipher and a block cipher is really a difference in how much data gets combined with the key at once — and the XOR gate is where that combination actually happens.
Before XOR, a quick refresher on the two basic logic gates it's usually taught alongside. Both take two bits and produce one — the difference is in which combinations of inputs produce a 1.
Output is 1 only when A and B are both 1.
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Output is 1 when A or B (or both) is 1.
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
XOR ("exclusive or") outputs 1 when its two inputs differ, and 0 when they match. That single rule is the engine behind most symmetric ciphers: it's cheap to compute, and — critically — applying the same key bits a second time undoes the first pass.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Both approaches use a secret key to turn plaintext into ciphertext. They differ in whether they process the message continuously or in fixed-size chunks. Try both panels below.
A keystream generator produces an endless run of pseudorandom bits from the key. Each bit of plaintext is combined with the matching keystream bit — usually with XOR — the instant it arrives.
The message is split into fixed-size blocks. Each full block is transformed through several rounds of substitution and permutation, keyed by the secret. Short final blocks get padded.
Repeat the key to match the length of the message, XOR each character byte-for-byte, and the result is your ciphertext. Run the exact same XOR a second time with the same key, and you get the plaintext back — that's what "symmetric" means in practice.