mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-19 03:35:12 +00:00
Merge pull request #377 from terrafrost/rc4-changes
RC4: speedups * terrafrost/rc4-changes: RC4: speedups
This commit is contained in:
commit
5cc024a3b5
@ -267,10 +267,7 @@ class Crypt_RC4 extends Crypt_Base
|
|||||||
{
|
{
|
||||||
$key = $this->key;
|
$key = $this->key;
|
||||||
$keyLength = strlen($key);
|
$keyLength = strlen($key);
|
||||||
$keyStream = array();
|
$keyStream = range(0, 255);
|
||||||
for ($i = 0; $i < 256; $i++) {
|
|
||||||
$keyStream[$i] = $i;
|
|
||||||
}
|
|
||||||
$j = 0;
|
$j = 0;
|
||||||
for ($i = 0; $i < 256; $i++) {
|
for ($i = 0; $i < 256; $i++) {
|
||||||
$j = ($j + $keyStream[$i] + ord($key[$i % $keyLength])) & 255;
|
$j = ($j + $keyStream[$i] + ord($key[$i % $keyLength])) & 255;
|
||||||
@ -324,7 +321,7 @@ class Crypt_RC4 extends Crypt_Base
|
|||||||
|
|
||||||
$keyStream[$i] = $ksj;
|
$keyStream[$i] = $ksj;
|
||||||
$keyStream[$j] = $ksi;
|
$keyStream[$j] = $ksi;
|
||||||
$text[$k] = chr(ord($text[$k]) ^ $keyStream[($ksj + $ksi) & 255]);
|
$text[$k] = $text[$k] ^ chr($keyStream[($ksj + $ksi) & 255]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
|
Loading…
Reference in New Issue
Block a user