RSADP

See {@link http://tools.ietf.org/html/rfc3447#section-5.1.2 RFC3447#section-5.1.2}.

@access private
@param \phpseclib\Math\BigInteger $c
@return \phpseclib\Math\BigInteger
762279
function _rsadp($c)
    {
        if ($c->compare($this->zero) < 0 || $c->compare($this->modulus) > 0) {
            user_error('Ciphertext representative out of range');
            return false;
        }
        return $this->_exponentiate($c);
    }
475770
private function isAlphaNum($c) {

		// Get ASCII value of character for C-like comparisons
		$a = ord($c);

		// Compare using defined character ordinals, or between PHP strings
		// Note : === is micro-faster than == when types are known to be the same
		return
			($a >= self::ORD_a && $a <= self::ORD_z) ||
			($a >= self::ORD_0 && $a <= self::ORD_9) ||
			($a >= self::ORD_cA && $a <= self::ORD_cZ) ||
			$c === '_' || $c === '$' || $c === '\\' || $a > 126
		;
	}
1078384
public function bigInteger($column, $autoIncrement = false, $unsigned = false)
    {
        return $this->table->addColumn($column, Type::BIGINT, compact('autoIncrement', 'unsigned'));
    }
764584
private function translateValue($s, $bpc)
	{
		$n = $this->twoBytesToInt($s);

		if ($bpc == 16) {
			$n = ($n >> 8);
		}

		//elseif ($bpc==4) { $n = ($n << 2); }
		//elseif ($bpc==2) { $n = ($n << 4); }

		return $n;
	}
896574
final public static function bcround($number, $precision, $roundingMode = self::ROUND_HALF_UP)
    {
        if ($number instanceof Decimal) {
            $number = (string) $number;
        }

        $precision = self::normalizePrecision($precision);
        if (self::isNotDecimalString($number)) {
            return Decimal::create($number, $precision);
        }

        if ($roundingMode === self::ROUND_HALF_UP) {
            return Decimal::create(self::bcRoundHalfUp($number, $precision), $precision);
        }

        $firstDecimalAfterPrecision = self::getFirstDecimalAfterPrecision($number, $precision);
        if ($firstDecimalAfterPrecision === self::HALF) {
            $result = self::roundTied($number, $precision, $roundingMode);
        } else {
            $result = self::roundNotTied($firstDecimalAfterPrecision, $number, $precision);
        }

        /*
         * Arbitrary precision arithmetic allows for '-0.0' which is not equal to '0.0' if compared with bccomp.
         * We have no use for this behaviour, so negative numbers have to be checked if they are minus zero,
         * so we can convert them into unsigned zero and return that.
         */
        $result = self::normalizeZero($result, $precision);

        return Decimal::create($result, $precision);
    }
1276396
public static function convert($c)
    {
        $runtimeVersion = Propel::VERSION;

        $conf = '';
        $conf .= "\$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();";
        $conf .= "
\$serviceContainer->checkVersion('{$runtimeVersion}');";
        // set datasources
        if (isset($c['connections'])) {
            foreach ($c['connections'] as $name => $params) {
                if (!is_array($params)) {
                    continue;
                }

                // set adapters
                if (isset($params['adapter'])) {
                    $conf .= "
\$serviceContainer->setAdapterClass('{$name}', '{$params['adapter']}');";
                }

                // set connection settings
                if (isset($params['slaves'])) {
                    $conf .= "
\$manager = new \Propel\Runtime\Connection\ConnectionManagerMasterSlave();
\$manager->setReadConfiguration(" . var_export($params['slaves'], true). ");";
                } elseif (isset($params['dsn'])) {
                    $conf .= "
\$manager = new \Propel\Runtime\Connection\ConnectionManagerSingle();";
                } else {
                    continue;
                }

                if (isset($params['dsn'])) {
                    $masterConfigurationSetter = isset($params['slaves']) ? 'setWriteConfiguration' : 'setConfiguration';
                    $connection = $params;
                    unset($connection['adapter']);
                    unset($connection['slaves']);
                    $conf .= "
\$manager->{$masterConfigurationSetter}(". var_export($connection, true) . ");";
                }

                $conf .= "
\$manager->setName('{$name}');
\$serviceContainer->setConnectionManager('{$name}', \$manager);";
            }

            // set default datasource
            if (isset($c['defaultConnection'])) {
                $defaultDatasource = $c['defaultConnection'];
            } elseif (isset($c['connections']) && is_array($c['connections'])) {
                // fallback to the first datasource
                $datasourceNames = array_keys($c['connections']);
                $defaultDatasource = $datasourceNames[0];
            }

            $conf .= "
\$serviceContainer->setDefaultDatasource('{$defaultDatasource}');";
        }

        // set profiler
        if (isset($c['profiler'])) {
            $profilerConf = $c['profiler'];
            if (isset($profilerConf['classname'])) {
                $conf .= "
\$serviceContainer->setProfilerClass('{$profilerConf['classname']}');";
                unset($profilerConf['classname']);
            }

            if ($profilerConf) {
                $conf .= "
\$serviceContainer->setProfilerConfiguration(" . var_export($profilerConf, true) . ");";
            }
            unset($c['profiler']);
        }

        // set logger
        if (isset($c['log']) && count($c['log']) > 0) {
            foreach ($c['log'] as $key => $logger) {
                $conf .= "
\$serviceContainer->setLoggerConfiguration('{$key}', " . var_export($logger, true) . ");";
            }
            unset($c['log']);
        }

        return preg_replace('/[ \t]*$/m', '', $conf);
    }
650688
function bitwise_leftShift($shift)
    {
        $temp = new Math_BigInteger();

        switch (MATH_BIGINTEGER_MODE) {
            case MATH_BIGINTEGER_MODE_GMP:
                static $two;

                if (!isset($two)) {
                    $two = gmp_init('2');
                }

                $temp->value = gmp_mul($this->value, gmp_pow($two, $shift));

                break;
            case MATH_BIGINTEGER_MODE_BCMATH:
                $temp->value = bcmul($this->value, bcpow('2', $shift, 0), 0);

                break;
            default: // could just replace _rshift with this, but then all _lshift() calls would need to be rewritten
                     // and I don't want to do that...
                $temp->value = $this->value;
                $temp->_lshift($shift);
        }

        return $this->_normalize($temp);
    }
1150157
public function simplified() : BigRational
    {
        $gcd = $this->numerator->gcd($this->denominator);

        $numerator = $this->numerator->quotient($gcd);
        $denominator = $this->denominator->quotient($gcd);

        return new BigRational($numerator, $denominator, false);
    }
479446
private static function getRSADP(RSAKey $key, BigInteger $c)
    {
        if ($c->compare(BigInteger::createFromDecimal(0)) < 0 || $c->compare($key->getModulus()) > 0) {
            return false;
        }

        return self::exponentiate($key, $c);
    }
163748
public function negated() : BigDecimal
    {
        return new BigDecimal(Calculator::get()->neg($this->value), $this->scale);
    }
1059217
private static function getRSAVP1(RSAKey $key, BigInteger $s)
    {
        if ($s->compare(BigInteger::createFromDecimal(0)) < 0 || $s->compare($key->getModulus()) > 0) {
            return false;
        }

        return self::exponentiate($key, $s);
    }
442295
public function setMaxLimit($c)
    {
        $c = (int) $c;
        $c and $this->maxlimit = $c;

        return $this;
    }
430219
public function base10($number)
    {
        if (!is_int($number)) {
            throw new \InvalidArgumentException('Expecting integer');
        }

        if ($this->integerPart === '0' && !$this->fractionalPart) {
            return $this;
        }

        $sign = '';
        $integerPart = $this->integerPart;

        if ($integerPart[0] === '-') {
            $sign = '-';
            $integerPart = substr($integerPart, 1);
        }

        if ($number >= 0) {
            $integerPart = ltrim($integerPart, '0');
            $lengthIntegerPart = strlen($integerPart);
            $integers = $lengthIntegerPart - min($number, $lengthIntegerPart);
            $zeroPad = $number - min($number, $lengthIntegerPart);

            return new self(
                $sign.substr($integerPart, 0, $integers),
                rtrim(str_pad('', $zeroPad, '0').substr($integerPart, $integers).$this->fractionalPart, '0')
            );
        }

        $number = abs($number);
        $lengthFractionalPart = strlen($this->fractionalPart);
        $fractions = $lengthFractionalPart - min($number, $lengthFractionalPart);
        $zeroPad = $number - min($number, $lengthFractionalPart);

        return new self(
            $sign.ltrim($integerPart.substr($this->fractionalPart, 0, $lengthFractionalPart - $fractions).str_pad('', $zeroPad, '0'), '0'),
            substr($this->fractionalPart, $lengthFractionalPart - $fractions)
        );
    }
1150704
function _make_odd()
    {
        switch (MATH_BIGINTEGER_MODE) {
            case self::MODE_GMP:
                gmp_setbit($this->value, 0);
                break;
            case self::MODE_BCMATH:
                if ($this->value[strlen($this->value) - 1] % 2 == 0) {
                    $this->value = bcadd($this->value, '1');
                }
                break;
            default:
                $this->value[0] |= 1;
        }
    }
93102
public static function sqrt($base)
    {
        if (!static::is($base)) {
            throw new \InvalidArgumentException(
                "The \$base parameters must be of type int (or string representing a big int)."
            );
        }

        if (is_int($base)) {
            return sqrt($base);
        } elseif (function_exists('bcsqrt')) {
            return bcsqrt($base);
        }

        throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore
    }
242819
public function bitwiseXOr($x)
    {
        switch (MATH_BIGINTEGER_MODE) {
            case MATH_BIGINTEGER_MODE_GMP:
                $temp = new BigInteger();
                $temp->value = gmp_xor($this->value, $x->value);
                return $this->protectedNormalize($temp);
            case MATH_BIGINTEGER_MODE_BCMATH:
                $left = $this->toBytes();
                $right = $x->toBytes();
                $length = max(strlen($left), strlen($right));
                $left = str_pad($left, $length, chr(0), STR_PAD_LEFT);
                $right = str_pad($right, $length, chr(0), STR_PAD_LEFT);
                return $this->protectedNormalize(new BigInteger($left ^ $right, 256));
        }
        $length = max(count($this->value), count($x->value));
        $result = $this->copy();
        $result->value = array_pad($result->value, $length, 0);
        $x->value = array_pad($x->value, $length, 0);
        for ($i = 0; $i < $length; ++ $i) {
            $result->value[$i] ^= $x->value[$i];
        }
        return $this->protectedNormalize($result);
    }
1145045
public function Mod( $denominator )
	{
		$denominator = $denominator instanceof DecimalValue ? $denominator : Convert::ToDecimal( $denominator );

		if ( $denominator->getIsZero() )
			throw XPath2Exception::withErrorCode( "FOAR0001", Resources::FOAR0001 );

		if ( $denominator->getIsNAN() )
			throw XPath2Exception::withErrorCode( "FOAR0002", Resources::FOAR0002 );

		if ( $this->getIsNAN() || $this->getIsInfinite() )
			throw XPath2Exception::withErrorCode( "FOAR0002", Resources::FOAR0002 );

		$power = 0;
		// bcmod does not handle decimals so if they exist the powers of the two numbers must be increased until there are no decimals
		if ( $this->getIsDecimal() )
		{
			$power = strlen( $this->getIntegerPart() );
		}

		if ( $denominator->getIsDecimal() )
		{
			$power = max( strlen( $denominator->getIntegerPart() ), $power );
		}

		$multiplier = new DecimalValue( 10 );
		$multiplier = $multiplier->Pow( new DecimalValue( $power ) );
		$numerator = $this->Mul( $multiplier );
		$denominator = $denominator->Mul( $multiplier );
		$mod = bcmod( $numerator->getIntegerPart(), $denominator->getIntegerPart() );

		// Now need to divide by the multiplier to restore the correct power
		$mod = new DecimalValue( $mod );
		$mod = $mod->Div( $multiplier );
		return $mod;
	}