|
BigDigits C++ OOP
1.0.1
|
Class to represent and operate on a BigDigits number. More...
Public Member Functions | |
| BigDigit () | |
| Initialise as zero. | |
| BigDigit (bdigit_t x) | |
| Initialize with 32-bit unsigned integer. | |
| BigDigit (const char *str) | |
| Constructor for C-string literals like "0xdeadbeef". | |
| BigDigit (int x) | |
| Initialize with integer. | |
| BigDigit (std::string s) | |
| Initialise with value represented by a string, see from_str(). | |
| BigDigit | cbrt () const |
Return the integer cube root of the object's value floor(cuberoot(b)) | |
| int | cmp_ct (const BigDigit &other) const |
| Compare values in constant time. More... | |
| BigDigit | gcd (const BigDigit &other) const |
Return the greatest common divisor of this value and other. | |
| int | getbit (size_t n) const |
Return value 1 or 0 of bit at index n. More... | |
| bool | is_even () const |
| Returns true if number is even. | |
| bool | is_odd () const |
| Returns true if number is odd. | |
| bool | is_prime () const |
Return true if number is prime. | |
| int | jacobi (const BigDigit &n) const |
| Return the Jacobi symbol (a/n) = {-1,0,+1}. More... | |
| BigDigit | mod_add (const BigDigit &v, const BigDigit &m) const |
Add v modulo m More... | |
| BigDigit | mod_exp (const BigDigit &e, const BigDigit &m) const |
Compute modular exponentiation of object's value raised to power e over a modulus m. More... | |
| BigDigit | mod_exp_ct (const BigDigit &e, const BigDigit &m) const |
Compute modular exponentiation of object's value raised to power e over a modulus m in constant time. More... | |
| BigDigit | mod_halve (const BigDigit &p) const |
Computes u/2 (mod p) for an odd prime p. More... | |
| BigDigit | mod_inv (const BigDigit &m) const |
Compute the inverse modulo m. | |
| BigDigit | mod_mult (const BigDigit &y, const BigDigit &m) const |
Multiply by y modulo m. | |
| BigDigit | mod_powerof2 (size_t L) const |
Returns a mod 2^L. More... | |
| BigDigit | mod_sqrt (const BigDigit &p) const |
Compute a square root modulo an odd prime p. More... | |
| BigDigit | mod_square (const BigDigit &m) const |
Square modulo m | |
| BigDigit | mod_sub (const BigDigit &v, const BigDigit &m) const |
Subtract v modulo m. More... | |
| BigDigit | operator& (const BigDigit &other) const |
| Bitwise AND. | |
| BigDigit | operator&= (const BigDigit &other) |
| Bitwise AND Assign. | |
| BigDigit | operator^ (const BigDigit &other) const |
| Bitwise Exclusive OR (XOR) | |
| BigDigit | operator^= (const BigDigit &other) |
| Bitwise Exclusive OR Assign. | |
| BigDigit | operator| (const BigDigit &other) const |
| Bitwise OR. | |
| BigDigit | operator|= (const BigDigit &other) |
| Bitwise OR Assign. | |
| BigDigit | operator~ () const |
| Bitwise NOT. More... | |
| BigDigit | pow (unsigned short int n) const |
Raise to the power n. | |
| void | print () const |
| Print in decimal to stdout with newline. | |
| void | print (std::string pre) const |
| Print in decimal with prefix and newline. | |
| void | printbits () const |
Print in binary (0 and 1) with newline. | |
| void | printbits (std::string pre) const |
Print in binary (0 and 1) with prefix and newline. | |
| void | printhex () const |
| Print in hexadecimal with newline. | |
| void | printhex (std::string pre) const |
| Print in hexadecimal with prefix and newline. | |
| BigDigit | reverse_octets (size_t n) const |
| Reverse order of octets inside BigDigit up to the n'th octet. More... | |
| BigDigit | set_prime (size_t nbits) |
Generate a prime of exactly nbits bits using "internal" RNG. More... | |
| BigDigit | set_prime (size_t nbits, BD_RANDFUNC UserRandFunc) |
Generate a prime of exactly nbits bits using a user-defined external RNG. More... | |
| BigDigit | set_prime (size_t nbits, BD_RANDFUNC UserRandFunc, unsigned char *seed, size_t seedlen) |
Generate a prime of exactly nbits bits using a user-defined external RNG with a seed. More... | |
| BigDigit | set_rand_bits (size_t nbits) |
Generate a random BIGD number of bit length at most nbits using internal RNG. More... | |
| BigDigit | set_rand_number (const BigDigit &n) |
| Generate a number at random from a uniform distribution in [0, n-1] using internal RNG. More... | |
| BigDigit | setbit (size_t n, int value) |
Set bit at index n with value 1 or 0. More... | |
| BigDigit | sqrt () const |
Return the integer square root of the object's value floor(sqrt(b)) | |
| BigDigit | square () const |
| Compute the square. More... | |
| std::vector< unsigned char > | to_octets () const |
| Encode this BigDigit object to a byte array excluding any leading zero bytes. More... | |
| std::vector< unsigned char > | to_octets (size_t nb) const |
Encode this BigDigit object to a byte array of exactly nb bytes. More... | |
| bdigit_t | to_short () const |
| Return the least significant digit of the object. More... | |
| std::string | to_str () const |
| Return a std::string containing the decimal representation of the BigDigit value. | |
| std::string | to_strhex () const |
| Return a std::string containing the hexadecimal representation of the BigDigit value. | |
Static Public Member Functions | |
| template<typename First , typename Second > | |
| static BigDigit | gcd (const First &first, const Second &second) |
| Return GCD of a list of numbers. More... | |
Friends | |
| BigDigit | from_octets (const std::vector< unsigned char > bv) |
| Convert a byte array to an equivalent BigDigit. More... | |
| BigDigit | from_str (std::string s) |
| Convert the initial characters of the string s to an equivalent BigDigit. More... | |
Class to represent and operate on a BigDigits number.
| int dibigd::BigDigit::cmp_ct | ( | const BigDigit & | other | ) | const |
Compare values in constant time.
|
inlinestatic |
Return GCD of a list of numbers.
| int dibigd::BigDigit::getbit | ( | size_t | n | ) | const |
Return value 1 or 0 of bit at index n.
| int dibigd::BigDigit::jacobi | ( | const BigDigit & | n | ) | const |
Return the Jacobi symbol (a/n) = {-1,0,+1}.
Add v modulo m
| v | Number to be added modulo m |
| m | Modulus |
u is the object's value. u,v < m then this is faster than (u+v)%m. Compute modular exponentiation of object's value raised to power e over a modulus m.
Not constant time. For constant time use mod_exp_ct().
| e | the exponent |
| m | the modulus |
b^e mod m Compute modular exponentiation of object's value raised to power e over a modulus m in constant time.
| e | the exponent |
| m | the modulus |
b^e mod m Computes u/2 (mod p) for an odd prime p.
where u is the object's value.
u to be in the range [0,p-1]. | BigDigit dibigd::BigDigit::mod_powerof2 | ( | size_t | L | ) | const |
Returns a mod 2^L.
i.e. clears all bits at index greater than L.
Compute a square root modulo an odd prime p.
| p | An odd prime. |
p-x. Returns 0 if root not defined. Subtract v modulo m.
| v | Number to be subtracted modulo m |
| m | Modulus |
u is the object's value. v > u and returns u + m - v. If u,v < m then this is faster than (u-v)%m. | BigDigit dibigd::BigDigit::operator~ | ( | ) | const |
Bitwise NOT.
| BigDigit dibigd::BigDigit::reverse_octets | ( | size_t | n | ) | const |
| BigDigit dibigd::BigDigit::set_prime | ( | size_t | nbits | ) |
Generate a prime of exactly nbits bits using "internal" RNG.
This modifies the object.
| BigDigit dibigd::BigDigit::set_prime | ( | size_t | nbits, |
| BD_RANDFUNC | UserRandFunc | ||
| ) |
Generate a prime of exactly nbits bits using a user-defined external RNG.
This modifies the object and returns the new value.
| BigDigit dibigd::BigDigit::set_prime | ( | size_t | nbits, |
| BD_RANDFUNC | UserRandFunc, | ||
| unsigned char * | seed, | ||
| size_t | seedlen | ||
| ) |
Generate a prime of exactly nbits bits using a user-defined external RNG with a seed.
This modifies the object and returns the new value.
| BigDigit dibigd::BigDigit::set_rand_bits | ( | size_t | nbits | ) |
Generate a random BIGD number of bit length at most nbits using internal RNG.
This modifies the object and returns the new value.
Generate a number at random from a uniform distribution in [0, n-1] using internal RNG.
This modifies the object and returns the new value.
| BigDigit dibigd::BigDigit::setbit | ( | size_t | n, |
| int | value | ||
| ) |
Set bit at index n with value 1 or 0.
| BigDigit dibigd::BigDigit::square | ( | ) | const |
Compute the square.
| std::vector<unsigned char> dibigd::BigDigit::to_octets | ( | ) | const |
Encode this BigDigit object to a byte array excluding any leading zero bytes.
| std::vector<unsigned char> dibigd::BigDigit::to_octets | ( | size_t | nb | ) | const |
Encode this BigDigit object to a byte array of exactly nb bytes.
This ensures any leading zero bytes are included.
| bdigit_t dibigd::BigDigit::to_short | ( | ) | const |
Return the least significant digit of the object.
|
friend |
Convert a byte array to an equivalent BigDigit.
| bv | An array of bytes. |
|
friend |
Convert the initial characters of the string s to an equivalent BigDigit.
| s | A string of digits. A leading 0x or 0X indicates a hexadecimal (base 16) integer with valid characters [0-9a-fA-F], a leading 0b or 0B indicates a binary (base 2) integer with valid characters [01], otherwise it indicates a decimal (base 10) integer with valid characters [0-9]. |
| std::invalid_argument | exception if an invalid character is found. |