private function _encryptInternal($input, $base, $pad, $password, $iv, $checkVal = false)
    {
        $this->_validateInput($input, $base, $checkVal);
        $this->_validateIv($iv);
        $hashPassword = $this->_hashPassword($password);
        $roundKeys = $this->_roundKeys($hashPassword, $iv);

        $binary = $this->_convertToBin($input, $base);

        for ($i = 1; $i <= $this->rounds; $i++) {
            $left = substr($binary, 0, $this->sideSize);
            $right = substr($binary, -1 * $this->sideSize);

            $key = $roundKeys[$i];
            $round = $this->_round($right, $key, $hashPassword, $iv);

            $newLeft = $right;
            $newRight = $this->_binaryXor($left, $round);

            $binary = $newLeft . $newRight;
        }

        $output = $this->_convertFromBin($binary, $base, $pad);
        $compare = DataConverter::binToDec($binary);

        return (gmp_cmp($this->minValue, $compare) > 0 || gmp_cmp($compare, $this->maxValue) > 0)
            ? $this->_encryptInternal($output, $base, $pad, $password, $iv, false)
            : $output;
    }
private function _encryptInternal($input, $base, $pad, $password, $iv, $checkVal = false)
    {
        $this->_validateInput($input, $base, $checkVal);
        $this->_validateIv($iv);
        $hashPassword = $this->_hashPassword($password);
        $roundKeys = $this->_roundKeys($hashPassword, $iv);

        $binary = $this->_convertToBin($input, $base);

        for ($i = 1; $i <= $this->rounds; $i++) {
            $left = substr($binary, 0, $this->sideSize);
            $right = substr($binary, -1 * $this->sideSize);

            $key = $roundKeys[$i];
            $round = $this->_round($right, $key, $hashPassword, $iv);

            $newLeft = $right;
            $newRight = $this->_binaryXor($left, $round);

            $binary = $newLeft . $newRight;
        }

        $output = $this->_convertFromBin($binary, $base, $pad);
        $compare = DataConverter::binToDec($binary);

        return (gmp_cmp($this->minValue, $compare) > 0 || gmp_cmp($compare, $this->maxValue) > 0)
            ? $this->_encryptInternal($output, $base, $pad, $password, $iv, false)
            : $output;
    }
private function _encryptInternal ( $ input , $ base , $ pad , $ password , $ iv , $ checkVal = false ) { $ this -> _validateInput ( $ input , $ base , $ checkVal ) ; $ this -> _validateIv ( $ iv ) ; $ hashPassword = $ this -> _hashPassword ( $ password ) ; $ roundKeys = $ this -> _roundKeys ( $ hashPassword , $ iv ) ; $ binary = $ this -> _convertToBin ( $ input , $ base ) ; for ( $ i = 1 ; $ i <= $ this -> rounds ; $ i ++ ) { $ left = substr ( $ binary , 0 , $ this -> sideSize ) ; $ right = substr ( $ binary , - 1 * $ this -> sideSize ) ; $ key = $ roundKeys [ $ i ] ; $ round = $ this -> _round ( $ right , $ key , $ hashPassword , $ iv ) ; $ newLeft = $ right ; $ newRight = $ this -> _binaryXor ( $ left , $ round ) ; $ binary = $ newLeft . $ newRight ; } $ output = $ this -> _convertFromBin ( $ binary , $ base , $ pad ) ; $ compare = DataConverter :: binToDec ( $ binary ) ; return ( gmp_cmp ( $ this -> minValue , $ compare ) > 0 || gmp_cmp ( $ compare , $ this -> maxValue ) > 0 ) ? $ this -> _encryptInternal ( $ output , $ base , $ pad , $ password , $ iv , false ) : $ output ; }
Encrypts input data.

@param string      $input    String representation of input number.
@param int         $base     Input number base.
@param bool        $pad      Pad left with zeroes?
@param string|null $password Encryption password.
@param string|null $iv       Encryption initialization vector. Must be unique!
@param bool        $checkVal Should check if input value is in range?

@return string Outputs encrypted data in the same format as input data.
Encrypts input data .