Hpmbmath Object Method

IntroductionQuick ReferencesHow Do I ... TopicsBuilt-in ToolsScripting 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.


Number Theory Operation Methods Overview

Here's a list of the number theory operation methods dispatched by Hpmbmath.


Additional Methods Overview

Here's a list of some additional methods dispatched by Hpmbmath.


Hpmbmath Object Methods References

Compare()

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.

Add()

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.

Subtract()

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.

Multiply()

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.

Divide()

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.

Pow2()

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.

BitCount()

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.

BitLeftShift()

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.

BitRightShift()

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.

BitAnd()

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.

BitOr()

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.

BitXor()

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.

BitNot()

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.

Mod()

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.

ModPow2()

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.

ModPow()

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.

GCD()

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

ModInverse()

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.

FermatTest()

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.

SolovayStrassenTest()

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.

MillerRabinTest()

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.

MillerRabinSearch()

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.

GenRandomBits()

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.

Swap()

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.

Output()

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.