Crypto++ 8.9
Free C++ class library of cryptographic schemes
|
Multiple precision integer with arithmetic operations. More...
#include <integer.h>
Classes | |
class | DivideByZero |
Exception thrown when division by 0 is encountered. More... | |
class | OpenPGPDecodeErr |
Exception thrown when an error is encountered decoding an OpenPGP integer. More... | |
class | RandomNumberNotFound |
Exception thrown when a random number cannot be found that satisfies the condition. More... | |
ENUMS, EXCEPTIONS, and TYPEDEFS | |
enum | Sign { POSITIVE =0 , NEGATIVE =1 } |
Used internally to represent the integer. More... | |
enum | Signedness { UNSIGNED , SIGNED } |
Used when importing and exporting integers. More... | |
enum | RandomNumberType { ANY , PRIME } |
Properties of a random integer. More... | |
INPUT/OUTPUT | |
CRYPTOPP_DLL std::istream & | operator>> (std::istream &in, Integer &a) |
Extraction operator. | |
CRYPTOPP_DLL std::ostream & | operator<< (std::ostream &out, const Integer &a) |
Insertion operator. | |
CRYPTOPP_DLL friend Integer | a_times_b_mod_c (const Integer &x, const Integer &y, const Integer &m) |
Modular multiplication. | |
CRYPTOPP_DLL friend Integer | a_exp_b_mod_c (const Integer &x, const Integer &e, const Integer &m) |
Modular exponentiation. | |
CREATORS | |
Integer () | |
Creates the zero integer. | |
Integer (const Integer &t) | |
copy constructor | |
Integer (signed long value) | |
Convert from signed long. | |
Integer (Sign sign, lword value) | |
Convert from lword. | |
Integer (Sign sign, word highWord, word lowWord) | |
Convert from two words. | |
Integer (const char *str, ByteOrder order=BIG_ENDIAN_ORDER) | |
Convert from a C-string. | |
Integer (const wchar_t *str, ByteOrder order=BIG_ENDIAN_ORDER) | |
Convert from a wide C-string. | |
Integer (const byte *encodedInteger, size_t byteCount, Signedness sign=UNSIGNED, ByteOrder order=BIG_ENDIAN_ORDER) | |
Convert from a big-endian byte array. | |
Integer (BufferedTransformation &bt, size_t byteCount, Signedness sign=UNSIGNED, ByteOrder order=BIG_ENDIAN_ORDER) | |
Convert from a big-endian array. | |
Integer (BufferedTransformation &bt) | |
Convert from a BER encoded byte array. | |
Integer (RandomNumberGenerator &rng, size_t bitCount) | |
Create a random integer. | |
Integer (RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType=ANY, const Integer &equiv=Zero(), const Integer &mod=One()) | |
Create a random integer of special form. | |
static const Integer & | Zero () |
Integer representing 0. | |
static const Integer & | One () |
Integer representing 1. | |
static const Integer & | Two () |
Integer representing 2. | |
static Integer | Power2 (size_t e) |
Exponentiates to a power of 2. | |
ENCODE/DECODE | |
size_t | MinEncodedSize (Signedness sign=UNSIGNED) const |
Minimum number of bytes to encode this integer. | |
void | Encode (byte *output, size_t outputLen, Signedness sign=UNSIGNED) const |
Encode in big-endian format. | |
void | Encode (BufferedTransformation &bt, size_t outputLen, Signedness sign=UNSIGNED) const |
Encode in big-endian format. | |
void | DEREncode (BufferedTransformation &bt) const |
Encode in DER format. | |
void | DEREncodeAsOctetString (BufferedTransformation &bt, size_t length) const |
Encode absolute value as big-endian octet string. | |
size_t | OpenPGPEncode (byte *output, size_t bufferSize) const |
Encode absolute value in OpenPGP format. | |
size_t | OpenPGPEncode (BufferedTransformation &bt) const |
Encode absolute value in OpenPGP format. | |
void | Decode (const byte *input, size_t inputLen, Signedness sign=UNSIGNED) |
Decode from big-endian byte array. | |
void | Decode (BufferedTransformation &bt, size_t inputLen, Signedness sign=UNSIGNED) |
Decode nonnegative value from big-endian byte array. | |
void | BERDecode (const byte *input, size_t inputLen) |
Decode from BER format. | |
void | BERDecode (BufferedTransformation &bt) |
Decode from BER format. | |
void | BERDecodeAsOctetString (BufferedTransformation &bt, size_t length) |
Decode nonnegative value from big-endian octet string. | |
void | OpenPGPDecode (const byte *input, size_t inputLen) |
Decode from OpenPGP format. | |
void | OpenPGPDecode (BufferedTransformation &bt) |
Decode from OpenPGP format. | |
ACCESSORS | |
bool | IsConvertableToLong () const |
Determines if the Integer is convertable to Long. | |
signed long | ConvertToLong () const |
Convert the Integer to Long. | |
unsigned int | BitCount () const |
Determines the number of bits required to represent the Integer. | |
unsigned int | ByteCount () const |
Determines the number of bytes required to represent the Integer. | |
unsigned int | WordCount () const |
Determines the number of words required to represent the Integer. | |
bool | GetBit (size_t i) const |
Provides the i-th bit of the Integer. | |
byte | GetByte (size_t i) const |
Provides the i-th byte of the Integer. | |
lword | GetBits (size_t i, size_t n) const |
Provides the low order bits of the Integer. | |
bool | IsZero () const |
Determines if the Integer is 0. | |
bool | NotZero () const |
Determines if the Integer is non-0. | |
bool | IsNegative () const |
Determines if the Integer is negative. | |
bool | NotNegative () const |
Determines if the Integer is non-negative. | |
bool | IsPositive () const |
Determines if the Integer is positive. | |
bool | NotPositive () const |
Determines if the Integer is non-positive. | |
bool | IsEven () const |
Determines if the Integer is even parity. | |
bool | IsOdd () const |
Determines if the Integer is odd parity. | |
MANIPULATORS | |
Integer & | operator= (const Integer &t) |
Assignment. | |
Integer & | operator+= (const Integer &t) |
Addition Assignment. | |
Integer & | operator-= (const Integer &t) |
Subtraction Assignment. | |
Integer & | operator*= (const Integer &t) |
Multiplication Assignment. | |
Integer & | operator/= (const Integer &t) |
Division Assignment. | |
Integer & | operator%= (const Integer &t) |
Remainder Assignment. | |
Integer & | operator/= (word t) |
Division Assignment. | |
Integer & | operator%= (word t) |
Remainder Assignment. | |
Integer & | operator<<= (size_t n) |
Left-shift Assignment. | |
Integer & | operator>>= (size_t n) |
Right-shift Assignment. | |
Integer & | operator&= (const Integer &t) |
Bitwise AND Assignment. | |
Integer & | operator|= (const Integer &t) |
Bitwise OR Assignment. | |
Integer & | operator^= (const Integer &t) |
Bitwise XOR Assignment. | |
void | Randomize (RandomNumberGenerator &rng, size_t bitCount) |
Set this Integer to random integer. | |
void | Randomize (RandomNumberGenerator &rng, const Integer &min, const Integer &max) |
Set this Integer to random integer. | |
bool | Randomize (RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType, const Integer &equiv=Zero(), const Integer &mod=One()) |
Set this Integer to random integer of special form. | |
bool | GenerateRandomNoThrow (RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs) |
Generate a random number. | |
void | GenerateRandom (RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs) |
Generate a random number. | |
void | SetBit (size_t n, bool value=1) |
Set the n-th bit to value. | |
void | SetByte (size_t n, byte value) |
Set the n-th byte to value. | |
void | Negate () |
Reverse the Sign of the Integer. | |
void | SetPositive () |
Sets the Integer to positive. | |
void | SetNegative () |
Sets the Integer to negative. | |
void | swap (Integer &a) |
Swaps this Integer with another Integer. | |
UNARY OPERATORS | |
bool | operator! () const |
Negation. | |
Integer | operator+ () const |
Addition. | |
Integer | operator- () const |
Subtraction. | |
Integer & | operator++ () |
Pre-increment. | |
Integer & | operator-- () |
Pre-decrement. | |
Integer | operator++ (int) |
Post-increment. | |
Integer | operator-- (int) |
Post-decrement. | |
BINARY OPERATORS | |
int | Compare (const Integer &a) const |
Perform signed comparison. | |
Integer | Plus (const Integer &b) const |
Addition. | |
Integer | Minus (const Integer &b) const |
Subtraction. | |
Integer | Times (const Integer &b) const |
Multiplication. | |
Integer | DividedBy (const Integer &b) const |
Division. | |
Integer | Modulo (const Integer &b) const |
Remainder. | |
Integer | DividedBy (word b) const |
Division. | |
word | Modulo (word b) const |
Remainder. | |
Integer | And (const Integer &t) const |
Bitwise AND. | |
Integer | Or (const Integer &t) const |
Bitwise OR. | |
Integer | Xor (const Integer &t) const |
Bitwise XOR. | |
Integer | operator>> (size_t n) const |
Right-shift. | |
Integer | operator<< (size_t n) const |
Left-shift. | |
OTHER ARITHMETIC FUNCTIONS | |
Integer | AbsoluteValue () const |
Retrieve the absolute value of this integer. | |
Integer | Doubled () const |
Add this integer to itself. | |
Integer | Squared () const |
Multiply this integer by itself. | |
Integer | SquareRoot () const |
Extract square root. | |
bool | IsSquare () const |
Determine whether this integer is a perfect square. | |
bool | IsUnit () const |
Determine if 1 or -1. | |
Integer | MultiplicativeInverse () const |
Calculate multiplicative inverse. | |
Integer | InverseMod (const Integer &n) const |
Calculate multiplicative inverse. | |
word | InverseMod (word n) const |
Calculate multiplicative inverse. | |
static void | Divide (Integer &r, Integer &q, const Integer &a, const Integer &d) |
Extended Division. | |
static void | Divide (word &r, Integer &q, const Integer &a, word d) |
Extended Division. | |
static void | DivideByPowerOf2 (Integer &r, Integer &q, const Integer &a, unsigned int n) |
Extended Division. | |
static Integer | Gcd (const Integer &a, const Integer &n) |
Calculate greatest common divisor. | |
Additional Inherited Members | |
Public Member Functions inherited from ASN1Object | |
virtual void | BEREncode (BufferedTransformation &bt) const |
Encode this object into a BufferedTransformation. | |
Multiple precision integer with arithmetic operations.
The Integer class can represent positive and negative integers with absolute value less than (256**sizeof(word))(256**sizeof(int)).
Internally, the library uses a sign magnitude representation, and the class has two data members. The first is a IntegerSecBlock (a SecBlock<word>) and it is used to hold the representation. The second is a Sign (an enumeration), and it is used to track the sign of the Integer.
For details on how the Integer class initializes its function pointers using InitializeInteger and how it creates Integer::Zero(), Integer::One(), and Integer::Two(), then see the comments at the top of integer.cpp
.
enum Integer::Sign |
Used internally to represent the integer.
Sign is used internally to represent the integer. It is also used in a few API functions.
Enumerator | |
---|---|
POSITIVE | the value is positive or 0 |
NEGATIVE | the value is negative |
enum Integer::Signedness |
Convert from lword.
sign | enumeration indicating Sign |
value | the long word |
Convert from two words.
sign | enumeration indicating Sign |
highWord | the high word |
lowWord | the low word |
|
explicit |
Convert from a C-string.
str | C-string value |
order | the ByteOrder of the string to be processed |
str
can be in base 8, 10, or 16. Base is determined by a case insensitive suffix of 'o' (8), '.' (10), or 'h' (16). No suffix means base 10.
Byte order was added at Crypto++ 5.7 to allow use of little-endian integers with curve25519, Poly1305 and Microsoft CAPI.
|
explicit |
Convert from a wide C-string.
str | wide C-string value |
order | the ByteOrder of the string to be processed |
str
can be in base 8, 10, or 16. Base is determined by a case insensitive suffix of 'o' (8), '.' (10), or 'h' (16). No suffix means base 10.
Byte order was added at Crypto++ 5.7 to allow use of little-endian integers with curve25519, Poly1305 and Microsoft CAPI.
Integer::Integer | ( | const byte * | encodedInteger, |
size_t | byteCount, | ||
Signedness | sign = UNSIGNED, | ||
ByteOrder | order = BIG_ENDIAN_ORDER ) |
Convert from a big-endian byte array.
encodedInteger | big-endian byte array |
byteCount | length of the byte array |
sign | enumeration indicating Signedness |
order | the ByteOrder of the array to be processed |
Byte order was added at Crypto++ 5.7 to allow use of little-endian integers with curve25519, Poly1305 and Microsoft CAPI.
Integer::Integer | ( | BufferedTransformation & | bt, |
size_t | byteCount, | ||
Signedness | sign = UNSIGNED, | ||
ByteOrder | order = BIG_ENDIAN_ORDER ) |
Convert from a big-endian array.
bt | BufferedTransformation object with big-endian byte array |
byteCount | length of the byte array |
sign | enumeration indicating Signedness |
order | the ByteOrder of the data to be processed |
Byte order was added at Crypto++ 5.7 to allow use of little-endian integers with curve25519, Poly1305 and Microsoft CAPI.
|
explicit |
Convert from a BER encoded byte array.
bt | BufferedTransformation object with BER encoded byte array |
Integer::Integer | ( | RandomNumberGenerator & | rng, |
size_t | bitCount ) |
Create a random integer.
rng | RandomNumberGenerator used to generate material |
bitCount | the number of bits in the resulting integer |
The random integer created is uniformly distributed over [0, 2bitCount]
.
Integer::Integer | ( | RandomNumberGenerator & | rng, |
const Integer & | min, | ||
const Integer & | max, | ||
RandomNumberType | rnType = ANY, | ||
const Integer & | equiv = Zero(), | ||
const Integer & | mod = One() ) |
Create a random integer of special form.
rng | RandomNumberGenerator used to generate material |
min | the minimum value |
max | the maximum value |
rnType | RandomNumberType to specify the type |
equiv | the equivalence class based on the parameter mod |
mod | the modulus used to reduce the equivalence class |
RandomNumberNotFound | if the set is empty. |
Ideally, the random integer created should be uniformly distributed over {x | min <= x <= max
and x
is of rnType and x % mod == equiv}
. However the actual distribution may not be uniform because sequential search is used to find an appropriate number from a random starting point.
May return (with very small probability) a pseudoprime when a prime is requested and max > lastSmallPrime*lastSmallPrime
. lastSmallPrime
is declared in nbtheory.h.
|
static |
|
static |
|
static |
|
static |
size_t Integer::MinEncodedSize | ( | Signedness | sign = UNSIGNED | ) | const |
Minimum number of bytes to encode this integer.
sign | enumeration indicating Signedness |
void Integer::Encode | ( | byte * | output, |
size_t | outputLen, | ||
Signedness | sign = UNSIGNED ) const |
Encode in big-endian format.
output | big-endian byte array |
outputLen | length of the byte array |
sign | enumeration indicating Signedness |
Unsigned means encode absolute value, signed means encode two's complement if negative.
outputLen can be used to ensure an Integer is encoded to an exact size (rather than a minimum size). An exact size is useful, for example, when encoding to a field element size.
void Integer::Encode | ( | BufferedTransformation & | bt, |
size_t | outputLen, | ||
Signedness | sign = UNSIGNED ) const |
Encode in big-endian format.
bt | BufferedTransformation object |
outputLen | length of the encoding |
sign | enumeration indicating Signedness |
Unsigned means encode absolute value, signed means encode two's complement if negative.
outputLen can be used to ensure an Integer is encoded to an exact size (rather than a minimum size). An exact size is useful, for example, when encoding to a field element size.
|
virtual |
Encode in DER format.
bt | BufferedTransformation object |
Encodes the Integer using Distinguished Encoding Rules The result is placed into a BufferedTransformation object
Implements ASN1Object.
void Integer::DEREncodeAsOctetString | ( | BufferedTransformation & | bt, |
size_t | length ) const |
Encode absolute value as big-endian octet string.
bt | BufferedTransformation object |
length | the number of mytes to decode |
size_t Integer::OpenPGPEncode | ( | byte * | output, |
size_t | bufferSize ) const |
Encode absolute value in OpenPGP format.
output | big-endian byte array |
bufferSize | length of the byte array |
OpenPGPEncode places result into the buffer and returns the number of bytes used for the encoding
size_t Integer::OpenPGPEncode | ( | BufferedTransformation & | bt | ) | const |
Encode absolute value in OpenPGP format.
bt | BufferedTransformation object |
OpenPGPEncode places result into a BufferedTransformation object and returns the number of bytes used for the encoding
void Integer::Decode | ( | const byte * | input, |
size_t | inputLen, | ||
Signedness | sign = UNSIGNED ) |
Decode from big-endian byte array.
input | big-endian byte array |
inputLen | length of the byte array |
sign | enumeration indicating Signedness |
void Integer::Decode | ( | BufferedTransformation & | bt, |
size_t | inputLen, | ||
Signedness | sign = UNSIGNED ) |
Decode nonnegative value from big-endian byte array.
bt | BufferedTransformation object |
inputLen | length of the byte array |
sign | enumeration indicating Signedness |
bt.MaxRetrievable() >= inputLen
. void Integer::BERDecode | ( | const byte * | input, |
size_t | inputLen ) |
Decode from BER format.
input | big-endian byte array |
inputLen | length of the byte array |
|
virtual |
void Integer::BERDecodeAsOctetString | ( | BufferedTransformation & | bt, |
size_t | length ) |
Decode nonnegative value from big-endian octet string.
bt | BufferedTransformation object |
length | length of the byte array |
void Integer::OpenPGPDecode | ( | const byte * | input, |
size_t | inputLen ) |
Decode from OpenPGP format.
input | big-endian byte array |
inputLen | length of the byte array |
void Integer::OpenPGPDecode | ( | BufferedTransformation & | bt | ) |
Decode from OpenPGP format.
bt | BufferedTransformation object |
bool Integer::IsConvertableToLong | ( | ) | const |
Determines if the Integer is convertable to Long.
*this
can be represented as a signed long signed long Integer::ConvertToLong | ( | ) | const |
Convert the Integer to Long.
unsigned int Integer::BitCount | ( | ) | const |
Determines the number of bits required to represent the Integer.
BitCount is calculated as floor(log2(abs(*this))) + 1
.
unsigned int Integer::ByteCount | ( | ) | const |
Determines the number of bytes required to represent the Integer.
ByteCount is calculated as ceiling(BitCount()/8)
.
unsigned int Integer::WordCount | ( | ) | const |
Determines the number of words required to represent the Integer.
WordCount is calculated as ceiling(ByteCount()/sizeof(word))
.
bool Integer::GetBit | ( | size_t | i | ) | const |
Provides the i-th bit of the Integer.
lword Integer::GetBits | ( | size_t | i, |
size_t | n ) const |
Provides the low order bits of the Integer.
*this >> i
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Multiplication Assignment.
t | the other Integer |
*this * t
Remainder Assignment.
t | the other Integer |
*this % t
Remainder Assignment.
t | the other word |
*this % t
Integer & Integer::operator<<= | ( | size_t | n | ) |
Integer & Integer::operator>>= | ( | size_t | n | ) |
Bitwise AND Assignment.
t | the other Integer |
*this & t
operator&=() performs a bitwise AND on *this
. Missing bits are truncated at the most significant bit positions, so the result is as small as the smaller of the operands.
Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.
Bitwise OR Assignment.
t | the second Integer |
*this | t
operator|=() performs a bitwise OR on *this
. Missing bits are shifted in at the most significant bit positions, so the result is as large as the larger of the operands.
Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.
Bitwise XOR Assignment.
t | the other Integer |
*this ^ t
operator^=() performs a bitwise XOR on *this
. Missing bits are shifted in at the most significant bit positions, so the result is as large as the larger of the operands.
Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.
void Integer::Randomize | ( | RandomNumberGenerator & | rng, |
size_t | bitCount ) |
Set this Integer to random integer.
rng | RandomNumberGenerator used to generate material |
bitCount | the number of bits in the resulting integer |
The random integer created is uniformly distributed over [0, 2bitCount]
.
bitCount
is 0, then this Integer is set to 0 (and not 0 or 1). void Integer::Randomize | ( | RandomNumberGenerator & | rng, |
const Integer & | min, | ||
const Integer & | max ) |
Set this Integer to random integer.
rng | RandomNumberGenerator used to generate material |
min | the minimum value |
max | the maximum value |
The random integer created is uniformly distributed over [min, max]
.
bool Integer::Randomize | ( | RandomNumberGenerator & | rng, |
const Integer & | min, | ||
const Integer & | max, | ||
RandomNumberType | rnType, | ||
const Integer & | equiv = Zero(), | ||
const Integer & | mod = One() ) |
Set this Integer to random integer of special form.
rng | RandomNumberGenerator used to generate material |
min | the minimum value |
max | the maximum value |
rnType | RandomNumberType to specify the type |
equiv | the equivalence class based on the parameter mod |
mod | the modulus used to reduce the equivalence class |
RandomNumberNotFound | if the set is empty. |
Ideally, the random integer created should be uniformly distributed over {x | min <= x <= max
and x
is of rnType and x % mod == equiv}
. However the actual distribution may not be uniform because sequential search is used to find an appropriate number from a random starting point.
May return (with very small probability) a pseudoprime when a prime is requested and max > lastSmallPrime*lastSmallPrime
. lastSmallPrime
is declared in nbtheory.h.
bool Integer::GenerateRandomNoThrow | ( | RandomNumberGenerator & | rng, |
const NameValuePairs & | params = g_nullNameValuePairs ) |
Generate a random number.
rng | RandomNumberGenerator used to generate material |
params | additional parameters that cannot be passed directly to the function |
GenerateRandomNoThrow attempts to generate a random number according to the parameters specified in params. The function does not throw RandomNumberNotFound.
The example below generates a prime number using NameValuePairs that Integer class recognizes. The names are not provided in argnames.h.
AutoSeededRandomPool prng; AlgorithmParameters params = MakeParameters("BitLength", 2048) ("RandomNumberType", Integer::PRIME); Integer x; if (x.GenerateRandomNoThrow(prng, params) == false) throw std::runtime_error("Failed to generate prime number");
|
inline |
Generate a random number.
rng | RandomNumberGenerator used to generate material |
params | additional parameters that cannot be passed directly to the function |
RandomNumberNotFound | if a random number is not found |
GenerateRandom attempts to generate a random number according to the parameters specified in params.
The example below generates a prime number using NameValuePairs that Integer class recognizes. The names are not provided in argnames.h.
AutoSeededRandomPool prng; AlgorithmParameters params = MakeParameters("BitLength", 2048) ("RandomNumberType", Integer::PRIME); Integer x; try { x.GenerateRandom(prng, params); } catch (RandomNumberNotFound&) { x = -1; }
void Integer::SetBit | ( | size_t | n, |
bool | value = 1 ) |
Set the n-th bit to value.
0-based numbering.
void Integer::SetByte | ( | size_t | n, |
byte | value ) |
Set the n-th byte to value.
0-based numbering.
|
inline |
|
inline |
|
inline |
|
inline |
int Integer::Compare | ( | const Integer & | a | ) | const |
Perform signed comparison.
a | the Integer to compare |
-1 | if *this < a |
0 | if *this = a |
1 | if *this > a |
Multiplication.
Remainder.
Remainder.
Bitwise AND.
t | the other Integer |
*this & t
And() performs a bitwise AND on the operands. Missing bits are truncated at the most significant bit positions, so the result is as small as the smaller of the operands.
Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.
Bitwise OR.
t | the other Integer |
*this | t
Or() performs a bitwise OR on the operands. Missing bits are shifted in at the most significant bit positions, so the result is as large as the larger of the operands.
Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.
Bitwise XOR.
t | the other Integer |
*this ^ t
Xor() performs a bitwise XOR on the operands. Missing bits are shifted in at the most significant bit positions, so the result is as large as the larger of the operands.
Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.
|
inline |
|
inline |
|
inline |
|
inline |
Multiply this integer by itself.
Integer Integer::SquareRoot | ( | ) | const |
Extract square root.
if negative return 0, else return floor of square root
bool Integer::IsUnit | ( | ) | const |
Determine if 1 or -1.
Integer Integer::MultiplicativeInverse | ( | ) | const |
Calculate multiplicative inverse.
|
static |
Extended Division.
r | a reference for the remainder |
q | a reference for the quotient |
a | reference to the dividend |
d | reference to the divisor |
Divide calculates r and q such that (a == d*q + r) && (0 <= r < abs(d)).
Extended Division.
r | a reference for the remainder |
q | a reference for the quotient |
a | reference to the dividend |
d | reference to the divisor |
Divide calculates r and q such that (a == d*q + r) && (0 <= r < abs(d)). This overload uses a faster division algorithm because the divisor is short.
|
static |
Extended Division.
r | a reference for the remainder |
q | a reference for the quotient |
a | reference to the dividend |
n | reference to the divisor |
DivideByPowerOf2 calculates r and q such that (a == d*q + r) && (0 <= r < abs(d)). It returns same result as Divide(r, q, a, Power2(n)), but faster. This overload uses a faster division algorithm because the divisor is a power of 2.
Calculate greatest common divisor.
a | reference to the first number |
n | reference to the secind number |
a
and n
. Calculate multiplicative inverse.
n | reference to the modulus |
*this % n
.InverseMod returns the multiplicative inverse of the Integer *this
modulo the Integer n
. If no Integer exists then Integer 0 is returned.
Calculate multiplicative inverse.
n | the modulus |
*this % n
.InverseMod returns the multiplicative inverse of the Integer *this
modulo the word n
. If no Integer exists then word 0 is returned.
|
friend |
Extraction operator.
in | reference to a std::istream |
a | reference to an Integer |
|
friend |
Insertion operator.
out | reference to a std::ostream |
a | a constant reference to an Integer |
The output integer responds to hex, std::oct, std::hex, std::upper and std::lower. The output includes the suffix h (for hex), . (dot, for dec) and o (for octal). There is currently no way to suppress the suffix.
If you want to print an Integer without the suffix or using an arbitrary base, then use IntToString<Integer>().
|
friend |
Modular multiplication.
x | reference to the first term |
y | reference to the second term |
m | reference to the modulus |
(a * b) % m
.
|
friend |
Modular exponentiation.
x | reference to the base |
e | reference to the exponent |
m | reference to the modulus |
(a ^ b) % m
.