Hpmbmath Object Method
Introduction |
Quick References |
How Do I ... Topics |
Built-in Tools |
Scripting and Programming
In all Hpmbmath object methods, multiple-precision unsigned integer is presented
by a special kind of string, that is: a space-separated list of hex-bytes,
whatever it acts as an argument or a return value. For example, hex number:
4b fc 3b 2f eb ba 0d ae
is presented by string:
"4b fc 3b 2f eb ba 0d ae"
Later, we will use Hex String Number to refer the multiple-precision
unsigned integer in Hpmbmath object methods.
Hpmbmath object supports the following big number operation methods:
Arithmetic Operation Methods Overview
Here's a list of the arithmetic operation methods dispatched by Hpmbmath object.
Bitwise Operation Methods Overview
Here's a list of the bitwise operation methods dispatched by Hpmbmath.
- BitCount(strHex)
- returns a integer value indicating the significant bit number of the
Hex String Number strHex.
- BitLeftShift(strHex, nShift)
- shifts argument strHex left (LSB to MSB) by nShift bits
and returns a Hex String Number indicating the result.
- BitRightShift(strHex, nShift)
- shifts argument strHex right (MSB to LSB) by nShift bits
and returns a Hex String Number indicating the result.
- BitAnd(strHex1, strHex2)
- ANDs two Hex String Number (bitwise-AND) and returns a
Hex String Number indicating the result.
- BitOr(strHex1, strHex2)
- ORs two Hex String Number (bitwise-OR) and returns a
Hex String Number indicating the result.
- BitXor(strHex1, strHex2)
- exclusive-ORs two Hex String Number (bitwise-XOR) and returns a
Hex String Number indicating the result.
- BitNot(strHex)
- computes argument strHex's complement and returns a
Hex String Number indicating the result.
Number Theory Operation Methods Overview
Here's a list of the number theory operation methods dispatched by Hpmbmath.
- Mod(strHex1, strHex2)
- divides two Hex String Number and returns a Hex String Number
indicating the remainder.
- ModPow2(strHex1, strHex2)
- squares argument strHex1, then divides argument strHex2,
and returns a Hex String Number indicating the remainder.
- ModPow(strHex1, strHex2, strHex3)
- raises argument strHex1 to strHex2 power, then divides argument
strHex3, and returns a Hex String Number indicating the remainder.
- GCD(strHex1, strHex2)
- finds the Greatest Common Divisor of two arguments strHex1 and
strHex2.
- ModInverse(strHex1, strHex2)
- Computes the inverse of strHex1 modulo strHex2.
- FermatTest(strHex, nTimes)
- checks the primality of argument strHex for nTimes-times using
Fermat method, and returns a integer value indicating the result.
- SolovayStrassenTest(strHex, nTimes)
- checks the primality of argument strHex for nTimes-times using
Solovay-Strassen method, and returns a integer value indicating the result.
- MillerRabinTest(strHex, nTimes)
- checks the primality of argument strHex for nTimes-times using
Miller-Rabin method, and returns a integer value indicating the result.
- MillerRabinSearch(nBits, nTimes)
- searches for a nBits-bit random probabilistic prime and tests its
primality for nTimes-times using Miller-Rabin method.
Additional Methods Overview
Here's a list of some additional methods dispatched by Hpmbmath.
- GenRandomBits(nBits)
- generates a nBits-bit pseudo-random number and returns a
Hex String Number indicating the result.
- Swap(strHex, nUnit)
- swaps the byte order of strHex by the specified nUnit-unit
and returns a Hex String Number indicating the
result.
- Output(strHex)
- outputs a string to Hpmbcalc Scripting Host's console.
Hpmbmath Object Methods References
Script Call Syntax:
result = Compare(strHex1, strHex2)
Description:
Multiple-precision integer Compare routine. Returns an integer indicating the
result of two Hex String Number strHex1 and strHex2
comparison.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| Integer |
1 if strHex1 > strHex2, 0 if strHex1 == strHex2, or -1 if strHex1 < strHex2.
|
Script Call Syntax:
strRes = Add(strHex1, strHex2)
Description:
Multiple-precision integer Add routine. Adds argument strHex1 to argument
strHex2 and returns a Hex String Number indicating the sum.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the sum. |
Script Call Syntax:
strRes = Subtract(strHex1, strHex2)
Description:
Multiple-precision integer Subtract routine. Subtracts argument strHex2
from argument strHex1 and returns a Hex String Number indicating
the difference.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the difference. |
Script Call Syntax:
strRes = Multiply(strHex1, strHex2)
Description:
Multiple-precision integer Multiply routine. Multiplies argument strHex1
and argument strHex2 and returns a Hex String Number indicating
the product.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the product. |
Script Call Syntax:
strRes = Divide(strHex1, strHex2)
Description:
Multiple-precision integer Divide routine. Divides argument strHex1 by
argument strHex2 and returns a Hex String Number indicating the
quotient.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the quotient. |
Script Call Syntax:
strRes = Pow2(strHex)
Description:
Multiple-precision integer Square routine. Squares argument strHex returns
a Hex String Number indicating the result.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Multiple-precision integer |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the operation result. |
Script Call Syntax:
nRes = BitCount(strHex)
Description:
Multiple-precision integer BitCount routine. Counts the significant bit number
of the argument strHex and returns a integer indicating the bit number.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Multiple-precision integer |
Returns:
| Type |
Description |
| Integer |
a integer indicating the bit number. |
Script Call Syntax:
strRes = BitLeftShift(strHex, nBits)
Description:
This method shifts argument strHex left by nBits bits (LSB to MSB)
and returns a Hex String Number indicating the result.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Multiple-precision integer |
| nBits |
Integer |
The bit number to shift left |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the operation result. |
Script Call Syntax:
strRes = BitRightShift(strHex, nBits)
Description:
This method shifts argument strHex right by nBits bits (MSB to LSB)
and returns a Hex String Number indicating the result.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Multiple-precision integer |
| nBits |
Integer |
The bit number to shift right |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the operation result. |
Script Call Syntax:
strRes = BitAnd(strHex1, strHex2)
Description:
Multiple-precision integer AND routine. Bitwise-ANDs argument strHex1 with
argument strHex2 and returns a Hex String Number indicating the
result.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the operation result. |
Script Call Syntax:
strRes = BitOr(strHex1, strHex2)
Description:
Multiple-precision integer OR routine. Bitwise-ORs argument strHex1 with
argument strHex2 and returns a Hex String Number indicating the
result.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the operation result. |
Script Call Syntax:
strRes = BitXor(strHex1, strHex2)
Description:
Multiple-precision integer XOR routine. Bitwise-XORs argument strHex1 with
argument strHex2 and returns a Hex String Number indicating the
result.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the operation result. |
Script Call Syntax:
strRes = BitNot(strHex)
Description:
Multiple-precision integer complement routine. Complements argument strHex
and returns a Hex String Number indicating the result.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Multiple-precision integer |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the operation result. |
Script Call Syntax:
strRes = Mod(strHex1, strHex2)
Description:
Multiple-precision integer modulus routine. Divides argument strHex1 by
argument strHex2 and returns a Hex String Number indicating the
remainder.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the remainder. |
Script Call Syntax:
strRes = ModPow2(strHex1, strHex2)
Description:
This method squares argument strHex1, then divides by argument strHex2,
and returns a Hex String Number indicating the remainder.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the remainder. |
Script Call Syntax:
strRes = ModPow(strHex1, strHex2, strHex3)
Description:
This method raises argument strHex1 to strHex2 power, then divides by
argument strHex3, and returns a Hex String Number indicating the remainder.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
| strHex3 |
String |
Multiple-precision integer 3 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the remainder. |
Script Call Syntax:
strRes = GCD(strHex1, strHex2)
Description:
Multiple-precision integer GCD Algorithm. Finds the Greatest Common Divisor of
two arguments strHex1 and strHex2.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision integer 1 |
| strHex2 |
String |
Multiple-precision integer 2 |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the GCD of two arguments
strHex1 and strHex2 |
Script Call Syntax:
strRes = ModInverse(strHex1, strHex2)
Description:
Multiple-precision integer modular inverse. Computes the inverse of strHex1
modulo strHex2.
Parameters:
| Name |
Type |
Description |
| strHex1 |
String |
Multiple-precision number |
| strHex2 |
String |
Multiple-precision modulo |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the inverse of strHex1
modulo strHex2. strRes = "0" if the inverse does not exist. |
Script Call Syntax:
nRes = FermatTest(strHex, nTimes)
Description:
This method checks the primality of argument strHex for the times
specified by the argument nTimes using Fermat Primality Test, and returns
a integer indicating the result.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Multiple-precision integer 1 |
| nTimes |
Integer |
Primality test times |
Returns:
| Type |
Description |
| Integer |
This method returns a integer indicating the primality test result:
nRes >> 0 if strHex1 is a prime, nRes = 0 if strHex1 is not a prime,
nRes < 0 if an error occurs. |
Script Call Syntax:
nRes = SolovayStrassenTest(strHex, nTimes)
Description:
This method checks the primality of argument strHex for the times specified
by the argument nTimes using Solovay-Strassen Primality Test, and returns a
integer indicating the result.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Multiple-precision integer 1 |
| nTimes |
Integer |
Primality test times |
Returns:
| Type |
Description |
| Integer |
This method returns a integer indicating the primality test result:
nRes > 0 if strHex1 is a prime, nRes = 0 if strHex1 is not a prime,
nRes < 0 if an error occurs. |
Script Call Syntax:
nRes = MillerRabinTest(strHex, nTimes)
Description:
This method checks the primality of argument strHex for the times specified
by the argument nTimes using Miller-Rabin Primality Test, and returns a integer
indicating the result.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Multiple-precision integer 1 |
| nTimes |
Integer |
Primality test times |
Returns:
| Type |
Description |
| Integer |
This method returns a integer indicating the primality test result:
nRes > 0 if strHex1 is a prime, nRes = 0 if strHex1 is not a prime,
nRes < 0 if an error occurs. |
Script Call Syntax:
MillerRabinSearch(nBits, nTimes)
Description:
This method searches for a nBits-bit random probabilistic prime and tests
its primality for nTimes-times using Miller-Rabin method.
Parameters:
| Name |
Type |
Description |
| nBits |
Integer |
Bit length of the prime to be generated. |
| nTimes |
Integer |
Primality test times |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the generated random probabilistic prime. |
Script Call Syntax:
strRes = GenRandomBits(nBits)
Description:
This method generates nBits-bit pseudo-random number and returns a
Hex String Number indicating the result.
Parameters:
| Name |
Type |
Description |
| nBits |
Integer |
Bit length of the pseudo-random number to be generated. |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the generated pseudo-random number. |
Script Call Syntax:
strRes = Swap(strHex, nUnit)
Description:
This method swaps the byte order of strHex by the specified nUnit-unit
and returns a Hex String Number indicating the result.
Parameters:
| Name |
Type |
Description |
| strHex |
String |
Hex String Number to be swapped. |
| nUnit |
Integer |
Specifies byte number per unit. If nUnit == 0, the byte order of
strHex will be reversed. |
Returns:
| Type |
Description |
| String |
a Hex String Number indicating the result. |
Script Call Syntax:
Output(strText)
Description:
This method outputs a line of text to Hpmbcalc Scripting Host's console.
Parameters:
| Name |
Type |
Description |
| strText |
String |
Text to be outputted. |