In this blog, we will discuss one of the cryptographic methods or techniques known as the stream cipher. We will discuss some crucial factors in the stream cipher and implement a mathematical example to demonstrate the stream cipher logic.
But before that, let's discuss the term cryptography in brief.
Cryptography
Cryptography is one of the subjects in computer science that focus on secure communication between the sender and receiver and also discusses the methods we can use to secure digital data like digital signature uploaded on the internet.
With cryptography, we do not need to worry about the confidentiality and integrity of the data during transmission.
There are mainly three types of cryptography techniques.
Public key or symmetric key cryptography
Secret key or asymmetric key cryptography
Hash functions
Stream Cipher
Before discussing stream cipher, you need to know a few terms we will frequently use during the explanation.
Plaintext: The normal text we will convert into a non-readable format.
Ciphertext: The text we will generate after converting the plain text by applying cryptography techniques.
Key: A key is a string of characters or bits that helps us convert plain text into cipher text and is only known to the sender and receiver.
Encryption: Encryption converts plain text into cipher text with the help of a secret key.
Decryption: Decryption converts cipher text into normal or plain text with the help of a secret key.
Now let's discuss the stream cipher. A stream cipher is a symmetric cryptography technique that converts plain text into cipher text with the help of a keystream. A keystream is a randomly generated string or bits that will help us to convert the plain text into ciphertext. In a stream cipher, the encryption will be applied on a single bit at a time, meaning if the sender sends a 6-bit message, then each of the bits has to go through the encryption.
0
1
1
0
1
1
There are two types of stream cipher.
Synchronous stream cipher
Self-Synchronous stream cipher
Synchronous Stream Cipher
In a synchronous stream cipher, the plaintext will be combined or encrypted with the independently generated pseudorandom keystream.
Self-Synchronous Stream Cipher
In the self-synchronous stream cipher, the keystream will be generated along with some bits of the cipher text. The reason for doing this is to avoid any tampering with the message stream or ciphertext. If the message stream has been tampered with by someone, the receiver can detect it by comparing the cipher text and keystream.
Keystream
Keystream or secret key is the most crucial part of the stream cipher. A keystream you will use must be confidential except for the sender and receiver. In a stream cipher, mostly the keystream is the same as the size of the plaintext, and it is beneficial because it is not easy for an attacker to generate the keystream.
But what if your plain text is large, like 200KB or more than that?
Well, in this case, you can choose a key with some fixed amount, for example, 30 KB, and the rest you can generate with the help of a Keystream generator but remember the keystream generator has to be completely random and will not follow a fixed pattern for the generation.
Example
In the stream cipher, the XOR operation will be applied on the plain text and keystream to generate the cipher text. When we use an XOR operation between two bits, it follows some rules.
XOR Operation
Bit 1
Bit 2
Resultant Bit
0
0
0
0
1
1
1
0
1
1
1
0
If you apply XOR on two separate bits and they are the same, then the resultant bit will be 0, and if they are 0 and 1 or 1 and 0, then resulting bit will be 1.
Now let's apply the XOR operation on plaintext in the binary format.
As you can see in the image, we have used the XOR operation on the plaintext and keystream and generated a random ciphertext.
Let's see a more particle example of the stream cipher.
In the above image, we have used the XOR calculator, an online website. As Input 1, we have given some text; as INPUT 2, we have given a completely random key in hexadecimal format.
As a result, we have generated a cipher text in hexadecimal format. Keep in mind that INPUT 2 is randomly generated, and changing it will affect the output.
Now, let's decrypt the cipher text.
As you can see, we got the same plaintext we entered after applying the XOR on ciphertext and Keystream. I hope now you have a more precise understanding of stream cipher.
Advantages of Stream Cipher
The benefit of a stream cipher is that it typically operates faster and with much less code than block ciphers because it does not require block ciphers as a building block.
It encrypts one bit at a time.
More 1s and 0s can be added to a keystream to increase its efficiency and make cryptanalysis more challenging.
It can be a great cipher when to want to send a stream of data to a destination.
There are two types of stream cipher: Synchronous and Asynchronous stream cipher.
Does stream cipher encrypts a block of data at a time?
Stream cipher encrypted one bit at a time.
Why do we use XOR operation in stream cipher?
XOR uses less computational power to encrypt or decrypt the message.
What type of cryptography techniques is applied to the steam cipher?
Stream cipher follows symmetric key encryption means the sender and receiver both have a mutual secret key.
Conclusion
In this blog, we have discussed the Stream cipher and different cryptography terms. We have also discussed an example to demonstrate the working of a stream cipher, and in the end, we have mentioned the advantages of stream cipher.
To learn more about cryptography, check out the following articles.