SoFunction
Updated on 2025-03-03

Detailed explanation of the key variables and algorithm characteristics of RC4 encryption

What is RC4

The RC4 encryption algorithm is a cluster of stream encryption algorithms with variable key length designed by Ron Rivest in 1987, designed by the top RSA trio. The RC4 algorithm is a technical means of encryption in the field of electronic information. It is used in wireless communication networks and is an electronic password that only authorized users can enjoy the service.

RC4 stream cipher is one of the most widely used stream ciphers, which encrypt messages bytes at a time by algorithms, which are simple and fast to operate. RC4 is a technical means of encryption in the field of electronic information. It is used in wireless communication networks. It is an electronic password that only authorized users can enjoy the service, using 64-bit or 128-bit key sizes. It is commonly used in applications such as Secure Sockets Layer (SSL), Transport Layer Security (TLS), and is also used in the IEEE 802.11 wireless LAN standard.

RC4 encryption is a typical symmetric encryption algorithm.

Features of RC4 algorithm

(1) The algorithm is simple and easy to implement with software, with fast encryption speed and relatively high security;

(2) The key length is variable, generally 256 bytes.

Several key variables for RC4 encryption

1、Key Stream: The key of the RC4 algorithm is to generate corresponding key streams based on the plaintext and keys. The length of the key stream corresponds to the length of the plaintext, that is, the length of the explanatory text is 500 bytes, and the key stream is also 500 bytes. Of course, the encryption generated ciphertext is also 500 bytes, becauseciphertext i-th byte = plaintext i-th byte^ key stream i-th byte

2、State vector S: The length is 256, S[0], S[1]....S[255]. Each unit is a byte. At any time the algorithm runs, S includes an 8-bit arrangement combination of 0-255, except that the position of the value is changed;

3、Temporary vector T: The length is also 256, and each unit is also one byte. If the length of the key is 256 bytes, the value of the key is assigned to T directly, otherwise, each byte of the key is assigned to T in a rotation manner;

4、Key K: The length is 1-256 bytes. Note that the length of the keylen has no necessary relationship with the length of the plaintext and the length of the key stream. Usually, the length of the key is taken as 16 bytes (128 bits).

RC4 encryption principle

1. Initialize S and T

for i=0 to 255 do
   S[i] =i;
   T[i]=K[ imodkeylen ];

2. Initial arrangement S

for i=0 to 255 do
   j= ( j+S[i]+T[i])mod256;
   swap(S[i],S[j]);

3. Generate a key stream

for r=0 to len do  //r is the length of the plain text, r byte   i=(i+1) mod 256;
   j=(j+S[i])mod 256;
   swap(S[i],S[j]);
   t=(S[i]+S[j])mod 256;
   k[r]=S[t];

By knowing the principle of RC4 encryption, you can write encrypted or decrypted scripts based on the specific situation

The above is a detailed explanation of the characteristics and principles of RC4 encryption key variables and algorithms. For more information about RC4 encryption key variable algorithms, please pay attention to my other related articles!