CI_Encrypt::_add_cipher_noise PHP Method

_add_cipher_noise() protected method

Adds permuted noise to the IV + encrypted data to protect against Man-in-the-middle attacks on CBC mode ciphers http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
protected _add_cipher_noise ( $data, $key ) : string
return string
    protected function _add_cipher_noise($data, $key)
    {
        $key = $this->hash($key);
        $str = '';
        for ($i = 0, $j = 0, $ld = strlen($data), $lk = strlen($key); $i < $ld; ++$i, ++$j) {
            if ($j >= $lk) {
                $j = 0;
            }
            $str .= chr((ord($data[$i]) + ord($key[$j])) % 256);
        }
        return $str;
    }