[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger/Engines/ -> BCMath.php (summary)

BCMath BigInteger Engine PHP version 5 and 7

Author: Jim Wigginton
Copyright: 2017 Jim Wigginton
License: http://www.opensource.org/licenses/mit-license.html MIT License
Link: http://pear.php.net/package/Math_BigInteger
File Size: 697 lines (18 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

BCMath:: (38 methods):
  isValidEngine()
  __construct()
  initialize()
  toString()
  toBytes()
  add()
  subtract()
  multiply()
  divide()
  modInverse()
  extendedGCD()
  gcd()
  abs()
  bitwise_and()
  bitwise_or()
  bitwise_xor()
  bitwise_rightShift()
  bitwise_leftShift()
  compare()
  equals()
  modPow()
  powMod()
  powModInner()
  normalize()
  randomRangePrime()
  randomRange()
  make_odd()
  testSmallPrimes()
  scan1divide()
  pow()
  min()
  max()
  between()
  setBitmask()
  isOdd()
  testBit()
  isNegative()
  negate()


Class: BCMath  - X-Ref

BCMath Engine.

isValidEngine()   X-Ref
Test for engine validity

see: parent::__construct()
return: bool

__construct($x = 0, $base = 10)   X-Ref
Default constructor

see: parent::__construct()
param: mixed $x integer Base-10 number or base-$base number if $base set.
param: int $base

initialize($base)   X-Ref
Initialize a BCMath BigInteger Engine instance

see: parent::__construct()
param: int $base

toString()   X-Ref
Converts a BigInteger to a base-10 number.

return: string

toBytes($twos_compliment = false)   X-Ref
Converts a BigInteger to a byte string (eg. base-256).

return: string
param: bool $twos_compliment

add(BCMath $y)   X-Ref
Adds two BigIntegers.

return: BCMath
param: BCMath $y

subtract(BCMath $y)   X-Ref
Subtracts two BigIntegers.

return: BCMath
param: BCMath $y

multiply(BCMath $x)   X-Ref
Multiplies two BigIntegers.

return: BCMath
param: BCMath $x

divide(BCMath $y)   X-Ref
Divides two BigIntegers.

Returns an array whose first element contains the quotient and whose second element contains the
"common residue".  If the remainder would be positive, the "common residue" and the remainder are the
same.  If the remainder would be negative, the "common residue" is equal to the sum of the remainder
and the divisor (basically, the "common residue" is the first positive modulo).

return: array{static, static}
param: BCMath $y

modInverse(BCMath $n)   X-Ref
Calculates modular inverses.

Say you have (30 mod 17 * x mod 17) mod 17 == 1.  x can be found using modular inverses.

return: false|BCMath
param: BCMath $n

extendedGCD(BCMath $n)   X-Ref
Calculates the greatest common divisor and Bezout's identity.

Say you have 693 and 609.  The GCD is 21.  Bezout's identity states that there exist integers x and y such that
693*x + 609*y == 21.  In point of fact, there are actually an infinite number of x and y combinations and which
combination is returned is dependent upon which mode is in use.  See
{@link http://en.wikipedia.org/wiki/B%C3%A9zout%27s_identity Bezout's identity - Wikipedia} for more information.

return: array{gcd: static, x: static, y: static}
param: BCMath $n

gcd(BCMath $n)   X-Ref
Calculates the greatest common divisor

Say you have 693 and 609.  The GCD is 21.

return: BCMath
param: BCMath $n

abs()   X-Ref
Absolute value.

return: BCMath

bitwise_and(BCMath $x)   X-Ref
Logical And

return: BCMath
param: BCMath $x

bitwise_or(BCMath $x)   X-Ref
Logical Or

return: BCMath
param: BCMath $x

bitwise_xor(BCMath $x)   X-Ref
Logical Exclusive Or

return: BCMath
param: BCMath $x

bitwise_rightShift($shift)   X-Ref
Logical Right Shift

Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift.

return: BCMath
param: int $shift

bitwise_leftShift($shift)   X-Ref
Logical Left Shift

Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift.

return: BCMath
param: int $shift

compare(BCMath $y)   X-Ref
Compares two numbers.

Although one might think !$x->compare($y) means $x != $y, it, in fact, means the opposite.  The reason for this
is demonstrated thusly:

$x  > $y: $x->compare($y)  > 0
$x  < $y: $x->compare($y)  < 0
$x == $y: $x->compare($y) == 0

Note how the same comparison operator is used.  If you want to test for equality, use $x->equals($y).

{@internal Could return $this->subtract($x), but that's not as fast as what we do do.}

see: self::equals()
return: int in case < 0 if $this is less than $y; > 0 if $this is greater than $y, and 0 if they are equal.
param: BCMath $y

equals(BCMath $x)   X-Ref
Tests the equality of two numbers.

If you need to see if one number is greater than or less than another number, use BigInteger::compare()

return: bool
param: BCMath $x

modPow(BCMath $e, BCMath $n)   X-Ref
Performs modular exponentiation.

return: BCMath
param: BCMath $e
param: BCMath $n

powMod(BCMath $e, BCMath $n)   X-Ref
Performs modular exponentiation.

Alias for modPow().

return: BCMath
param: BCMath $e
param: BCMath $n

powModInner(BCMath $e, BCMath $n)   X-Ref
Performs modular exponentiation.

return: BCMath
param: BCMath $e
param: BCMath $n

normalize(BCMath $result)   X-Ref
Normalize

Removes leading zeros and truncates (if necessary) to maintain the appropriate precision

return: BCMath
param: BCMath $result

randomRangePrime(BCMath $min, BCMath $max)   X-Ref
Generate a random prime number between a range

If there's not a prime within the given range, false will be returned.

return: false|BCMath
param: BCMath $min
param: BCMath $max

randomRange(BCMath $min, BCMath $max)   X-Ref
Generate a random number between a range

Returns a random number between $min and $max where $min and $max
can be defined using one of the two methods:

BigInteger::randomRange($min, $max)
BigInteger::randomRange($max, $min)

return: BCMath
param: BCMath $min
param: BCMath $max

make_odd()   X-Ref
Make the current number odd

If the current number is odd it'll be unchanged.  If it's even, one will be added to it.

see: self::randomPrime()

testSmallPrimes()   X-Ref
Test the number against small primes.

see: self::isPrime()

scan1divide(BCMath $r)   X-Ref
Scan for 1 and right shift by that amount

ie. $s = gmp_scan1($n, 0) and $r = gmp_div_q($n, gmp_pow(gmp_init('2'), $s));

see: self::isPrime()
return: int
param: BCMath $r

pow(BCMath $n)   X-Ref
Performs exponentiation.

return: BCMath
param: BCMath $n

min(BCMath ...$nums)   X-Ref
Return the minimum BigInteger between an arbitrary number of BigIntegers.

return: BCMath
param: BCMath ...$nums

max(BCMath ...$nums)   X-Ref
Return the maximum BigInteger between an arbitrary number of BigIntegers.

return: BCMath
param: BCMath ...$nums

between(BCMath $min, BCMath $max)   X-Ref
Tests BigInteger to see if it is between two integers, inclusive

return: bool
param: BCMath $min
param: BCMath $max

setBitmask($bits)   X-Ref
Set Bitmask

see: self::setPrecision()
return: Engine
param: int $bits

isOdd()   X-Ref
Is Odd?

return: bool

testBit($x)   X-Ref
Tests if a bit is set

return: bool

isNegative()   X-Ref
Is Negative?

return: bool

negate()   X-Ref
Negate

Given $k, returns -$k

return: BCMath