Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cBigInteger Class Reference

#include <cBigInteger.h>

Inheritance diagram for GrayLib::cBigInteger:
GrayLib::cBigUnsigned GrayLib::cBitArray GrayLib::cBitArrayStatic Gray::cBits

Public Member Functions

 cBigInteger ()
 
 cBigInteger (const THIS_t &x)
 
 cBigInteger (const cBigUnsigned &x, bool bNegative=false)
 
 cBigInteger (const char *pszStr, RADIX_t uRadix=10)
 
 cBigInteger (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks, bool bNegative)
 
 cBigInteger (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks, bool bStatic, bool bNegative)
 
 cBigInteger (UINTMAX_t x)
 
 cBigInteger (INTMAX_t x)
 
 cBigInteger (UINT32 x)
 
 cBigInteger (INT32 x)
 
bool isNegative () const
 
int get_Sign () const
 
const cBigUnsignedget_Magnitude () const
 
COMPARE_t CompareU (BLOCK_t x) const
 
COMPARE_t CompareS (BLOCKI_t x) const
 
COMPARE_t Compare (const cBigInteger &x) const
 
COMPARE_t CompareMagnitude (const cBigUnsigned &x) const
 
bool IsEqual (const THIS_t &x) const
 
bool IsEqual (BLOCKI_t x) const
 
bool operator== (const THIS_t &x) const
 
bool operator!= (const THIS_t &x) const
 
bool operator< (const THIS_t &x) const
 
bool operator<= (const THIS_t &x) const
 
bool operator>= (const THIS_t &x) const
 
bool operator> (const THIS_t &x) const
 
template<typename TYPE >
TYPE get_ValS () const
 
template<typename TYPE >
TYPE get_Val () const
 
StrLen_t GetStr (char *pszOut, StrLen_t iOutMax, RADIX_t uRadix=10) const
 
cString GetStr (RADIX_t uRadix=10) const
 
bool SetStr (const char *pszIn, RADIX_t uRadix=10, const char **ppszEnd=nullptr)
 
HRESULT SetBinaryBE (const BYTE *pData, size_t nSize, bool bByteSign)
 
HRESULT SetBinaryBE (const cMemBlock &b, bool bByteSign)
 
HRESULT GetBinaryBE (BYTE *pOut, size_t nSizeOut) const
 
void SetCopyInt (const cBigInteger &x)
 
HRESULT SetCopySecure (const THIS_t &val, bool assign)
 
void operator= (const THIS_t &x)
 
void SetZeroAll ()
 
void SetNullVal ()
 
void put_ValU (UINTMAX_t n)
 
void put_ValS (INTMAX_t n)
 
template<typename TYPE >
void put_Val (TYPE n)
 
void SetBlocksStatic (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks)
 
void SetBlocksStatic (const cBitArrayStatic &b)
 
void OpAdd1 (BLOCKI_t n)
 
void OpSubtract1 (BLOCKI_t n)
 
void InitAdd (const cBigInteger &a, const cBigInteger &b)
 
void InitAddU (const cBigUnsigned &a, const cBigUnsigned &b)
 
void InitSubtract (const cBigInteger &a, const cBigInteger &b)
 
HRESULT InitSubU (const cBigUnsigned &a, const cBigUnsigned &b)
 
void OpSubtract (const THIS_t &b)
 
HRESULT OpSubtractU (const cBigUnsigned &a)
 
void InitSubtract1 (const THIS_t &a, BLOCKI_t n)
 
void InitAdd1 (const THIS_t &a, BLOCKI_t n)
 
void InitMultiply (const cBigInteger &a, const cBigInteger &b)
 
HRESULT InitDivide (const cBigInteger &dividend, const cBigInteger &divisor, OUT cBigInteger &remainder)
 
HRESULT InitDivide (const THIS_t &a, const cBigInteger &b)
 
HRESULT InitModulus (const THIS_t &a, const THIS_t &b)
 
HRESULT InitModulusU (const THIS_t &a, const THIS_t &b)
 
BLOCK_t GetModulusH (BLOCKH_t b) const
 
cBigInteger operator+ (const THIS_t &x) const
 
cBigInteger operator- (const THIS_t &x) const
 
cBigInteger operator* (const THIS_t &x) const
 
cBigInteger operator/ (const THIS_t &x) const
 
cBigInteger operator% (const THIS_t &x) const
 
cBigInteger operator- () const
 
void operator+= (const THIS_t &x)
 
void operator-= (const THIS_t &x)
 
void operator*= (const THIS_t &x)
 
void operator/= (const THIS_t &x)
 
void operator%= (const THIS_t &x)
 
void CheckNegativeZero ()
 
void put_Negative (bool b=true)
 
void put_Sign (int nSign)
 
void FlipSign ()
 
void operator++ ()
 
void operator++ (int)
 
void operator-- ()
 
void operator-- (int)
 
void InitGreatestCommonDivisor (const cBigInteger &a, const cBigInteger &b)
 
HRESULT InitModInv (const cBigInteger &A, const cBigInteger &N)
 
HRESULT SetPowerMod (const THIS_t &base, const THIS_t &exponent, const THIS_t &modulus, OUT cBigUnsigned *pRR)
 
 UNITTEST_FRIEND (cBigInteger)
 
template<>
INT64 get_Val () const
 
template<>
void put_Val (long n)
 
template<>
void put_Val (int n)
 
template<>
void put_Val (short n)
 
- Public Member Functions inherited from GrayLib::cBigUnsigned
 cBigUnsigned ()
 
 cBigUnsigned (const cBigUnsigned &x)
 
 cBigUnsigned (BIT_ENUM_t nBits, BLOCK_t uValMask)
 
 cBigUnsigned (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks)
 
 cBigUnsigned (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks, bool bStatic)
 
 cBigUnsigned (const char *pszStr, RADIX_t nBaseRadix=10)
 
 ~cBigUnsigned ()
 
 cBigUnsigned (UINTMAX_t x)
 
 cBigUnsigned (INTMAX_t x)
 
 cBigUnsigned (UINT32 x)
 
 cBigUnsigned (INT32 x)
 
void SetBlockSizeInit (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks)
 
bool isZero () const
 
bool isOdd () const
 
template<typename TYPE >
TYPE get_ValU () const
 
template<typename TYPE >
TYPE get_ValUC () const
 
template<typename TYPE >
TYPE get_ValS () const
 
template<typename TYPE >
TYPE get_Val () const
 
COMPARE_t CompareU (BLOCK_t x) const
 Compare against primitive type for speed. More...
 
bool operator== (BLOCK_t x) const
 
bool operator!= (BLOCK_t x) const
 
bool operator< (BLOCK_t x) const
 
bool operator<= (BLOCK_t x) const
 
bool operator>= (BLOCK_t x) const
 
bool operator> (BLOCK_t x) const
 
COMPARE_t Compare (const cBigUnsigned &x) const
 Compares this to x like Perl's <=> More...
 
bool operator== (const cBigUnsigned &x) const
 
bool operator!= (const cBigUnsigned &x) const
 
bool operator< (const cBigUnsigned &x) const
 
bool operator<= (const cBigUnsigned &x) const
 
bool operator>= (const cBigUnsigned &x) const
 
bool operator> (const cBigUnsigned &x) const
 
StrLen_t GetStr (char *pszOut, StrLen_t iOutMax, RADIX_t nBaseRadix=10) const
 
cString GetStr (RADIX_t nBaseRadix=10) const
 
bool SetStr (const char *pszVal, RADIX_t nBaseRadix=10, const char **ppszEnd=(const char **) nullptr)
 
void put_ValU (UINTMAX_t n)
 
HRESULT put_ValS (INTMAX_t n)
 
template<typename TYPE >
void put_Val (TYPE n)
 
void InitBitAnd (const cBigUnsigned &a, const cBigUnsigned &b)
 
void InitBitOr (const cBigUnsigned &a, const cBigUnsigned &b)
 
void InitBitXor (const cBigUnsigned &a, const cBigUnsigned &b)
 
HRESULT InitBitShiftLeft (const cBigUnsigned &a, int b)
 
HRESULT InitBitShiftRight (const cBigUnsigned &a, int b)
 
void OpBitShiftLeft1 (BLOCK_t nBitMask=0)
 
HRESULT OpBitShiftLeft (BIT_ENUM_t b)
 
HRESULT OpBitShiftRight (BIT_ENUM_t b)
 
void OpAdd1 (BLOCK_t nVal)
 
HRESULT OpSubtract1 (BLOCK_t nVal)
 
void InitSubtract1 (const THIS_t &a, BLOCK_t n)
 
void InitAdd (const cBigUnsigned &a, const cBigUnsigned &b)
 
HRESULT InitSubtract (const cBigUnsigned &a, const cBigUnsigned &b)
 
HRESULT OpSubtract (const THIS_t &b)
 
void InitMultiply1 (const cBigUnsigned &a, BLOCK_t b)
 
void InitMultiplyH (const cBigUnsigned &a, BLOCKH_t b)
 
void InitMultiply (const cBigUnsigned &a, const cBigUnsigned &b)
 
BLOCK_t GetModulusH (BLOCKH_t b) const
 
BLOCKH_t InitDivideH (const cBigUnsigned &a, BLOCKH_t b)
 
HRESULT InitDivide (const cBigUnsigned &a, const cBigUnsigned &b, OUT cBigUnsigned &remainder)
 
HRESULT InitDivide (const THIS_t &a, const THIS_t &b)
 
HRESULT InitModulus (const THIS_t &a, const THIS_t &b)
 
HRESULT InitModInv (const cBigUnsigned &A, const cBigUnsigned &N)
 
HRESULT SetRandomBits2 (BIT_ENUM_t nBits, IRandomNoise *pRandom=nullptr)
 
HRESULT SetRandomBits (BIT_ENUM_t nBits, IRandomNoise *pRandom=nullptr)
 
BLOCK_t get_MontgomeryInit () const
 
void SetMontMul (THIS_t &rDst, const THIS_t &B, const THIS_t &N, BLOCK_t mm)
 
void SetMontRedux (THIS_t &rDst, const THIS_t &N, BLOCK_t mm)
 
void SetPower (const THIS_t &base, const THIS_t &exponent)
 
HRESULT SetPowerMod (const THIS_t &base, const THIS_t &exponent, const THIS_t &modulus, OUT THIS_t *pRR=nullptr)
 
BITOP_TYPE TestPrimeSmall () const
 
HRESULT TestPrimeMiller (IRandomNoise *pRandom=nullptr) const
 
HRESULT TestPrimeFermat (IRandomNoise *pRandom=nullptr) const
 
HRESULT TestPrime (IRandomNoise *pRandom=nullptr) const
 
HRESULT SetPrimePrev (IRandomNoise *pRandom=nullptr, cThreadState *pCancel=nullptr)
 
HRESULT SetPrimeBits (BIT_ENUM_t nBits, IRandomNoise *pRandom=nullptr, cThreadState *pCancel=nullptr)
 
HRESULT SetPrimeBitsDH (BIT_ENUM_t nbits, IRandomNoise *pRandom=nullptr, cThreadState *pCancel=nullptr)
 
cBigUnsigned operator+ (const THIS_t &x) const
 Overloaded return-by-value operators. More...
 
cBigUnsigned operator+ (BLOCK_t x) const
 
cBigUnsigned operator- (const THIS_t &x) const
 
cBigUnsigned operator- (BLOCK_t x) const
 
cBigUnsigned operator* (const THIS_t &x) const
 
cBigUnsigned operator* (BLOCKH_t x) const
 
cBigUnsigned operator/ (const THIS_t &x) const
 
cBigUnsigned operator/ (BLOCKH_t n) const
 
cBigUnsigned operator% (const THIS_t &x) const
 
BLOCKH_t operator% (BLOCKH_t n) const
 
cBigUnsigned operator& (const THIS_t &x) const
 
cBigUnsigned operator| (const THIS_t &x) const
 
cBigUnsigned operator^ (const THIS_t &x) const
 
cBigUnsigned operator<< (int b) const
 
cBigUnsigned operator>> (int b) const
 
void operator+= (const THIS_t &x)
 
void operator+= (BLOCK_t x)
 
void operator-= (const THIS_t &x)
 
void operator-= (BLOCK_t x)
 
void operator*= (const THIS_t &x)
 
void operator*= (BLOCKH_t x)
 
void operator/= (const THIS_t &x)
 
void operator/= (BLOCKH_t n)
 
void operator%= (const THIS_t &x)
 
void operator%= (BLOCKH_t n)
 
void operator&= (const THIS_t &x)
 
void operator|= (const THIS_t &x)
 
void operator^= (const THIS_t &x)
 
void operator<<= (int b)
 
void operator>>= (int b)
 
void operator++ ()
 
void operator++ (int)
 
void operator-- ()
 
void operator-- (int)
 
 UNITTEST_FRIEND (cBigUnsigned)
 
template<>
long get_Val () const
 overloads to get signed value correctly. More...
 
template<>
void put_Val (long n)
 
template<>
void put_Val (int n)
 
template<>
void put_Val (short n)
 
- Public Member Functions inherited from GrayLib::cBitArray
bool isHighBlockUseExact () const
 
bool isHighBlockUseValid () const
 
BLOCK_ENUM_t get_BlocksUse () const
 
void UpdateBlocksUse ()
 
void UpdateBlocksUseMax (BLOCK_ENUM_t nBlocksUseMax)
 
void UpdateBlocksUseCap ()
 
BLOCK_tRefBlock (BLOCK_ENUM_t nBlock)
 
 cBitArray ()
 
 cBitArray (BIT_ENUM_t nBits)
 
 cBitArray (BIT_ENUM_t nBits, BLOCK_t uValueMask)
 
 cBitArray (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks)
 
 cBitArray (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks, bool bStatic)
 
 ~cBitArray ()
 
void SetBlocksStatic (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks)
 
void SetBlocksStatic (const cBitArrayStatic &b)
 
HRESULT SetBlockSizeGrow (BLOCK_ENUM_t nBlocksNew)
 
HRESULT SetBlockSizeShrink (BLOCK_ENUM_t nBlocksNew)
 
void SetBlockSizeUse (BLOCK_ENUM_t nBlocksNew)
 
bool IsEqual (const THIS_t &x) const
 
bool IsEqualU (BLOCK_t x) const
 
bool operator== (const THIS_t &x) const
 
bool operator!= (const THIS_t &x) const
 
bool isEmptyBits () const
 
bool IsSet (BIT_ENUM_t nBit) const
 
BIT_ENUM_t get_Lowest1Bit () const
 
BIT_ENUM_t get_Highest1Bit () const
 
BIT_ENUM_t get_Count1Bits () const
 
void SetBit (BIT_ENUM_t nBit)
 
void ClrBit (BIT_ENUM_t nBit)
 
void ModBit (BIT_ENUM_t nBit, bool bVal)
 
void SetTruncateBits (BIT_ENUM_t nBits)
 
HRESULT SetRandomBits (BIT_ENUM_t nBits, IRandomNoise *pRandom=nullptr)
 
HRESULT SetRandomBitsLarge (BIT_ENUM_t nBits, IRandomNoise *pRandom=nullptr)
 
void SetCopyBits (const THIS_t &ref)
 
HRESULT SetCopySecure (const THIS_t &val, bool assign)
 
void SetZeroAll ()
 
void SetNullVal ()
 
size_t get_BinarySize () const
 
HRESULT GetBinaryBE (BYTE *pOut, size_t nSizeOut) const
 
HRESULT GetBinaryBE (cHeapBlock &b) const
 
HRESULT SetBinaryBE (const BYTE *pData, size_t nSize)
 
HRESULT SetBinaryLE (const BYTE *pData, size_t nSize)
 
 UNITTEST_FRIEND (cBitArray)
 
- Public Member Functions inherited from GrayLib::cBitArrayStatic
 cBitArrayStatic () noexcept
 
 cBitArrayStatic (BIT_ENUM_t nBits)
 
 cBitArrayStatic (BIT_ENUM_t nBits, BLOCK_t uValueMask)
 
 cBitArrayStatic (BLOCK_ENUM_t nBlocks, const BLOCK_t *pData)
 
 cBitArrayStatic (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocksInit, bool bStatic)
 
 cBitArrayStatic (const THIS_t &ref)
 
 cBitArrayStatic (THIS_t &&ref) noexcept
 
 ~cBitArrayStatic ()
 
bool isNullVal () const noexcept
 
bool isZeroVal () const noexcept
 
BLOCK_ENUM_t get_BlocksCap () const noexcept
 
size_t get_BytesCap () const noexcept
 
BLOCK_t GetBlockInt (BLOCK_ENUM_t i) const
 
const BLOCK_tget_BlockPtrC () const noexcept
 
BLOCK_tget_BlockPtr ()
 
BLOCK_tRefBlockInt (BLOCK_ENUM_t i)
 
UINT32 GetU32Int (BLOCK_ENUM_t j) const
 
void SetU32Int (BLOCK_ENUM_t j, UINT32 val32)
 
const THIS_toperator= (const THIS_t &ref)
 
THIS_toperator= (THIS_t &&ref)
 
bool isStatic () const noexcept
 
void SetBlocksStatic (BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks)
 
bool isReadOnly () const noexcept
 
BIT_ENUM_t get_BitsCap () const noexcept
 
bool IsValidBit (BIT_ENUM_t nBit) const noexcept
 
bool IsSet (BIT_ENUM_t nBit) const
 
bool isOdd () const
 
void ClrBit (BIT_ENUM_t nBit)
 
void SetBit (BIT_ENUM_t nBit)
 
bool SetBitRet (BIT_ENUM_t nBit)
 
void ModBit (BIT_ENUM_t nBit, bool bVal)
 
void SetNullVal () noexcept
 
void SetZeroAll ()
 
void SetAll1 ()
 
void SetBitsSizeZ (BIT_ENUM_t nBits)
 
void SetInvertBytes (size_t nSize)
 
void SetCopyBits (const THIS_t &ref)
 

Static Public Member Functions

static HRESULT GRAYCALL SwapSecure (THIS_t &X, THIS_t &Y, bool swap)
 
static HRESULT GRAYCALL ExtendedEuclidean (const cBigUnsigned &m, const cBigUnsigned &n, cBigUnsigned &g, cBigInteger &r, cBigInteger &s)
 
- Static Public Member Functions inherited from GrayLib::cBigUnsigned
static void MultiplyHelper (BLOCK_t *pDst, BLOCK_ENUM_t nBlocks, const cBigUnsigned &rSrc, BLOCK_t nMult)
 
static void GRAYCALL EuclideanAlgorithm (const cBigUnsigned &x, const cBigUnsigned &y, OUT cBigUnsigned &a, OUT cBigUnsigned &b, OUT cBigUnsigned &g)
 
static cBigUnsigned GRAYCALL GetGreatestCommonDivisor (const cBigUnsigned &x, const cBigUnsigned &y)
 
- Static Public Member Functions inherited from GrayLib::cBitArray
static HRESULT GRAYCALL ReturnError (HRESULT hRes, const char *pszMsg)
 
static HRESULT GRAYCALL SwapSecure (THIS_t &X, THIS_t &Y, bool swap)
 
- Static Public Member Functions inherited from GrayLib::cBitArrayStatic
static BLOCK_ENUM_t GetBlocksFromBits (BIT_ENUM_t nBits) noexcept
 
static BLOCK_ENUM_t GetBlocksFromBytes (size_t nBytes) noexcept
 
static bool IsReasonableBlockQty (BLOCK_ENUM_t nBlocks) noexcept
 
- Static Public Member Functions inherited from Gray::cBits
static constexpr size_t GetSizeBytes (BIT_ENUM_t nBits) noexcept
 
template<typename TYPE >
static constexpr TYPE Mask1 (BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr bool IsMask1 (TYPE nVal) noexcept
 
template<typename TYPE >
static constexpr bool IsSet (TYPE nVal, BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr bool IsClear (TYPE nVal, BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr TYPE SetBit (TYPE nVal, BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr TYPE ClearBit (TYPE nVal, BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr bool HasMask (TYPE nVal, TYPE nMask) noexcept
 
template<typename TYPE >
static BIT_ENUM_t Highest1Bit (TYPE nMask) noexcept
 
template<typename TYPE >
static BIT_ENUM_t Count1Bits (TYPE nMask) noexcept
 
template<typename TYPE >
static TYPE Rotl (TYPE nVal, BIT_ENUM_t nBits) noexcept
 
template<typename TYPE >
static TYPE Rotr (TYPE nVal, BIT_ENUM_t nBits) noexcept
 
template<typename TYPE >
static TYPE Reverse (TYPE nVal) noexcept
 
template<>
BIT_ENUM_t Count1Bits (UINT32 nVal) noexcept
 
template<>
BYTE Reverse (BYTE nVal) noexcept
 
template<>
UINT32 Reverse (UINT32 nVal) noexcept
 
template<>
ULONG Reverse (ULONG nVal) noexcept
 

Additional Inherited Members

- Public Types inherited from GrayLib::cBitArrayStatic
typedef UINT32 BLOCK_t
 The biggest unsigned type I can do atomic math on for this architecture. More...
 
typedef INT32 BLOCKI_t
 The biggest signed type I can do atomic math on. More...
 
typedef WORD BLOCKH_t
 half sized BLOCK_t for multiplication overflows. More...
 
typedef unsigned int BLOCK_ENUM_t
 Type for the index of a BLOCK_t in the array. NOT bits BIT_ENUM_t. More...
 
- Static Public Attributes inherited from GrayLib::cBitArrayStatic
static const BLOCK_ENUM_t k_BLOCK_MAX = 8096
 Arbitrary Max reasonable size. More...
 
static const size_t k_SIZE_MAX = k_BLOCK_MAX * sizeof(BLOCK_t)
 
static const BIT_ENUM_t k_BIT_MAX = k_SIZE_MAX * 8
 
static const cBitArrayStatic k_Zero
 
static const BLOCK_t k_OneBlock = 1
 
static const BIT_ENUM_t k_BLOCK_BITS = (BIT_ENUM_t)(sizeof(BLOCK_t) * 8)
 The number of bits in a BLOCK_t, BIT_ENUM_t. More...
 
static const BIT_ENUM_t k_BLOCKH_BITS = (BIT_ENUM_t)(sizeof(BLOCKH_t) * 8)
 The number of bits in a BLOCKH_t, BIT_ENUM_t. More...
 
- Static Public Attributes inherited from Gray::cBits
static const BYTE k_8 = 8
 represent the 8 bits in a byte. BIT_ENUM_t More...
 
- Protected Member Functions inherited from GrayLib::cBitArray
void put_BlocksUse (BLOCK_ENUM_t nBlocksUse)
 
BLOCK_t GetBlock (BLOCK_ENUM_t nBlock) const
 
void AddBlockGrow (BLOCK_t nVal)
 
void SetBlock (BLOCK_ENUM_t i, BLOCK_t nVal)
 
- Protected Member Functions inherited from GrayLib::cBitArrayStatic
bool IsValidBlockIndex (BLOCK_ENUM_t i) const noexcept
 
void SetBlockSizeReAlloc (BLOCK_ENUM_t nBlocksNew)
 
void SetBlockSizeUninit (BLOCK_ENUM_t nBlocksNew)
 
void SetBlockSizeGrow (BLOCK_ENUM_t nBlocksNew)
 
BLOCK_ENUM_t FindUsedBlocksQty (BLOCK_ENUM_t nBlocks) const
 
BLOCK_ENUM_t FindUsedBlocksQty () const
 
- Protected Attributes inherited from GrayLib::cBitArray
BLOCK_ENUM_t m_nBlocksUse
 Qty of blocks that is non zero. ASSUME anything above this is 0 blocks. More...
 

Detailed Description

A cBigInteger object represents a signed integer of size limited only by available memory. A cBigInteger is just an aggregate of a cBigUnsigned and a sign bit. cBitArray.Len = max binary exponent. Similar to JDK BigInteger. http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html

Constructor & Destructor Documentation

◆ cBigInteger() [1/10]

GrayLib::cBigInteger::cBigInteger ( )
inline

Constructs zero.

◆ cBigInteger() [2/10]

GrayLib::cBigInteger::cBigInteger ( const THIS_t x)
inline

Copy constructor

◆ cBigInteger() [3/10]

GrayLib::cBigInteger::cBigInteger ( const cBigUnsigned x,
bool  bNegative = false 
)
inline

Constructor from a cBigUnsigned and a sign

◆ cBigInteger() [4/10]

GrayLib::cBigInteger::cBigInteger ( const char *  pszStr,
RADIX_t  uRadix = 10 
)
inline

construct from const string.

◆ cBigInteger() [5/10]

GrayLib::cBigInteger::cBigInteger ( BLOCK_ENUM_t  nBlocks,
const BLOCK_t pBlocks,
bool  bNegative 
)
inline

Create a NON static init object.

◆ cBigInteger() [6/10]

GrayLib::cBigInteger::cBigInteger ( BLOCK_ENUM_t  nBlocks,
const BLOCK_t pBlocks,
bool  bStatic,
bool  bNegative 
)
inline

Create a static init object.

◆ cBigInteger() [7/10]

GrayLib::cBigInteger::cBigInteger ( UINTMAX_t  x)
inline

◆ cBigInteger() [8/10]

GrayLib::cBigInteger::cBigInteger ( INTMAX_t  x)
inline

◆ cBigInteger() [9/10]

GrayLib::cBigInteger::cBigInteger ( UINT32  x)
inline

◆ cBigInteger() [10/10]

GrayLib::cBigInteger::cBigInteger ( INT32  x)
inline

Member Function Documentation

◆ CheckNegativeZero()

void GrayLib::cBigInteger::CheckNegativeZero ( )
inline

Make sure no negative zero. Fix it.

◆ Compare()

COMPARE_t GrayLib::cBigInteger::Compare ( const cBigInteger x) const

Compare A greater sign implies a greater number

◆ CompareMagnitude()

COMPARE_t GrayLib::cBigInteger::CompareMagnitude ( const cBigUnsigned x) const
inline

Ignore sign.

◆ CompareS()

COMPARE_t GrayLib::cBigInteger::CompareS ( BLOCKI_t  x) const

Compare against a small signed value.

◆ CompareU()

COMPARE_t GrayLib::cBigInteger::CompareU ( BLOCK_t  x) const
inline

◆ ExtendedEuclidean()

HRESULT GRAYCALL GrayLib::cBigInteger::ExtendedEuclidean ( const cBigUnsigned m,
const cBigUnsigned n,
cBigUnsigned g,
cBigInteger r,
cBigInteger s 
)
static

Extended Euclidean algorithm. gets GCD plus other stuff. AKA extended_gcd. http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm Given a and b, finds GCD g and numbers x, y such that x*a + y*b == g.

◆ FlipSign()

void GrayLib::cBigInteger::FlipSign ( )
inline

This one is trivial

◆ get_Magnitude()

const cBigUnsigned& GrayLib::cBigInteger::get_Magnitude ( ) const
inline

Get unsigned value.

◆ get_Sign()

int GrayLib::cBigInteger::get_Sign ( ) const
inline

◆ get_Val() [1/2]

template<typename TYPE >
TYPE GrayLib::cBigInteger::get_Val ( ) const
inline

just default to assume TYPE is unsigned.

◆ get_Val() [2/2]

template<>
short GrayLib::cBigInteger::get_Val ( ) const
inline

◆ get_ValS()

template<typename TYPE >
TYPE GrayLib::cBigInteger::get_ValS ( ) const
inline

get a signed type.

◆ GetBinaryBE()

HRESULT GrayLib::cBigInteger::GetBinaryBE ( BYTE *  pOut,
size_t  nSizeOut 
) const
inline

◆ GetModulusH()

BLOCK_t GrayLib::cBigInteger::GetModulusH ( BLOCKH_t  b) const
inline

◆ GetStr() [1/2]

StrLen_t GrayLib::cBigInteger::GetStr ( char *  pszOut,
StrLen_t  iOutMax,
RADIX_t  uRadix = 10 
) const

Get the value as a string.

◆ GetStr() [2/2]

cString GrayLib::cBigInteger::GetStr ( RADIX_t  uRadix = 10) const

◆ InitAdd()

void GrayLib::cBigInteger::InitAdd ( const cBigInteger a,
const cBigInteger b 
)

Set this to the sum of a + b. If one argument is zero, copy the other. don't care if this == &a || this == &b

◆ InitAdd1()

void GrayLib::cBigInteger::InitAdd1 ( const THIS_t a,
BLOCKI_t  n 
)
inline

◆ InitAddU()

void GrayLib::cBigInteger::InitAddU ( const cBigUnsigned a,
const cBigUnsigned b 
)
inline

Unsigned addition: X = |A| + |B| (HAC 14.7)

◆ InitDivide() [1/2]

HRESULT GrayLib::cBigInteger::InitDivide ( const cBigInteger dividend,
const cBigInteger divisor,
OUT cBigInteger remainder 
)

Signed division with remainder.

Note
dividend = divisor * (dividend / divisor) + (dividend % divisor) always holds. dividend = divisor * quotient + remainder

◆ InitDivide() [2/2]

HRESULT GrayLib::cBigInteger::InitDivide ( const THIS_t a,
const cBigInteger b 
)
inline

this = a / b;

◆ InitGreatestCommonDivisor()

void GrayLib::cBigInteger::InitGreatestCommonDivisor ( const cBigInteger a,
const cBigInteger b 
)

Greatest common divisor: *this = GCD(A, B) (HAC 14.54)

◆ InitModInv()

HRESULT GrayLib::cBigInteger::InitModInv ( const cBigInteger A,
const cBigInteger N 
)

Modular inverse: X = A^-1 mod N (HAC 14.61 / 14.64) returns X in range 1..N-1 such that X*A = 1 mod N A must be in range 1..N-1 Returns the multiplicative inverse of x modulo n, or throws an exception if they have a common factor.

◆ InitModulus()

HRESULT GrayLib::cBigInteger::InitModulus ( const THIS_t a,
const THIS_t b 
)
inline

this = a % b;

◆ InitModulusU()

HRESULT GrayLib::cBigInteger::InitModulusU ( const THIS_t a,
const THIS_t b 
)

Unsigned Modulo: |R| = A mod B Allow this === A.

◆ InitMultiply()

void GrayLib::cBigInteger::InitMultiply ( const cBigInteger a,
const cBigInteger b 
)

◆ InitSubtract()

void GrayLib::cBigInteger::InitSubtract ( const cBigInteger a,
const cBigInteger b 
)

◆ InitSubtract1()

void GrayLib::cBigInteger::InitSubtract1 ( const THIS_t a,
BLOCKI_t  n 
)
inline

◆ InitSubU()

HRESULT GrayLib::cBigInteger::InitSubU ( const cBigUnsigned a,
const cBigUnsigned b 
)
inline

Unsigned subtraction : X = |A| - |B|

◆ IsEqual() [1/2]

bool GrayLib::cBigInteger::IsEqual ( BLOCKI_t  x) const
inline

◆ IsEqual() [2/2]

bool GrayLib::cBigInteger::IsEqual ( const THIS_t x) const
inline

◆ isNegative()

bool GrayLib::cBigInteger::isNegative ( ) const
inline

◆ OpAdd1()

void GrayLib::cBigInteger::OpAdd1 ( BLOCKI_t  n)

add a small value.

◆ operator!=()

bool GrayLib::cBigInteger::operator!= ( const THIS_t x) const
inline

◆ operator%()

cBigInteger GrayLib::cBigInteger::operator% ( const THIS_t x) const
inline

Modulus.

◆ operator%=()

void GrayLib::cBigInteger::operator%= ( const THIS_t x)
inline

Mods *this by x. Don't care about quotient left in q.

◆ operator*()

cBigInteger GrayLib::cBigInteger::operator* ( const THIS_t x) const
inline

◆ operator*=()

void GrayLib::cBigInteger::operator*= ( const THIS_t x)
inline

◆ operator+()

cBigInteger GrayLib::cBigInteger::operator+ ( const THIS_t x) const
inline

◆ operator++() [1/2]

void GrayLib::cBigInteger::operator++ ( )
inline

◆ operator++() [2/2]

void GrayLib::cBigInteger::operator++ ( int  )
inline

◆ operator+=()

void GrayLib::cBigInteger::operator+= ( const THIS_t x)
inline

◆ operator-() [1/2]

cBigInteger GrayLib::cBigInteger::operator- ( ) const
inline

◆ operator-() [2/2]

cBigInteger GrayLib::cBigInteger::operator- ( const THIS_t x) const
inline

◆ operator--() [1/2]

void GrayLib::cBigInteger::operator-- ( )
inline

◆ operator--() [2/2]

void GrayLib::cBigInteger::operator-- ( int  )
inline

◆ operator-=()

void GrayLib::cBigInteger::operator-= ( const THIS_t x)
inline

◆ operator/()

cBigInteger GrayLib::cBigInteger::operator/ ( const THIS_t x) const
inline

◆ operator/=()

void GrayLib::cBigInteger::operator/= ( const THIS_t x)
inline

Divide *this by x. don't care about remainder.

◆ operator<()

bool GrayLib::cBigInteger::operator< ( const THIS_t x) const
inline

◆ operator<=()

bool GrayLib::cBigInteger::operator<= ( const THIS_t x) const
inline

◆ operator=()

void GrayLib::cBigInteger::operator= ( const THIS_t x)
inline

◆ operator==()

bool GrayLib::cBigInteger::operator== ( const THIS_t x) const
inline

◆ operator>()

bool GrayLib::cBigInteger::operator> ( const THIS_t x) const
inline

◆ operator>=()

bool GrayLib::cBigInteger::operator>= ( const THIS_t x) const
inline

◆ OpSubtract()

void GrayLib::cBigInteger::OpSubtract ( const THIS_t b)
inline

◆ OpSubtract1()

void GrayLib::cBigInteger::OpSubtract1 ( BLOCKI_t  n)

Prefix decrement

◆ OpSubtractU()

HRESULT GrayLib::cBigInteger::OpSubtractU ( const cBigUnsigned a)
inline

◆ put_Negative()

void GrayLib::cBigInteger::put_Negative ( bool  b = true)
inline

Must call this AFTER copy since there is no such thing as negative 0.

◆ put_Sign()

void GrayLib::cBigInteger::put_Sign ( int  nSign)
inline

Must call this AFTER copy since there is no such thing as negative 0.

◆ put_Val() [1/4]

template<>
void GrayLib::cBigInteger::put_Val ( int  n)
inline

◆ put_Val() [2/4]

template<>
void GrayLib::cBigInteger::put_Val ( long  n)
inline

◆ put_Val() [3/4]

template<>
void GrayLib::cBigInteger::put_Val ( short  n)
inline

◆ put_Val() [4/4]

template<typename TYPE >
void GrayLib::cBigInteger::put_Val ( TYPE  n)
inline

assume unsigned TYPE. signed types are handled individually below.

◆ put_ValS()

void GrayLib::cBigInteger::put_ValS ( INTMAX_t  n)
inline

◆ put_ValU()

void GrayLib::cBigInteger::put_ValU ( UINTMAX_t  n)
inline

Sets this from a native/primitive unsigned TYPE.

◆ SetBinaryBE() [1/2]

HRESULT GrayLib::cBigInteger::SetBinaryBE ( const BYTE *  pData,
size_t  nSize,
bool  bByteSign 
)

Set unsigned via network order binary blob. (x509,ASN)

  • bByteSign = the first byte represents the sign. flip all bits.

◆ SetBinaryBE() [2/2]

HRESULT GrayLib::cBigInteger::SetBinaryBE ( const cMemBlock b,
bool  bByteSign 
)
inline

◆ SetBlocksStatic() [1/2]

void GrayLib::cBigInteger::SetBlocksStatic ( BLOCK_ENUM_t  nBlocks,
const BLOCK_t pBlocks 
)

◆ SetBlocksStatic() [2/2]

void GrayLib::cBigInteger::SetBlocksStatic ( const cBitArrayStatic b)

◆ SetCopyInt()

void GrayLib::cBigInteger::SetCopyInt ( const cBigInteger x)

Assignment operator Calls like a = a have no effect

◆ SetCopySecure()

HRESULT GrayLib::cBigInteger::SetCopySecure ( const THIS_t val,
bool  assign 
)
inline

◆ SetNullVal()

void GrayLib::cBigInteger::SetNullVal ( )
inline

◆ SetPowerMod()

HRESULT GrayLib::cBigInteger::SetPowerMod ( const THIS_t base,
const THIS_t exponent,
const THIS_t modulus,
OUT cBigUnsigned pRR 
)

◆ SetStr()

bool GrayLib::cBigInteger::SetStr ( const char *  pszIn,
RADIX_t  uRadix = 10,
const char **  ppszEnd = nullptr 
)

Set the value from a string.

◆ SetZeroAll()

void GrayLib::cBigInteger::SetZeroAll ( )
inline

◆ SwapSecure()

static HRESULT GRAYCALL GrayLib::cBigInteger::SwapSecure ( THIS_t X,
THIS_t Y,
bool  swap 
)
inlinestatic

◆ UNITTEST_FRIEND()

GrayLib::cBigInteger::UNITTEST_FRIEND ( cBigInteger  )

The documentation for this class was generated from the following files: