A stream cipher is a symmetric key encryption algorithm that encrypts plaintext data one bit or byte at a time by combining it with a pseudorandom keystream. Each bit or byte of plaintext is processed individually, typically using the exclusive-or (XOR) operation with the corresponding bit or byte from the keystream, resulting in ciphertext that is unreadable without the correct key.
How Stream Ciphers Work
• Key and Keystream Generation: A secret key (sometimes with an initialization vector, IV) is used to generate a pseudorandom keystream. This keystream must be as long as the message for perfect security (as in a one-time pad), but in practice, cryptographic algorithms expand a shorter key into a longer keystream.
• Encryption: Each bit (or byte) of plaintext is combined with the corresponding bit (or byte) of the keystream using XOR. This produces the ciphertext.
• Decryption: The process is reversed—XORing the ciphertext with the same keystream retrieves the original plaintext. The same key is used for both encryption and decryption, making it a symmetric cipher.
Types of Stream Ciphers
• Synchronous Stream Ciphers: The keystream is generated independently of the plaintext and ciphertext. Both sender and receiver must remain synchronized; if synchronization is lost, decryption fails until resynchronization occurs.
• Self-Synchronizing Stream Ciphers: The keystream generation depends on previous ciphertext digits, allowing the system to recover from synchronization errors after a short period.