[ 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

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

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

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

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).

param: bool $twos_compliment
return: string

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

param: BCMath $y
return: BCMath

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

param: BCMath $y
return: BCMath

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

param: BCMath $x
return: BCMath

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).

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

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.

param: BCMath $n
return: false|BCMath

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.

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

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

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

param: BCMath $n
return: BCMath

abs()   X-Ref
Absolute value.

return: BCMath

bitwise_and(BCMath $x)   X-Ref
Logical And

param: BCMath $x
return: BCMath

bitwise_or(BCMath $x)   X-Ref
Logical Or

param: BCMath $x
return: BCMath

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

param: BCMath $x
return: BCMath

bitwise_rightShift($shift)   X-Ref
Logical Right Shift

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

param: int $shift
return: BCMath

bitwise_leftShift($shift)   X-Ref
Logical Left Shift

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

param: int $shift
return: BCMath

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.}

param: BCMath $y
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.

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()

param: BCMath $x
return: bool

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

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

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

Alias for modPow().

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

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

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

normalize(BCMath $result)   X-Ref
Normalize

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

param: BCMath $result
return: BCMath

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.

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

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)

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

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));

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

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

param: BCMath $n
return: BCMath

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

param: BCMath ...$nums
return: BCMath

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

param: BCMath ...$nums
return: BCMath

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

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

setBitmask($bits)   X-Ref
Set Bitmask

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

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