<?php
function RC4($key, $pt)
{
$s = array();
for ($i=0; $i<256; $i++) {
$s[$i] = $i;
}
$j = 0;
$key_len = strlen($key);
for ($i=0; $i<256; $i++) {
$j = ($j + $s[$i] + ord($key[$i % $key_len])) % 256;
//swap
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
}
$i = 0;
$j = 0;
$ct = ‘‘;
$data_len = strlen($pt);
for ($y=0; $y< $data_len; $y++) {
$i = ($i + 1) % 256;
$j = ($j + $s[$i]) % 256;
//swap
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
$ct .= $pt[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
}
return $ct;
}
$text = ‘This is a test string.‘;
$md5 = md5(‘password‘);
echo $md5 . "\n";
$key = pack(‘H*‘, $md5); //嫌的话,让 $key = ‘testkey‘; 试试
print bin2hex(RC4($key, $text));
echo "\n";
echo bin2hex(openssl_encrypt($text, "RC4", $key, true));
echo "\n";
原文:https://www.cnblogs.com/a-flydog/p/14011649.html