RC4 Encryption Algorithm
RC4 Encryption Algorithm
Example:
RC4 Encryption:
10011000? 01010000=11001000
RC4Decryption
11001000? 01010000 = 10011000
Key-Generation Algorithm –
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.
Key-Scheduling Algorithm(KSA):
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 Pseudo random
generation algorithm (Stream Generation)
Pseudo random generation algorithm (Stream Generation):
PRGA is the actual Keystream. Once the vector S is initialized, the input key
will not be used. In this step, for each S[i] algorithm swap it with another byte in
S according to a scheme dictated by the current configuration of S. After reaching
S[255] the process continues, starting from S[0] again
Working of RC4:
Encryption Procedure
1. The user inputs a plain text file and a secret key.
2. The encryption engine then generates the keystream by using KSA and PRGA
Algorithm.
3. This keystream is now XOR with the plain text, this XORing is done byte by
byte to produce the encrypted text.
4. 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
Features of the RC4 encryption algorithm:
3. Variable key size: RC4 supports variable key sizes, from 40 bits to 2048 bits,
making it flexible for different security requirements.
4. Fast and efficient: RC4 is a fast and efficient encryption algorithm that is
suitable for low-power devices and applications that require high-speed data
transmission.
5. Widely used: RC4 has been widely used in various applications, including
wireless networks, secure sockets layer (SSL), virtual private networks (VPN),
and file encryption.
Advantages:
1. Fast and efficient: RC4 is a very fast and efficient encryption algorithm,
which makes it suitable for use in applications where speed and efficiency are
critical.
4. Widely used: RC4 has been widely used in various applications, including
wireless networks, secure sockets layer (SSL), virtual private networks (VPN),
and file encryption.
Disadvantages:
2. Security weaknesses: RC4 has some inherent weaknesses in its design, which
make it less secure than other encryption algorithms, such as AES .
3. Limited key length: The maximum key length for RC4 is 2048 bits, which
may not be sufficient for some applications that require stronger encryption.
5. If RC4 is not used with strong MAC then encryption is vulnerable to a bit-
flipping attack.
6. RC4 stream ciphers do not provide authentication.
9. RC4 fails to discard the beginning of output keystream or fails to use non-
random or related keys for the algorithm.
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.
1. 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).
2. RC4A: Souraduyti Paul and Bart Preneel have proposed an RC4 variant,
which they call RC4A, which is stronger than RC4.
3. VMPC: VMPC is another variant of RC4 which stands for Variably Modified
Permutation Composition.