RC4 means Rivest Cipher 4 invented by Ron Rivest in 1987 for RSA Security. It is a Stream Ciphers. Stream Ciphers operate on a stream of data byte by byte. RC4 stream cipher is one of the most widely used stream ciphers because of its simplicity and speed of operation. It is a variable key-size stream cipher with byte-oriented operations. It uses either 64 bit or 128-bit key sizes. It is generally used in applications such as Secure Socket Layer (SSL), Transport Layer Security (TLS), and also used in IEEE 802.11 wireless LAN std.
Why Encryption Is Important?
Unauthorized data access can be prevented by encryption. If we perform encryption then third parties can not have access to data which we share or receive. The encryption is done by using a secret key, or we can say that by using a public key and private key. Both sender and receiver are having their public key and private key through which encryption of plain text and decryption of ciphertext is performed.
History of RC4 Encryption
RC4 was designed by Ron Rivest in 1987. He was working under RSA Security. Rivest Cipher 4 is an official name while it is also known as Ron’s Code. Initially, RC4 was trade secret but once it’s code spread in the public domain it was no more a trade secret. While Ron did not reveal the RC4 algorithm until 2014 when he described the history of RC4 in English Wikipedia.
Applications of RC4
RC4 is used in various applications such as WEP from 1997 and WPA from 2003. We also find applications of RC4 in SSL from 1995 and it is a successor of TLS from 1999. RC4 is used in varied applications because of its simplicity, speed, and simplified implementation in both software and hardware.
Types of RC4
There are various types of RC4 such as Spritz, RC4A, VMPC, and RC4A.
- SPRITZ: Spritz can be used to build a cryptographic hash function, a deterministic random bit generator (DRBG), n an encryption algorithm that supports authenticated encryption with associated data (AEAD).
- RC4A: Souraduyti Paul and Bart Preneel have proposed an RC4 variant, which they call RC4A, which is stronger than RC4.
- VMPC: VMPC is another variant of RC4 which stands for Variably Modified Permutation Composition.
- RC4A+: RC4A+ is a modified version of RC4 with a more complex three-phase key schedule which takes about three times as long as RC4 and a more complex output function which performs four additional lookups in the S array for each byte output, taking approximately 1.7 times as long as basic RC4.
Algorithm
The algorithm operates on a user-selected variable-length key(K) of 1 to 256 bytes (8 to 2048 bits), typically between 5 and 16 bytes. To generate a 256-byte state vector S, the master key is used.
The first step is the array initialization. It is a character array of size 256 i.e. S[256]. After that, for every element of the array, we initialize S[i] to i.
Code for array initialization:
Char S[256];
int i;
for(i=0;i<256;i++)
S[i] = i
The array will look like -
S[] = {0, 1, 2, 3, ------, 254, 255}
After this, we will run the KSA algorithm-
KSA is going to use the secret key to scramble this array. KSA is a simple loop, in which we are having two variable i and j. We are using these variables to rearrange the array. Rearranging the array is done by using a secret key.
Code for KSA (Key Scheduling Algorithm ) :
int i, j=0;
for(i=0;i<256;i++)
{
j=( j + S[i] + T[i]) mod 256;
Swap(S[i], S[j]);
}
KSA has been scrambled, S[256] array is used to generate the PRGA(Pseudo Random Generation Algorithm). This is the actual Keystream.
Code for PRGA ( Pseudo Random Generation Algorithm ):
i=j=0;
while(true)
{
i = ( i + 1 ) mod 256;
j = ( j + S[i] ) mod 256;
Swap( S[i], S[j] );
t = ( S[i] + S[j] ) mod 256 ;
k = S[t];
}
This is the next step of scrambling.
RC4 Block Diagram

Working of RC4
Encryption Procedure
- The user inputs a plain text file and a secret key.
- The encryption engine then generates the keystream by using KSA and PRGA Algorithm.
- This keystream is now XOR with the plain text, this XORing is done byte by byte to produce the encrypted text.
- The encrypted text is then sent to the intended receiver, the intended receiver will then decrypted the text and after decryption, the receiver will get the original plain text.
Decryption Procedure
Decryption is achieved by doing the same byte-wise X-OR operation on the Ciphertext.
Example: Let A be the plain text and B be the keystream (A xor B) xor B = A
Advantages
- RC4 stream ciphers are simple to use.
- The speed of operation in RC4 is fast as compared to other ciphers.
- RC4 stream ciphers are strong in coding and easy to implement.
- RC4 stream ciphers do not require more memory.
- RC4 stream ciphers are implemented on large streams of data.
Disadvantages
- If RC4 is not used with strong MAC then encryption is vulnerable to a bit-flipping attack.
- RC4 stream ciphers do not provide authentication.
- RC4 algorithm requires additional analysis before including new systems.
- RC4 stream ciphers cannot be implemented on small streams of data.
- RC4 fails to discard the beginning of output keystream or fails to use non-random or related keys for the algorithm.
Similar Reads
What is RC4 Encryption?
RC4 means Rivest Cipher 4 invented by Ron Rivest in 1987 for RSA Security. It is a Stream Ciphers. Stream Ciphers operate on a stream of data byte by byte. RC4 stream cipher is one of the most widely used stream ciphers because of its simplicity and speed of operation. It is a variable key-size stre
5 min read
What is Data Encryption?
Data encryption is the process of converting readable information (plaintext) into an unreadable format (ciphertext) to protect it from unauthorized access. It is a method of preserving data confidentiality by transforming it into ciphertext, which can only be decoded using a unique decryption key p
10 min read
What is RPC Enumeration?
RPC is a remote procedure call (or a function call that carries out tasks on a different computer). RPC enumeration is the process of discovering what services are running on what port numbers. Enumerating RPC services can aid in finding information leaks because it allows an attacker to map which s
3 min read
What is an Encrypted Virus?
Encrypting viruses are a type of computer virus that can cause significant issues if they are identified. The entire world relies on computer systems for daily operations. Encrypting viruses are considered among the most dangerous because once your device is infected, it may begin encrypting all cri
9 min read
What is E2EE(End to End Encryption)?
E2EE or End to End Encryption refers to the process in which encryption of data are being done at the end host. It is an implementation of Asymmetric encryption and hence ensures a secure way of data communication. It is the most secure way to communicate privately and securely as data can be read-o
3 min read
What is Nonce in Cryptography?
Nonce is a random number used once in cryptographic communication meaning “number once” in the world of cryptocurrency. This randomly generated number is created to keep communication private and protect against replay attacks. The term "nonce" stands for "number used once." Nonces are important bec
8 min read
What is Remote Code Execution (RCE)?
Nowadays the popularity of web applications is growing faster because of the fulfilling requirements of the business and satisfying the needs of consumers. There are several services that are provided through web applications and their performance are measured through the services processing time an
4 min read
SQL Data Encryption
In today’s digital era, data security is more critical than ever, especially for organizations storing the personal details of their customers in their database. SQL Data Encryption aims to safeguard unauthorized access to data, ensuring that even if a breach occurs, the information remains unreadab
5 min read
Homomorphic Encryption.
In an age wherein information is regularly referred to as the new oil, shielding its confidentiality and integrity has come to be paramount. Traditional encryption techniques have been effective at safeguarding records at relaxation and in transit, but what if you could perform complex computations
7 min read
Data Encryption and Security in R
Data encryption and security are crucial aspects of data management and analysis, especially when dealing with sensitive information. R is a powerful statistical programming language, that provides various packages and functions to ensure data security through encryption, secure storage, and secure
3 min read
What Is CRAN In R Language?
CRAN (Comprehensive R Archive Network) is the primary repository for R packages, and it hosts thousands of packages that users can download and install to extend the functionality of the R Programming Language. These packages are created by R users and developers from around the world and cover a wi
4 min read
What is Privacy Enhancing Computation?
The technological advancement that has characterized the modern world has produced numerous privacy dangers. As the use of data continues to grow security and privacy of information are critical for any organization. Privacy-enhancing computation is one of the most effective approaches that is used
9 min read
What is Round Cipher?
Round ciphers are also known as block ciphers, and they are a classification of encryption algorithms that work systematically, converting the plaintext into ciphertext. These algorithms work on a limited number of bits at a time and subject them to a set of mathematical processes called rounds whic
10 min read
Twofish Encryption Algorithm
When it comes to data protection, encryption methods act as our buffering agents. One example of an excellent block cipher is the Twofish encryption algorithm. Although it was a competitor of another block cipher in the Advanced Encryption Standard competition and was later succeeded by the latter,
6 min read
What is Cipher?
Ciphers are the most vital components of cryptography, as it is through them that the protection of information is made possible in the ever-growing digital environment. In the present generation, given the technological advancement especially in the field of communication, the aspect of security is
7 min read
What is Expansion Permutation in Cryptography?
Cryptography is very vital today especially in the field of Information Technology in the aspect of transmitting information. There are many varied techniques in modern cryptography and one of those widely adopted in many deterministic algorithms is the expansion permutation, which is widely used in
7 min read
What is Multiplicative Cipher in Cryptography?
A multiplicative cipher is a type of cipher that comes under a monoalphabetic cipher, in which each letter that is present in the plaintext is replaced by a corresponding letter of the ciphertext, according to a fixed multiplication key. In this article, we will learn about the multiplicative cipher
9 min read
What is RARP?
The Reverse Address Resolution Protocol (RARP) is a networking protocol that is used to map a physical (MAC) address to an Internet Protocol (IP) address. It is the reverse of the more commonly used Address Resolution Protocol (ARP), which maps an IP address to a MAC address. In this article, we wil
6 min read
What is IPv4?
IP stands for Internet Protocol version v4 stands for Version Four (IPv4), is the most widely used system for identifying devices on a network. It uses a set of four numbers, separated by periods (like 192.168.0.1), to give each device a unique address. This address helps data find its way from one
5 min read