Keystream facts for kids
Imagine you have a secret message you want to send. In cryptography, which is the study of secret codes, a keystream is like a special, random list of characters. This list is mixed with your original message (called the plaintext) to turn it into a secret, coded message (called the ciphertext).
These characters can be tiny pieces of data like bits or bytes, or even numbers and letters (like A, B, C). It depends on how the secret code works.
To make the secret message, each character from the keystream is usually added to, subtracted from, or combined in a special way (called XORing) with a character from your original message. This mixing often uses a math trick called modular arithmetic.
Keystreams are very important in secret coding. They are used in the one-time pad cipher, which is known for being very secure. They are also used in most stream ciphers. Even Block ciphers can create keystreams. For example, a method called CTR mode can make a block cipher act like a stream cipher by producing a keystream.
How Keystreams Work
A keystream helps scramble your message. Think of it like a secret key that changes for each letter or part of your message.
An Example: Secret Messages
Let's look at a simple example using only the 26 letters of the English alphabet (a-z). We will ignore numbers, spaces, or other symbols for this. Each letter can be turned into a number from 0 to 25 (a=0, b=1, ..., z=25).
To encrypt your message, you add the numbers from the keystream to the numbers of your plaintext message. To decrypt (unscramble) it, you subtract the same keystream numbers from the secret ciphertext numbers.
Sometimes, when you add numbers, they might go over 25. If this happens, we "wrap" the number around. For example, if 26 becomes 0, 27 becomes 1, and so on. This "wrapping around" is what modular arithmetic means.
Here's how the message "attack at dawn" becomes "kcvniwlabluh" using the keystream "kjcngmlhylyu":
Plaintext | a | t | t | a | c | k | a | t | d | a | w | n |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Plaintext as numbers | 0 | 19 | 19 | 0 | 2 | 10 | 0 | 19 | 3 | 0 | 22 | 13 |
Keystream | k | j | c | n | g | m | l | h | y | l | y | u |
Keystream as numbers | 10 | 9 | 2 | 13 | 6 | 12 | 11 | 7 | 24 | 11 | 24 | 20 |
Ciphertext as numbers | 10 | 28 | 21 | 13 | 8 | 22 | 11 | 26 | 27 | 11 | 46 | 33 |
Ciphertext as numbers wrapped to 0-25 |
10 | 2 | 21 | 13 | 8 | 22 | 11 | 0 | 1 | 11 | 20 | 7 |
Ciphertext as text | k | c | v | n | i | w | l | a | b | l | u | h |
See also
In Spanish: Flujo de claves para niños