phpseclib\Crypt\RC4::_crypt PHP Method

_crypt() public method

Encrypts or decrypts a message.
See also: self::encrypt()
See also: self::decrypt()
public _crypt ( string $text, integer $mode ) : string
$text string
$mode integer
return string $text
    function _crypt($text, $mode)
    {
        if ($this->changed) {
            $this->_setup();
            $this->changed = false;
        }
        $stream =& $this->stream[$mode];
        if ($this->continuousBuffer) {
            $i =& $stream[0];
            $j =& $stream[1];
            $keyStream =& $stream[2];
        } else {
            $i = $stream[0];
            $j = $stream[1];
            $keyStream = $stream[2];
        }
        $len = strlen($text);
        for ($k = 0; $k < $len; ++$k) {
            $i = $i + 1 & 255;
            $ksi = $keyStream[$i];
            $j = $j + $ksi & 255;
            $ksj = $keyStream[$j];
            $keyStream[$i] = $ksj;
            $keyStream[$j] = $ksi;
            $text[$k] = $text[$k] ^ chr($keyStream[$ksj + $ksi & 255]);
        }
        return $text;
    }