#include <BigInteger.hpp>
Public Member Functions | |
| TBigInteger () | |
| TBigInteger (const TBigInteger< N > &rValue) | |
| TBigInteger (const IByteArray &rArray, Int iFromIndex=0) | |
| TBigInteger (const Uint8 *pui8Array, Int iSize) | |
| TBigInteger (int iValue) | |
| TBigInteger (unsigned int uiValue) | |
| TBigInteger (Uint32 ui32Value) | |
| TBigInteger (Int32 i32Value) | |
| TBigInteger (Uint64 ui64Value) | |
| TBigInteger (Int64 i64Value) | |
| Int | getBitSize () const |
| Int | getByteSize () const |
| Int | getBitLength () const |
| bool | isNegative () const |
| bool | isZero () const |
| TBigInteger< N > & | add (const TBigInteger< N > &rParam) |
| TBigInteger< N > & | add (int iParam) |
| TBigInteger< N > & | add (unsigned int uiParam) |
| void | assign (const TBigInteger< N > &rParam) |
| void | clear () |
| Int | compareTo (const TBigInteger< N > &rParam) const |
| TBigInteger< N > & | divide (const TBigInteger< N > &rParam) |
| TBigInteger< N > & | divideExt (const TBigInteger< N > &rParam, TBigInteger< N > &rModulo) |
| TBigInteger< N > | getNegated () const |
| TBigInteger< N > | getLeftShifted (Int iShift) const |
| TBigInteger< N > | getRightShifted (Int iShift) const |
| TBigInteger< N > | getSubtracted (const TBigInteger< N > &rParam) const |
| TBigInteger< N > & | mod (const TBigInteger< N > &rParam) |
| TBigInteger< N > & | modpow (const TBigInteger< N > &rExp, const TBigInteger< N > &rMod) |
| TBigInteger< N > & | negate () |
| void | shiftLeft (Int iShift) |
| void | shiftRight (Int iShift) |
| TBigInteger< N > & | subtract (const TBigInteger< N > &rParam) |
| TBigInteger< N > & | multiply (const TBigInteger< N > &rParam) |
| void | toByteArray (IByteArray &rData, Int iSize=N) const |
| void | appendToByteArray (IByteArray &rData, Int iSize=N) const |
| TBigInteger< N > & | operator= (const TBigInteger< N > &rParam) |
| bool | operator== (const TBigInteger< N > &rParam) const |
| bool | operator!= (const TBigInteger< N > &rParam) const |
| bool | operator< (const TBigInteger< N > &rParam) const |
| bool | operator> (const TBigInteger< N > &rParam) const |
| TBigInteger< N > | operator+ (const TBigInteger< N > &rParam) |
| TBigInteger< N > | operator- (const TBigInteger< N > &rParam) const |
| TBigInteger< N > | operator- () |
| TBigInteger< N > | operator* (const TBigInteger< N > &rParam) const |
| TBigInteger< N > | operator/ (const TBigInteger< N > &rParam) const |
| TBigInteger< N > | operator% (const TBigInteger< N > &rParam) const |
Static Public Member Functions | |
| static TBigInteger< N > | createFromHex (const TString &rHexString) |
Protected Member Functions | |
| void | assign32bit (Uint32 ui64Value, bool bNegative) |
| void | assign64bit (Uint64 ui64Value, bool bNegative) |
Static Protected Member Functions | |
| static void | divide_internal (const Uint8 *pui8Divisor, Uint8 *pui8Base, Uint8 *pui8Modulo) |
| static void | mod_internal (const Uint8 *pui8Divisor, const Uint8 *pui8NegDivisor, Uint8 *pui8Modulo) |
| static void | multiply_internal (const Uint8 *pui8Data1, Uint8 *pui8Data2) |
| static void | multiply_karatsuba (const Uint8 *pui8Data1, const Uint8 *pui8Data2, Uint8 *pui8Result) |
| static Int | compareTo_internal (const Uint8 *pui8Data1, const Uint8 *pui8Data2) |
| static Int | compareTo_positive (const Uint8 *pui8Data1, const Uint8 *pui8Data2, Int iSize) |
| static Int | getLastSignPos (const Uint8 *pui8Data, Int iSize) |
implements big integers with bit size >= 64bits
| zeus::TBigInteger< N >::TBigInteger | ( | ) | [inline] |
creates an empty big number (zero)
| zeus::TBigInteger< N >::TBigInteger | ( | const TBigInteger< N > & | rValue ) | [inline] |
copy constructor
| rValue | : number ro copy |
| zeus::TBigInteger< N >::TBigInteger | ( | const IByteArray & | rArray, |
| Int | iFromIndex = 0 |
||
| ) | [inline] |
creates a big number out of a byte array
| rArray | : array object |
| iFromIndex | : index to get the number from the array |
| zeus::TBigInteger< N >::TBigInteger | ( | const Uint8 * | pui8Array, |
| Int | iSize | ||
| ) | [inline] |
creates a big number out of a byte array
| rArray | : array object |
| iFromIndex | : index to get the number from the array |
| zeus::TBigInteger< N >::TBigInteger | ( | int | iValue ) | [inline] |
creates a big number out of a integer (signed)
| iValue | : simple integer valaue |
| zeus::TBigInteger< N >::TBigInteger | ( | unsigned int | uiValue ) | [inline] |
creates a big number out of a integer (unsigned signed)
| uiValue | : simple unsigned integer valaue |
| zeus::TBigInteger< N >::TBigInteger | ( | Uint32 | ui32Value ) | [inline] |
creates a big number out of a uint32
| ulValue | : simple unsigned integer valaue |
| zeus::TBigInteger< N >::TBigInteger | ( | Int32 | i32Value ) | [inline] |
creates a big number out of a int32
| lValue | : simple integer valaue |
| zeus::TBigInteger< N >::TBigInteger | ( | Uint64 | ui64Value ) | [inline] |
creates a big number out of a uint64
| uldValue | : simple unsigned integer valaue |
| zeus::TBigInteger< N >::TBigInteger | ( | Int64 | i64Value ) | [inline] |
creates a big number out of a int64
| ldValue | : simple integer valaue |
| TBigInteger<N>& zeus::TBigInteger< N >::add | ( | const TBigInteger< N > & | rParam ) | [inline] |
adds an other big number to this number
| rParam | : big number to add |
| TBigInteger<N>& zeus::TBigInteger< N >::add | ( | int | iParam ) | [inline] |
adds a simple integer number to this big number
| iParam | : simple number to add |
| TBigInteger<N>& zeus::TBigInteger< N >::add | ( | unsigned int | uiParam ) | [inline] |
adds a simple unsigned integer number to this big number
| uiParam | : simple number to add |
| void zeus::TBigInteger< N >::appendToByteArray | ( | IByteArray & | rData, |
| Int | iSize = N |
||
| ) | const [inline] |
Converts the big integer into a byte array and appends it at the end of an existing array
| rData | : [OUT] array |
| iSize | : [IN] size to add |
| void zeus::TBigInteger< N >::assign | ( | const TBigInteger< N > & | rParam ) | [inline] |
assigns a new big integer value to this container
| rParam | : value to assign |
| void zeus::TBigInteger< N >::assign32bit | ( | Uint32 | ui32Value, |
| bool | bNegative | ||
| ) | [protected] |
assigns a 32bit value
| ui32Value | : value to assign |
| bNegative | : represents a negative value = true |
| void zeus::TBigInteger< N >::assign64bit | ( | Uint64 | ui64Value, |
| bool | bNegative | ||
| ) | [protected] |
assigns a int64 value
| uldValue | : value to assign |
| bNegative | : represents a negative value = true |
| void zeus::TBigInteger< N >::clear | ( | ) | [inline] |
clears the big number. The big number is zero after this operation
| Int zeus::TBigInteger< N >::compareTo | ( | const TBigInteger< N > & | rParam ) | const [inline] |
compares two big integers and returns 0 if they are equal, < 0 if the this is smaller or > 0 is the this is bigger
| rParam | : value to check |
| < | 0 : this < rParam |
| 0 | : this == rParam > 0 : this > rParam |
| Int zeus::TBigInteger< N >::compareTo_internal | ( | const Uint8 * | pui8Data1, |
| const Uint8 * | pui8Data2 | ||
| ) | [static, protected] |
compares two big integers and returns 0 if they are equal, < 0 if the this is smaller or > 0 is the this is bigger
| rParam | : value to check |
| < | 0 : pui8Data1 < pui8Data2 |
| 0 | : pui8Data1 == pui8Data2 > 0 : pui8Data1 > pui8Data2 |
| Int zeus::TBigInteger< N >::compareTo_positive | ( | const Uint8 * | pui8Data1, |
| const Uint8 * | pui8Data2, | ||
| Int | iSize | ||
| ) | [static, protected] |
compares two big integers and returns 0 if they are equal, < 0 if the this is smaller or > 0 is the this is bigger. In contrast to compareTo_internal only positive numbers are checked
| pui8Data1 | : value 1 to check |
| pui8Data2 | : value 2 to check |
| iSize | : size of the smallest value |
| < | 0 : pui8Data1 < pui8Data2 |
| 0 | : pui8Data1 == pui8Data2 > 0 : pui8Data1 > pui8Data2 |
| static TBigInteger<N> zeus::TBigInteger< N >::createFromHex | ( | const TString & | rHexString ) | [inline, static] |
Creates a new big integer from a hex based string
| rHexString | : string containing hex number |
| TBigInteger<N>& zeus::TBigInteger< N >::divide | ( | const TBigInteger< N > & | rParam ) | [inline] |
divides this big number by a divisors
| rParam | : divisor |
| void zeus::TBigInteger< N >::divide_internal | ( | const Uint8 * | pui8Divisor, |
| Uint8 * | pui8Base, | ||
| Uint8 * | pui8Modulo | ||
| ) | [static, protected] |
divides two big integers
| pui8Divisor | : [IN] divisor |
| pui8Base | : [INOUT] base and result of the division |
| pui8Modulo | : [OUT] modulo of the division |
| TBigInteger<N>& zeus::TBigInteger< N >::divideExt | ( | const TBigInteger< N > & | rParam, |
| TBigInteger< N > & | rModulo | ||
| ) | [inline] |
divides this big number by a divisors
| rParam | : divisor |
| Int zeus::TBigInteger< N >::getBitLength | ( | ) | const [inline] |
in contrast to getBitSize() this returns the effective length in bits of the number
| Int zeus::TBigInteger< N >::getBitSize | ( | ) | const [inline] |
returns the size of the number memory in bits TBigInteger<64> will return 512
| Int zeus::TBigInteger< N >::getByteSize | ( | ) | const [inline] |
returns the size of the number memory in bytes TBigInteger<64> will return 64
| static Int zeus::TBigInteger< N >::getLastSignPos | ( | const Uint8 * | pui8Data, |
| Int | iSize | ||
| ) | [inline, static, protected] |
returns the position of the last sign
| TBigInteger<N> zeus::TBigInteger< N >::getLeftShifted | ( | Int | iShift ) | const [inline] |
returns the value shiftet by iShift. The content of this big value is not changed. Use shiftLeft() to directly shift a value.
| iShift | : shift in bits |
| TBigInteger<N> zeus::TBigInteger< N >::getNegated | ( | ) | const [inline] |
Returns the negation of this value. The content of this big value is not changed. Use negate() to directly negate a value.
| TBigInteger<N> zeus::TBigInteger< N >::getRightShifted | ( | Int | iShift ) | const [inline] |
returns the value shiftet by iShift. The content of this big value is not changed. Use shiftLeft() to directly shift a value.
| iShift | : shift in bits |
| TBigInteger<N> zeus::TBigInteger< N >::getSubtracted | ( | const TBigInteger< N > & | rParam ) | const [inline] |
returns the subtracted value. The content of this big value is not changed. Use substract() to directly substract a value.
| rParam | : value to subtract |
| bool zeus::TBigInteger< N >::isNegative | ( | ) | const [inline] |
Checks if the number is negative
| true | : number is negative |
| false,: | number is not negative (zero or positive) |
| bool zeus::TBigInteger< N >::isZero | ( | ) | const [inline] |
returns true if the number is zero
| true | : number is zero |
| false,: | number is non zero |
| TBigInteger<N>& zeus::TBigInteger< N >::mod | ( | const TBigInteger< N > & | rParam ) | [inline] |
Applies the modulus operation to this value.
| rParam | : modulus |
| void zeus::TBigInteger< N >::mod_internal | ( | const Uint8 * | pui8Divisor, |
| const Uint8 * | pui8NegDivisor, | ||
| Uint8 * | pui8Modulo | ||
| ) | [static, protected] |
implements a fast modulo method. In contrast to the divide_internal, only the modulus relevant implementation is kept.
| pui8Divisor | : [IN] divisor |
| pui8NegDivisor | : [IN] inverse divisor |
| pui8Modulo | : [INOUT] inputs the base and returns the modulo of the division |
| TBigInteger<N>& zeus::TBigInteger< N >::modpow | ( | const TBigInteger< N > & | rExp, |
| const TBigInteger< N > & | rMod | ||
| ) | [inline] |
returns the modulus of an exponential term. this = (this ^ exp) mod n. Fast and simple algorithm was found at http://en.wikipedia.org/wiki/Modular_exponentiation
| rExp | : exponent |
| rMod | : modulo |
| TBigInteger<N>& zeus::TBigInteger< N >::multiply | ( | const TBigInteger< N > & | rParam ) | [inline] |
multiplies two big numbers together
| rParam | : value to multiply |
| void zeus::TBigInteger< N >::multiply_internal | ( | const Uint8 * | pui8Data1, |
| Uint8 * | pui8Data2 | ||
| ) | [static, protected] |
internal method to multiply two big numbers together
| pui8Data1 | : [IN] first number of size N |
| pui8Data2 | : [INOUT] second number and result of size N |
| void zeus::TBigInteger< N >::multiply_karatsuba | ( | const Uint8 * | pui8Data1, |
| const Uint8 * | pui8Data2, | ||
| Uint8 * | pui8Result | ||
| ) | [static, protected] |
multiplies two big numbers together using the karatsuba algorithm. This algorithm is more efficient than the conventional multiplications O(n^1.585) instead of O(n^2). Since for smaller numbers the conventional multiplication is as fast we use the karatsuba for bit length over 3200bits (400*8).
| pui8Data1 | : [IN] first number of size N |
| pui8Data2 | : [IN] second number of size N |
| pui8Result | : [OUT] result of size N*N. The result buffer must be at zero before starting |
| TBigInteger<N>& zeus::TBigInteger< N >::negate | ( | ) | [inline] |
Negates the big integer value
| bool zeus::TBigInteger< N >::operator!= | ( | const TBigInteger< N > & | rParam ) | const [inline] |
checks if two big numbers are unequal
| rParam | : big number to check |
| true | : are not equal |
| false,: | are equal |
| TBigInteger<N> zeus::TBigInteger< N >::operator% | ( | const TBigInteger< N > & | rParam ) | const [inline] |
modulo of two values
| TBigInteger<N> zeus::TBigInteger< N >::operator* | ( | const TBigInteger< N > & | rParam ) | const [inline] |
Multiplies two values
| TBigInteger<N> zeus::TBigInteger< N >::operator+ | ( | const TBigInteger< N > & | rParam ) | [inline] |
Adds two values
| TBigInteger<N> zeus::TBigInteger< N >::operator- | ( | ) | [inline] |
unary negative operator
| TBigInteger<N> zeus::TBigInteger< N >::operator- | ( | const TBigInteger< N > & | rParam ) | const [inline] |
subtracts two values
| TBigInteger<N> zeus::TBigInteger< N >::operator/ | ( | const TBigInteger< N > & | rParam ) | const [inline] |
divides two values
| bool zeus::TBigInteger< N >::operator< | ( | const TBigInteger< N > & | rParam ) | const [inline] |
checks if the given integer is bigger
| rParam | : big number to check |
| true | : rParam is bigger |
| false,: | rParam is smaller |
| TBigInteger<N>& zeus::TBigInteger< N >::operator= | ( | const TBigInteger< N > & | rParam ) | [inline] |
assign a new big integer to this value
| bool zeus::TBigInteger< N >::operator== | ( | const TBigInteger< N > & | rParam ) | const [inline] |
checks if two big numbers are equal
| rParam | : big number to check |
| true | : are equal |
| false,: | not equal |
| bool zeus::TBigInteger< N >::operator> | ( | const TBigInteger< N > & | rParam ) | const [inline] |
checks if the given integer is smaller
| rParam | : big number to check |
| true | : rParam is smaller |
| false,: | rParam is bigger |
| void zeus::TBigInteger< N >::shiftLeft | ( | Int | iShift ) | [inline] |
shifts the big number to left
| iShift | : bits to shift |
| void zeus::TBigInteger< N >::shiftRight | ( | Int | iShift ) | [inline] |
shifts the big number to right
| iShift | : bits to shift |
| TBigInteger<N>& zeus::TBigInteger< N >::subtract | ( | const TBigInteger< N > & | rParam ) | [inline] |
subtracts a big value from this value
| rParam | : value to subtract |
| void zeus::TBigInteger< N >::toByteArray | ( | IByteArray & | rData, |
| Int | iSize = N |
||
| ) | const [inline] |
Converts the big integer into a byte array
| rData | : [OUT] array |
| iSize | : [IN] size to add |