RC4 algorithm RC4 encryption algorithm is the famous RSA trio of the number one figure Ron Rivest in 1987 designed the key length of the variable stream encryption algorithm cluster. RC4 algorithm is a kind of encryption technology in the field of electronic information, used in wireless communication network, is an electronic password, only authorized (pay the corresponding fee) users can enjoy the service.
RC4, proposed in 1987, is a symmetric encryption algorithm, which means that the key used is a single key (or private key). RC4 does not group the plaintext, but instead encrypts each byte in the plaintext in turn, and decrypts every byte in the ciphertext in turn.
RC4 algorithm is characterized by simple algorithm, fast running speed, and the key length is variable, variable range of 1-256 bytes (8-2048 bits), under the premise of today's technology support, when the key length is 128 bit, the brute force method to search for the key is not feasible, So it is foreseeable that the key range of the RC4 can withstand brute force search key attacks for a considerable amount of time in the future. In fact, no effective attack method for the RC4 encryption algorithm for 128bit key length is found today
/* $PWD secret key;
$data the data to encrypt
*/
Public function RC4 ($PWD, $data)
{
$cipher = ";
$key [] = "";
$box [] = "";
$pwd _length = strlen ($PWD);
$data _length = strlen ($data);
for ($i = 0; $i < $i + +) {
$key [$i] = Ord ($pwd [$i% $pwd _length]);
$box [$i] = $i;
}
for ($j = $i = 0; $i < $i + +) {
$j = ($j + $box [$i] + $key [$i])% 256;
$tmp = $box [$i];
$box [$i] = $box [$j];
$box [$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $data _length; $i + +) {
$a = ($a + 1)% 256;
$j = ($j + $box [$a])% 256;
$tmp = $box [$a];
$box [$a] = $box [$j];
$box [$j] = $tmp;
$k = $box [(($box [$a] + $box [$j])% 256)];
$cipher. = Chr (ord ($data [$i]) ^ $k);
}
return $cipher;
}
If you decrypt it, call the method again.
Implementing RC4 encryption and decryption in PHP