[ Index ] |
PHP Cross Reference of DokuWiki |
[Source view] [Print] [Project Stats]
Base 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: | 1299 lines (39 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
__construct($x = 0, $base = 10) X-Ref |
Default constructor param: int|numeric-string $x integer Base-10 number or base-$base number if $base set. param: int $base |
setModExpEngine($engine) X-Ref |
Sets engine type. Throws an exception if the type is invalid param: class-string<Engine> $engine |
toBytesHelper() X-Ref |
Converts a BigInteger to a byte string (eg. base-256). Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're saved as two's compliment. return: string |
toHex($twos_compliment = false) X-Ref |
Converts a BigInteger to a hex string (eg. base-16). return: string param: bool $twos_compliment |
toBits($twos_compliment = false) X-Ref |
Converts a BigInteger to a bit string (eg. base-2). Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're saved as two's compliment. return: string param: bool $twos_compliment |
modInverseHelper(Engine $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. {@internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=21 HAC 14.64} for more information.} return: static|false param: Engine $n |
__sleep() X-Ref |
Serialize Will be called, automatically, when serialize() is called on a BigInteger object. return: array |
__wakeup() X-Ref |
Serialize Will be called, automatically, when unserialize() is called on a BigInteger object. return: void |
jsonSerialize() X-Ref |
JSON Serialize Will be called, automatically, when json_encode() is called on a BigInteger object. return: array{hex: string, precision?: int] |
__toString() X-Ref |
Converts a BigInteger to a base-10 number. return: string |
__debugInfo() X-Ref |
__debugInfo() magic method Will be called, automatically, when print_r() or var_dump() are called return: array |
setPrecision($bits) X-Ref |
Set Precision Some bitwise operations give different results depending on the precision being used. Examples include left shift, not, and rotates. param: int $bits |
getPrecision() X-Ref |
Get Precision Returns the precision if it exists, -1 if it doesn't return: int |
setBitmask($bits) X-Ref |
Set Bitmask return: static param: int $bits see: self::setPrecision() |
bitwise_not() X-Ref |
Logical Not return: Engine|string |
base256_lshift(&$x, $shift) X-Ref |
Logical Left Shift Shifts binary strings $shift bits, essentially multiplying by 2**$shift. return: void param: string $x param: int $shift |
bitwise_leftRotate($shift) X-Ref |
Logical Left Rotate Instead of the top x bits being dropped they're appended to the shifted bit string. return: Engine param: int $shift |
bitwise_rightRotate($shift) X-Ref |
Logical Right Rotate Instead of the bottom x bits being dropped they're prepended to the shifted bit string. return: Engine param: int $shift |
minMaxBits($bits) X-Ref |
Returns the smallest and largest n-bit number return: array{min: static, max: static} param: int $bits |
getLength() X-Ref |
Return the size of a BigInteger in bits return: int |
getLengthInBytes() X-Ref |
Return the size of a BigInteger in bytes return: int |
powModOuter(Engine $e, Engine $n) X-Ref |
Performs some pre-processing for powMod return: static|false param: Engine $e param: Engine $n |
slidingWindow(Engine $x, Engine $e, Engine $n, $class) X-Ref |
Sliding Window k-ary Modular Exponentiation Based on {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=27 HAC 14.85} / {@link http://math.libtomcrypt.com/files/tommath.pdf#page=210 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. return: T param: Engine $x param: Engine $e param: Engine $n param: class-string<T> $class |
random($size) X-Ref |
Generates a random number of a certain size Bit length is equal to $size return: Engine param: int $size |
randomPrime($size) X-Ref |
Generates a random prime number of a certain size Bit length is equal to $size return: Engine param: int $size |
randomRangePrimeOuter(Engine $min, Engine $max) X-Ref |
Performs some pre-processing for randomRangePrime return: static|false param: Engine $min param: Engine $max |
randomRangeHelper(Engine $min, Engine $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: Engine param: Engine $min param: Engine $max |
randomRangePrimeInner(Engine $x, Engine $min, Engine $max) X-Ref |
Performs some post-processing for randomRangePrime return: static|false param: Engine $x param: Engine $min param: Engine $max |
setupIsPrime() X-Ref |
Sets the $t parameter for primality testing return: int |
testPrimality($t) X-Ref |
Tests Primality Uses the {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=8 HAC 4.24} for more info. return: bool param: int $t |
isPrime($t = false) X-Ref |
Checks a numer to see if it's prime 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. return: bool param: int|bool $t |
rootHelper($n) X-Ref |
Performs a few preliminary checks on root return: Engine param: int $n |
rootInner($n) X-Ref |
Calculates the nth root of a biginteger. Returns the nth root of a positive biginteger, where n defaults to 2 {@internal This function is based off of {@link http://mathforum.org/library/drmath/view/52605.html this page} and {@link http://stackoverflow.com/questions/11242920/calculating-nth-root-with-bcmath-in-php this stackoverflow question}.} return: Engine param: int $n |
root($n = 2) X-Ref |
Calculates the nth root of a biginteger. return: Engine param: int $n |
minHelper(array $nums) X-Ref |
Return the minimum BigInteger between an arbitrary number of BigIntegers. return: Engine param: array $nums |
maxHelper(array $nums) X-Ref |
Return the minimum BigInteger between an arbitrary number of BigIntegers. return: Engine param: array $nums |
createRecurringModuloFunction() X-Ref |
Create Recurring Modulo Function Sometimes it may be desirable to do repeated modulos with the same number outside of modular exponentiation return: callable |
extendedGCDHelper(Engine $n) X-Ref |
Calculates the greatest common divisor and Bezout's identity. return: array{gcd: Engine, x: Engine, y: Engine} param: Engine $n |
bitwise_split($split) X-Ref |
Bitwise Split Splits BigInteger's into chunks of $split bits return: Engine[] param: int $split |
bitwiseAndHelper(Engine $x) X-Ref |
Logical And return: Engine param: Engine $x |
bitwiseOrHelper(Engine $x) X-Ref |
Logical Or return: Engine param: Engine $x |
bitwiseXorHelper(Engine $x) X-Ref |
Logical Exclusive Or return: Engine param: Engine $x |