# Encryption and Decryption with Stream Ciphers

This blog will introduce the first type of the symmetric cipher, which is known as “Stream Ciphers“.

The figure below shows the encryption and decryption process in stream ciphers:

Note: Plaintext = xi, Ciphertext = yi & key stream = si.

Encryption and decryption are same functions, where they are simple additions modulo 2 (XOR).

 Encryption: yi = esi(xi) = xi + si mod 2 Decryption: xi = dsi(yi) = yi + si mod 2

Note: xi , yi & si ∈ {0,1}.

The question is – What is the difference between the key (k) and the key stream (s)The key is used to encrypt and decrypt the message and it is only known only by the sender and the receiver. The key stream, on the other hand, is the result of the XORed key and generated from the original key. Usually, the original key goes through a process called “key stream generator” to generate the key stream.

Before we get deep into the process of key stream generator, let’s have a look at the of XOR operation. XOR operation is equivalent to modulo 2 addition. This is good for perfectly random key stream (si), where each ciphertext output bit has a chance of 50% to be either (0 or 1). Also, inverting the XOR is simple, since it is the same XOR operation.

The figure below shows the process of generating the key stream.

The security of stream cipher depends entirely on the key stream (si), where it should be:

• Should be random.
• Must be reproducible by sender and receiver.

Stream ciphers can be either Synchronous Stream Cipher or Asynchronous Stream Cipher. The difference is that the Synchronous Stream Cipher the key stream (si) depends only on the key (k). However, Asynchronous Stream Cipher the key stream (si) depends on both the key (k) and the ciphertext.