Engine

Implements\JsonSerializable

Base Engine.

author

Jim Wigginton terrafrost@php.net

package

Default

Methods

Default constructor

__construct(integer|\phpseclib3\Math\BigInteger\Engines\numeric-string $x,integer $base = 10)

Arguments

$x

integer|\phpseclib3\Math\BigInteger\Engines\numeric-string

integer Base-10 number or base-$base number if $base set.

$base

integer

__debugInfo() magic method

__debugInfo(): array

Will be called, automatically, when print_r() or var_dump() are called

Response

array

Serialize

__sleep(): array

Will be called, automatically, when serialize() is called on a BigInteger object.

Response

array

Converts a BigInteger to a base-10 number.

__toString(): string

Response

string

Serialize

__wakeup(): void

Will be called, automatically, when unserialize() is called on a BigInteger object.

Logical Left Shift

base256_lshift(string &$x,integer $shift): void
static

Shifts binary strings $shift bits, essentially multiplying by 2**$shift.

Arguments

$x

string

$shift

integer

Logical Left Rotate

bitwise_leftRotate(integer $shift): \phpseclib3\Math\BigInteger\Engines\Engine

Instead of the top x bits being dropped they're appended to the shifted bit string.

Arguments

$shift

integer

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Logical Not

bitwise_not(): \phpseclib3\Math\BigInteger\Engines\Engine|string

Logical Right Rotate

bitwise_rightRotate(integer $shift): \phpseclib3\Math\BigInteger\Engines\Engine

Instead of the bottom x bits being dropped they're prepended to the shifted bit string.

Arguments

$shift

integer

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Bitwise Split

bitwise_split(integer $split): array<mixed,\phpseclib3\Math\BigInteger\Engines\Engine>

Splits BigInteger's into chunks of $split bits

Arguments

$split

integer

Response

array<mixed,\phpseclib3\Math\BigInteger\Engines\Engine>

Logical And

bitwiseAndHelper(\phpseclib3\Math\BigInteger\Engines\Engine $x): \phpseclib3\Math\BigInteger\Engines\Engine

Logical Or

bitwiseOrHelper(\phpseclib3\Math\BigInteger\Engines\Engine $x): \phpseclib3\Math\BigInteger\Engines\Engine

Logical Exclusive Or

bitwiseXorHelper(\phpseclib3\Math\BigInteger\Engines\Engine $x): \phpseclib3\Math\BigInteger\Engines\Engine

Create Recurring Modulo Function

createRecurringModuloFunction(): callable

Sometimes it may be desirable to do repeated modulos with the same number outside of modular exponentiation

Response

callable

Calculates the greatest common divisor and Bezout's identity.

extendedGCDHelper(\phpseclib3\Math\BigInteger\Engines\Engine $n): \phpseclib3\Math\BigInteger\Engines\array{gcd:

Arguments

Response

\phpseclib3\Math\BigInteger\Engines\array{gcd:

Engine, x: Engine, y: Engine}

Return the size of a BigInteger in bits

getLength(): integer

Response

integer

Return the size of a BigInteger in bytes

getLengthInBytes(): integer

Response

integer

Get Precision

getPrecision(): integer

Returns the precision if it exists, -1 if it doesn't

Response

integer

Checks a numer to see if it's prime

isPrime(integer|boolean $t = false): boolean

Assuming the $t parameter is not set, this function has an error rate of 2**-80. The main motivation for the $t parameter is distributability. BigInteger::randomPrime() can be distributed across multiple pageloads on a website instead of just one.

Arguments

$t

integer|boolean

Response

boolean

jsonSerialize

jsonSerialize()

Return the minimum BigInteger between an arbitrary number of BigIntegers.

maxHelper(array $nums): \phpseclib3\Math\BigInteger\Engines\Engine
static

Arguments

$nums

array

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Return the minimum BigInteger between an arbitrary number of BigIntegers.

minHelper(array $nums): \phpseclib3\Math\BigInteger\Engines\Engine
static

Arguments

$nums

array

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Returns the smallest and largest n-bit number

minMaxBits(integer $bits): \phpseclib3\Math\BigInteger\Engines\array{min:
static

Arguments

$bits

integer

Response

\phpseclib3\Math\BigInteger\Engines\array{min:

static, max: static}

Calculates modular inverses.

modInverseHelper(\phpseclib3\Math\BigInteger\Engines\Engine $n): static|false

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

{@internal See HAC 14.64 for more information.}

Arguments

Response

static|false

Performs some pre-processing for powMod

powModOuter(\phpseclib3\Math\BigInteger\Engines\Engine $e,\phpseclib3\Math\BigInteger\Engines\Engine $n): static|false

Generates a random number of a certain size

random(integer $size): \phpseclib3\Math\BigInteger\Engines\Engine
static

Bit length is equal to $size

Arguments

$size

integer

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Generates a random prime number of a certain size

randomPrime(integer $size): \phpseclib3\Math\BigInteger\Engines\Engine
static

Bit length is equal to $size

Arguments

$size

integer

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Generate a random number between a range

randomRangeHelper(\phpseclib3\Math\BigInteger\Engines\Engine $min,\phpseclib3\Math\BigInteger\Engines\Engine $max): \phpseclib3\Math\BigInteger\Engines\Engine
static

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)

Arguments

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Performs some post-processing for randomRangePrime

randomRangePrimeInner(\phpseclib3\Math\BigInteger\Engines\Engine $x,\phpseclib3\Math\BigInteger\Engines\Engine $min,\phpseclib3\Math\BigInteger\Engines\Engine $max): static|false
static

Performs some pre-processing for randomRangePrime

randomRangePrimeOuter(\phpseclib3\Math\BigInteger\Engines\Engine $min,\phpseclib3\Math\BigInteger\Engines\Engine $max): static|false
static

Calculates the nth root of a biginteger.

root(integer $n = 2): \phpseclib3\Math\BigInteger\Engines\Engine

Arguments

$n

integer

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Performs a few preliminary checks on root

rootHelper(integer $n): \phpseclib3\Math\BigInteger\Engines\Engine

Arguments

$n

integer

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Calculates the nth root of a biginteger.

rootInner(integer $n): \phpseclib3\Math\BigInteger\Engines\Engine

Returns the nth root of a positive biginteger, where n defaults to 2

{@internal This function is based off of this page and this stackoverflow question.}

Arguments

$n

integer

Response

\phpseclib3\Math\BigInteger\Engines\Engine

Set Bitmask

setBitmask(integer $bits): static
static
see \phpseclib3\Math\BigInteger\Engines\Engine::setPrecision()

Arguments

$bits

integer

Response

static

Sets engine type.

setModExpEngine(\phpseclib3\Math\BigInteger\Engines\class-string<Engine> $engine)
static

Throws an exception if the type is invalid

Arguments

$engine

\phpseclib3\Math\BigInteger\Engines\class-string

Set Precision

setPrecision(integer $bits)

Some bitwise operations give different results depending on the precision being used. Examples include left shift, not, and rotates.

Arguments

$bits

integer

Sets the $t parameter for primality testing

setupIsPrime(): integer

Response

integer

Sliding Window k-ary Modular Exponentiation

slidingWindow(\phpseclib3\Math\BigInteger\Engines\Engine $x,\phpseclib3\Math\BigInteger\Engines\Engine $e,\phpseclib3\Math\BigInteger\Engines\Engine $n,\phpseclib3\Math\BigInteger\Engines\class-string<T> $class): \phpseclib3\Math\BigInteger\Engines\T
static

Based on HAC 14.85 / MPM 7.7. In a departure from those algorithims, however, this function performs a modular reduction after every multiplication and squaring operation. As such, this function has the same preconditions that the reductions being used do.

template

T of Engine

Arguments

$class

\phpseclib3\Math\BigInteger\Engines\class-string

Response

\phpseclib3\Math\BigInteger\Engines\T

Tests Primality

testPrimality(integer $t): boolean

Uses the Miller-Rabin primality test. See HAC 4.24 for more info.

Arguments

$t

integer

Response

boolean

Converts a BigInteger to a bit string (eg. base-2).

toBits(boolean $twos_compliment = false): string

Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're saved as two's compliment.

Arguments

$twos_compliment

boolean

Response

string

Converts a BigInteger to a byte string (eg. base-256).

toBytesHelper(): string

Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're saved as two's compliment.

Response

string

Converts a BigInteger to a hex string (eg. base-16).

toHex(boolean $twos_compliment = false): string

Arguments

$twos_compliment

boolean

Response

string

Constants

PRIMES

PRIMES

Properties

BigInteger(0)

zero :\phpseclib3\Math\BigInteger\Engines\array<class-string<static>,
static
var

static>

Type(s)

\phpseclib3\Math\BigInteger\Engines\array,

BigInteger(1)

one :\phpseclib3\Math\BigInteger\Engines\array<class-string<static>,
static
var

static>

Type(s)

\phpseclib3\Math\BigInteger\Engines\array,

BigInteger(2)

two :\phpseclib3\Math\BigInteger\Engines\array<class-string<static>,
static
var

static>

Type(s)

\phpseclib3\Math\BigInteger\Engines\array,

Modular Exponentiation Engine

modexpEngine :\phpseclib3\Math\BigInteger\Engines\array<class-string<static>,
static
var

class-string>

Type(s)

\phpseclib3\Math\BigInteger\Engines\array,

Engine Validity Flag

isValidEngine :\phpseclib3\Math\BigInteger\Engines\array<class-string<static>,
static
var

bool>

Type(s)

\phpseclib3\Math\BigInteger\Engines\array,

Holds the BigInteger's value

value :\GMP|string|array|integer
var

Type(s)

\GMP|string|array|integer

Holds the BigInteger's sign

is_negative :boolean
var

Type(s)

boolean

Precision

precision :integer
see
var

Type(s)

integer

Precision Bitmask

bitmask :static|false
see
var

Type(s)

static|false

Recurring Modulo Function

reduce :callable
var

Type(s)

callable

Mode independent value used for serialization.

hex :string
see
var

Type(s)

string