Namespace BigInteger
High-precision arithmetic
Defined in: bn.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Minimal set of high precision arithmetic operations for RSA encryption and decryption. |
Method Attributes | Method Name and Description |
---|---|
<static> |
BigInteger.abs(n)
Absolute value.
|
<static> |
BigInteger.bitLength(n)
Index of first non-zero bit starting from the LSB of the given BigInteger.
|
<static> |
BigInteger.compareTo(n, m)
Comparison of BigInteger.
|
<static> |
BigInteger.copyTo(source, target)
Copy the value of a BigInteger to another.
|
<static> |
BigInteger.create(v)
Create a new BigInteger initialized from the given hex value.
|
<static> |
BigInteger.divRem(n, m)
Euclidean division of two BigIntegers.
|
<static> |
BigInteger.expMod(x, e, n)
Modular exponentiation using Montgomery reduction.
|
<static> |
BigInteger.LshiftTo(n, k, r)
Logical shift to the left
|
<static> |
BigInteger.mod(n, m)
Modular remainder of an integer division.
|
<static> |
BigInteger.multiplyTo(n, m, r)
Multiplication of BigIntegers.
|
<static> |
BigInteger.nbits(n)
Index of the first non-zero bit starting from the least significant bit.
|
<static> |
BigInteger.negate(n)
Change sign of number.
|
<static> |
BigInteger.RshiftTo(n, k, r)
Logical shift to the right.
|
<static> |
BigInteger.squareTo(n, r)
Squaring of a BigInteger.
|
<static> |
BigInteger.subTo(n, m, r)
Subtraction of BigIntegers.
|
<static> |
BigInteger.toString(n)
Convert BigInteger to its hex representation.
|
<static> |
BigInteger.xor(n, m)
Exclusive OR of two numbers
|
Namespace Detail
BigInteger
Minimal set of high precision arithmetic operations for RSA encryption and decryption.
To preserve both defensiveness and performance, this is not an arbitrary precision library! Each number is represented by a constant length array of 256 elements. Because of tagging optimizations, each number stores 28 bits, hence the maximal precision is 7168 bits. 128 was not chosen to allow RSA on a 2048 bit modulus, and it is highly preferred to use a power of 2 to use the short dynamic accessor notation.
Author: Tom Wu (original author of JSBN), Anonymized.
- Requires:
- encoding
Method Detail
<static>
{BigInteger}
BigInteger.abs(n)
Absolute value.
- Parameters:
- {BigInteger} n
- Input number
- Returns:
- {BigInteger} If n is positive, returns n, otherwise return negate(n)
<static>
{number}
BigInteger.bitLength(n)
Index of first non-zero bit starting from the LSB of the given BigInteger.
- Parameters:
- {BigInteger} n
- Input BigInteger
- Returns:
- {number} the bit length of n.
<static>
{number}
BigInteger.compareTo(n, m)
Comparison of BigInteger.
- Parameters:
- {BigInteger} n
- First value
- {BigInteger} m
- Second value
- Returns:
- {number} A negative value if n
<static>
{BigInteger}
BigInteger.copyTo(source, target)
Copy the value of a BigInteger to another.
- Parameters:
- {BigInteger} source
- Integer to copy.
- {BigInteger} target
- Target of copy.
- Returns:
- {BigInteger} Returns the target of the copy.
<static>
{BigInteger}
BigInteger.create(v)
Create a new BigInteger initialized from the given hex value.
- Parameters:
- {string} v
- Hex representation of initial value in a string.
- Returns:
- {BigInteger} A BigInteger structure.
<static>
{BigInteger array[2]}
BigInteger.divRem(n, m)
Euclidean division of two BigIntegers.
- Parameters:
- {BigInteger} n
- First operand
- {BigInteger} m
- Second operand
- Returns:
- {BigInteger array[2]} Returns an array of two BigIntegers: first element is the quotient, second is the remainder.
<static>
{BigInteger}
BigInteger.expMod(x, e, n)
Modular exponentiation using Montgomery reduction.
- Parameters:
- {BigInteger} x
- Value to exponentiate
- {BigInteger} e
- Exponent
- {BigInteger} n
- Modulus - must be odd
- Returns:
- {BigInteger} x^e mod n
<static>
BigInteger.LshiftTo(n, k, r)
Logical shift to the left
- Parameters:
- {BigInteger} n
- Input number
- {number} k
- Number of positions to shift
- {BigInteger} r
- Target number to store the result to
<static>
{BigInteger}
BigInteger.mod(n, m)
Modular remainder of an integer division.
- Parameters:
- {BigInteger} n
- First operand
- {BigInteger} m
- Second operand
- Returns:
- {BigInteger} n mod m
<static>
BigInteger.multiplyTo(n, m, r)
Multiplication of BigIntegers.
- Parameters:
- {BigInteger} n
- First operand
- {BigInteger} m
- Second operand
- {BigInteger} r
- Target number to store the result (n*m) to.
<static>
{number}
BigInteger.nbits(n)
Index of the first non-zero bit starting from the least significant bit.
- Parameters:
- {number} n
- Input number
- Returns:
- {number} the bit length of n. Can behave strangely on negative and float values.
<static>
{BigInteger}
BigInteger.negate(n)
Change sign of number.
- Parameters:
- {BigInteger} n
- Input number
- Returns:
- {BigInteger} A newly allocated BigInteger with opposite value
<static>
BigInteger.RshiftTo(n, k, r)
Logical shift to the right.
- Parameters:
- {BigInteger} n
- Input number
- {number} k
- Number of positions to shift
- {BigInteger} r
- Target number to store the result to
<static>
BigInteger.squareTo(n, r)
Squaring of a BigInteger.
- Parameters:
- {BigInteger} n
- First operand
- {BigInteger} r
- Target number to store the result (n*n) to.
<static>
BigInteger.subTo(n, m, r)
Subtraction of BigIntegers.
- Parameters:
- {BigInteger} n
- First operand
- {BigInteger} m
- Second operand
- {BigInteger} r
- Target number to store the result (n-m) to.
<static>
{string}
BigInteger.toString(n)
Convert BigInteger to its hex representation.
- Parameters:
- {BigInteger} n
- Number to convert
- Returns:
- {string} Hex representation of n, as a string.
<static>
{BigInteger}
BigInteger.xor(n, m)
Exclusive OR of two numbers
- Parameters:
- {BigInteger} n
- First operand
- {BigInteger} m
- Second operand
- Returns:
- {BigInteger} n xor m