[ Index ]

PHP Cross Reference of DokuWiki




/vendor/phpseclib/phpseclib/phpseclib/Math/BinaryField/ -> Integer.php (summary)

Binary Finite Fields In a binary finite field numbers are actually polynomial equations. If you represent the number as a sequence of bits you get a sequence of 1's or 0's. These 1's or 0's represent the coefficients of the x**n, where n is the location of the given bit. When you add numbers over a binary finite field the result should have a coefficient of 1 or 0 as well. Hence addition and subtraction become the same operation as XOR. eg. 1 + 1 + 1 == 3 % 2 == 1 or 0 - 1 == -1 % 2 == 1

Author: Jim Wigginton
Copyright: 2017 Jim Wigginton
License: http://www.opensource.org/licenses/mit-license.html MIT License
File Size: 516 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Integer:: (26 methods):

Class: Integer  - X-Ref

Binary Finite Fields

__construct($instanceID, $num = '')   X-Ref
Default constructor

setModulo($instanceID, $modulo)   X-Ref
Set the modulo for a given instance

param: int $instanceID
param: string $modulo

setRecurringModuloFunction($instanceID, callable $function)   X-Ref
Set the modulo for a given instance

checkInstance(self $x, self $y)   X-Ref
Tests a parameter to see if it's of the right instance

Throws an exception if the incorrect class is being utilized

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

return: bool

compare(self $x)   X-Ref
Compares two numbers.

return: int

deg($x)   X-Ref
Returns the degree of the polynomial

return: int
param: string $x

polynomialDivide($x, $y)   X-Ref
Perform polynomial division

link: https://en.wikipedia.org/wiki/Polynomial_greatest_common_divisor#Euclidean_division
return: string[]

regularPolynomialMultiply($x, $y)   X-Ref
Perform polynomial multiplation in the traditional way

link: https://en.wikipedia.org/wiki/Finite_field_arithmetic#Multiplication
return: string

polynomialMultiply($x, $y)   X-Ref
Perform polynomial multiplation

Uses karatsuba multiplication to reduce x-bit multiplications to a series of 32-bit multiplications

link: https://en.wikipedia.org/wiki/Karatsuba_algorithm
return: string

subMultiply($x, $y)   X-Ref
Perform polynomial multiplication on 2x 32-bit numbers, returning
a 64-bit number

link: https://www.bearssl.org/constanttime.html#ghash-for-gcm
return: string
param: string $x
param: string $y

subAdd2($x, $y)   X-Ref
Adds two numbers

return: string
param: string $x
param: string $y

subAdd3($x, $y, $z)   X-Ref
Adds three numbers

return: string
param: string $x
param: string $y

add(self $y)   X-Ref
Adds two BinaryFieldIntegers.

return: static

subtract(self $x)   X-Ref
Subtracts two BinaryFieldIntegers.

return: static

multiply(self $y)   X-Ref
Multiplies two BinaryFieldIntegers.

return: static

modInverse()   X-Ref
Returns the modular inverse of a BinaryFieldInteger

return: static

divide(self $x)   X-Ref
Divides two PrimeFieldIntegers.

return: static

negate()   X-Ref

A negative number can be written as 0-12. With modulos, 0 is the same thing as the modulo
so 0-12 is the same thing as modulo-12

return: object

getModulo($instanceID)   X-Ref
Returns the modulo

return: string

toBytes()   X-Ref
Converts an Integer to a byte string (eg. base-256).

return: string

toHex()   X-Ref
Converts an Integer to a hex string (eg. base-16).

return: string

toBits()   X-Ref
Converts an Integer to a bit string (eg. base-2).

return: string

toBigInteger()   X-Ref
Converts an Integer to a BigInteger

return: string

__toString()   X-Ref
__toString() magic method

__debugInfo()   X-Ref
__debugInfo() magic method