Class: LargeInteger

verificatum.arithm.LargeInteger(first, second)

new LargeInteger(first, second)

Class for large immutable integers that handles memory allocation and provided utility functions.
Parameters:
Name Type Description
first Can be: (1) sign of explicit integer, (2) bit length of random integer, (3) byte array containing the bits of an integer, (4) hexadecimal representation of integer, (5) byte tree representation of integer, or (6) Javascript "number" representation of integer.
second Can be: (1) value of explicit integer, (2) or source of randomness, or in cases (3)-(6) it must be empty.
Source:

Methods

(static) byteLengthRandom(bitLength)

Returns the number of bytes needed to generate the given number of bits.
Parameters:
Name Type Description
bitLength Number of bits.
Source:
Returns:
Number of bytes needed.

abs()

Returns the absolute value of this integer.
Source:
Returns:
Absolute value of this integer.

add(term)

Computes sum of this integer and the input.
Parameters:
Name Type Description
term Other integer.
Source:
Returns:
this + term.

bitLength()

Bit length of this integer.
Source:
Returns:
Bit length of this integer.

cmp(other)

Compares this integer with the input.
Parameters:
Name Type Description
other Other integer.
Source:
Returns:
-1, 0, or 1 depending on if this integer is smaller than, equal to, or greater than the input.

div(divisor)

Computes integer quotient of this integer and the input.
Parameters:
Name Type Description
divisor Integer divisor.
Source:
Returns:
this / divisor for positive integers with rounding according to signs.

divQR(divisor)

Returns [q, r] such that q = this / divisor + r with this / divisor and r rounded with sign, in particular, if divisor is positive, then 0 <= r < divisor.
Parameters:
Name Type Description
divisor Divisor.
Source:
Returns:
Quotient and divisor.

egcd(other)

Computes extended greatest common divisor.
Parameters:
Name Type Description
other Other integer.
Source:
Returns:
Array [a, b, v] such that a * this + b * other = v and v is the greatest common divisor of this and other.

equals(other)

Checks if this integer is equal to the input.
Parameters:
Name Type Description
other Other integer.
Source:
Returns:
true if and only if this integer equals the input.

getBit(index)

Returns 1 or 0 depending on if the given bit is set or not.
Parameters:
Name Type Description
index Position of bit.
Source:
Returns:
1 or 0 depending on if the given bit is set or not.

iszero()

Checks if this integer is zero.
Source:
Returns:
true or false depending on if this is zero or not.

legendre(prime)

Returns (this | prime), i.e., the Legendre symbol of this modulo prime for an odd prime prime. (This is essentially a GCD algorithm that keeps track of the symbol.)
Parameters:
Name Type Description
prime An odd prime modulus.
Source:
Returns:
Legendre symbol of this instance modulo the input.

mod(modulus)

Computes integer remainder of this integer divided by the input as a value in [0, modulus - 1].
Parameters:
Name Type Description
modulus Divisor.
Source:
Returns:
Integer remainder.

modAdd(term, modulus)

Computes modular sum when this integer and the first input are non-negative and the last input is positive.
Parameters:
Name Type Description
term Other integer.
modulus Modulus.
Source:
Returns:
(this + term) mod modulus.

modInv(prime)

Computes modular inverse of this integer modulo the input prime.
Parameters:
Name Type Description
prime Odd positive prime integer.
Source:
Returns:
Integer x such that x * this = 1 mod prime, where 0 <= x < prime.

modMul(term, modulus)

Computes modular product when this integer and the first input are non-negative and the last input is positive.
Parameters:
Name Type Description
term Other integer.
modulus Modulus.
Source:
Returns:
(this * term) mod modulus.

modPow(exponent, modulus, naive)

Computes modular power of this integer raised to the exponent modulo the given modulus.
Parameters:
Name Type Description
exponent Exponent.
modulus Integer divisor.
naive Optional debugging parameter that enables slower naive implementation.
Source:
Returns:
this ^ exponent mod modulus for positive integers.

modSqrt(prime)

Returns a square root of this integer modulo an odd prime, where this integer is a quadratic residue modulo the prime.
Parameters:
Name Type Description
prime An odd prime modulus.
Source:
Returns:
Square root of this integer modulo the input odd prime.

modSub(term, modulus)

Computes modular difference when this integer and the first input are non-negative and the last input is positive.
Parameters:
Name Type Description
term Other integer.
modulus Modulus.
Source:
Returns:
(this - term) mod modulus.

mul(factor)

Computes product of this integer and the input.
Parameters:
Name Type Description
factor Other integer.
Source:
Returns:
this * term.

neg()

Returns negative of this integer.
Source:
Returns:
-this.

shiftLeft(offset)

Shifts this integer to the left.
Parameters:
Name Type Description
offset Bit positions to shift.
Source:
Returns:
This integer shifted the given number of bits to the left.

shiftRight(offset)

Shifts this integer to the right.
Parameters:
Name Type Description
offset Bit positions to shift.
Source:
Returns:
This integer shifted the given number of bits to the right.

slice(start, end)

Returns the bits between the start index and end index as an integer.
Parameters:
Name Type Description
start Inclusive start index.
end Exclusive end index.
Source:
Returns:
Bits between the start index and end index as an integer.

square()

Computes square of this integer.
Source:
Returns:
this * this.

sub(term)

Computes difference of this integer and the input.
Parameters:
Name Type Description
term Other integer.
Source:
Returns:
this - term.

toByteArray(byteSize)

Computes a byte array that represents the absolute value of this integer. The parameter can be used to truncate the most significant bytes or to ensure that a given number of bytes are used, effectively padding the representation with zeros.
Parameters:
Name Type Description
byteSize Number of bytes used in output.
Source:
Returns:
Resulting array.

toByteTree()

Computes a byte tree representation of this integer.
Source:
Returns:
Byte tree representation of this integer.

toHexString()

Computes a hexadecimal representation of this integer.
Source:
Returns:
Hexadecimal representation of this integer.