public static function crypt($str, $key) { $s = self::initializeState($key); $i = $j = 0; $res = ''; $size = Str::strlen($str); for ($y = 0; $y < $size; $y++) { $i = ($i + 1) % 256; $j = ($j + $s[$i]) % 256; $x = $s[$i]; $s[$i] = $s[$j]; $s[$j] = $x; $res .= $str[$y] ^ \chr($s[($s[$i] + $s[$j]) % 256]); } return $res; }
public function testVector() { /* * Test that known cypher text decrypts properly */ $cyphertext = hex2bin('140ad3d278a229ff3c487d'); $plain = 'Hello World'; $key = 'asdf'; $this->assertEquals($plain, Rc4::crypt($cyphertext, $key)); }