encrypt($iv); $blocksize = $cipher->block_size; if ((len($message) % $blocksize) != 0) { throw new Exception('message must be a multiple of 16 bytes (try adding '.(16 - (count($message) % 16)).' bytes of padding)'); } $ivp = substr($iv, 0, $blocksize - 0); $ivp2 = substr($iv, $blocksize, null); $ciphered = null; foreach (pyjslib_range(0, len($message), $blocksize) as $i) { $indata = substr($message, $i, ($i + $blocksize) - $i); if (($operation == 'decrypt')) { $xored = strxor($indata, $ivp2); $decrypt_xored = $cipher->decrypt($xored); $outdata = strxor($decrypt_xored, $ivp); $ivp = $indata; $ivp2 = $outdata; } elseif (($operation == 'encrypt')) { $xored = strxor($indata, $ivp); $encrypt_xored = $cipher->encrypt($xored); $outdata = strxor($encrypt_xored, $ivp2); $ivp = $outdata; $ivp2 = $indata; } else { throw new Exception('operation must be either \'decrypt\' or \'encrypt\''); } $ciphered .= $outdata; } return $ciphered; } }