Support for arbitrary precision mathematics in PHP.

Zend_Crypt_Math_BigInteger is a wrapper across three PHP extensions: bcmath, gmp and big_int. Since each offer similar functionality, but availability of each differs across installations of PHP, this wrapper attempts to select the fastest option available and encapsulate a subset of its functionality which all extensions share in common.

This class requires one of the three extensions to be available. BCMATH while the slowest, is available by default under Windows, and under Unix if PHP is compiled with the flag "--enable-bcmath". GMP requires the gmp library from http://www.swox.com/gmp/ and PHP compiled with the "--with-gmp" flag. BIG_INT support is available from a big_int PHP library available from only from PECL (a Windows port is not available).

category Zend
package Zend_Crypt
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
inherited_from \Zend_Crypt_Math_BigInteger

 Methods

Redirect all public method calls to the wrapped extension object.

__call(string $methodName, array $args) : mixed
Inherited

Parameters

$methodName

string

$args

array

Exceptions

\Zend_Crypt_Math_BigInteger_Exception

Returns

mixed

Constructor; a Factory which detects a suitable PHP extension for arbitrary precision math and instantiates the suitable wrapper object.

__construct(string $extension = null
Inherited

Parameters

$extension

string

Exceptions

\Zend_Crypt_Math_BigInteger_Exception

Get the big endian two's complement of a given big integer in binary notation

btwoc(string $long) : string

Parameters

$long

string

Returns

string

Translate a binary form into a big integer string

fromBinary(string $binary) : string

Parameters

$binary

string

Returns

string

Generate a pseudorandom number within the given range.

rand(string|integer $minimum, string|integer $maximum) : string

Will attempt to read from a systems RNG if it exists or else utilises a simple random character to maximum length process. Simplicity is a factor better left for development...

Parameters

$minimum

stringinteger

$maximum

stringinteger

Returns

string

Return a random strings of $length bytes

randBytes(integer $length, boolean $strong = false) : string
Static

Parameters

$length

integer

$strong

boolean

Returns

string

Return a random integer between $min and $max

randInteger(integer $min, integer $max, boolean $strong = false) : integer
Static

Parameters

$min

integer

$max

integer

$strong

boolean

Returns

integer

Translate a big integer string into a binary form

toBinary(string $integer) : string

Parameters

$integer

string

Returns

string

_loadAdapter()

_loadAdapter(string $extension = null
Inherited

Parameters

$extension

string

Exceptions

\Zend_Crypt_Math_BigInteger_Exception

 Properties

 

Holds an instance of one of the three arbitrary precision wrappers.

$_math : \Zend_Crypt_Math_BigInteger_Interface

Default

null