FBB::BigInt(3bobcat)
πΈ NAME πΈ
FBB::BigInt β Arithmetic on Integers of Unlimited Size
hey bestie, welcome to the 3bobcat manual, section 3. this is the page for the class that lets you do math on integers so big they'd make your calculator cry. π
β¨ SYNOPSIS β¨
#include <bobcat/bigint>
Linking option: -lbobcat -lcrypto
π DESCRIPTION π
So basically this class is a wrapper class around the openSSL BN series of functions. it hands you members to perform arithmetic on integral values of unlimited sizes, no cap. π§ Members are offered to generate primes and to perform all kinds of common arithmetic operations on BigInt objects. Also, conversions to characters and standard numerical value types are offered. it's giving "everything you could ever want", fr fr.
Below, the phrase the object may also refer to the object's value. The context in which this occurs will make it clear that the object's value rather than the object as-is is what's being referred to. iykyk.
Various constructors accept BIGNUM arguments. Type BIGNUM is the type containing an integer of unlimited precision as defined by OpenSSL. BIGNUM's definition is
typedef struct bignum_st BIGNUM;
struct bignum_st
{
BN_ULONG *d; // Pointer to an array of βBN_BITS2β bit chunks.
int top; // Index of last used d +1.
// The next are internal book keeping for bn_expand.
int dmax; // Size of the d array.
int neg; // one if the number is negative
int flags;
};
Signs of BigInt are handled in a special way, okay, pay attention. Whether a BigInt is negative or positive is determined by its sign-flag, and not by a sign bit like it is with int typed values. Since BigInt values have unlimited precision, shifting values to the left won't change their signs. lowkey iconic behavior. π
Operators return either a reference to the current (modified) object or return a BigInt object containing the computed value. The rule followed here was to implement the operators analogously to the way the operators work on int type values and variables. E.g., operator+() returns a BigInt value whereas operator+=() returns a BigInt & reference.
- All members modifying their objects return a reference to the current (modified) object.
- All members not modifying the current object return a
BigIntobject. - If both members exist performing the same functionality, the name of the member returning a
BigIntobject ends in ac(const) (e.g.,addModandaddModc). thecstands for const, she's consistent bestie.
β οΈ Almost all operators, members and constructors (except for the default constructor) throw Exception exceptions on failure. so like, be ready. π
π INHERITS FROM π
-
(nothing. she's self-made. main character energy. π )
π¦ TYPE π¦
The class BigInt defines the type Word, which is equal to the type BN_ULONG used by OpenSSL to store integral values of unlimited precision. A Word is an unsigned long, which is, depending on the architecture, usually 64 or 32 bits long.
π ENUMERATIONS π
Msb
This (most significant bit) enumeration is used when generating a cryptographically strong random number. Its values are:
MSB_UNKNOWNβ The most significant bit may be0or1.MSB_IS_ONEβ The most significant bit is guaranteed to be1.TOP_TWO_BITS_ONEβ The two most significant bits are guaranteed to be1, resulting in a product of two values each containingnBitshaving2 * nBitsbits.
Lsb
This (least significant bit) enumeration is used when generating random numbers, ensuring that the resulting value is either odd or even.
EVENβ The random value will be an even value;ODDβ The random value will be an odd value.
π CONSTRUCTORS π
BigInt()β The default constructor initializes aBigIntvalue to0;explicit BigInt(BIGNUM const &value)β This constructor initializes aBigIntfrom aconst BIGNUM;explicit BigInt(BIGNUM const *value)β This constructor initializes aBigIntfrom a pointer to aconst BIGNUM;explicit BigInt(BIGNUM *value)β This constructor initializes aBigIntfrom a pointer to aBIGNUM(theBIGNUMvalue pointed to byvalueis not mondified by the constructor. This constructor is a mere wrapper around the previous constructor). Note that none of the constructors expecting aBIGNUMargument modify their argument. If the memory used by theBIGNUMargument must be returned to the common pool an explicitBN_free(3ssl)call is required;BigInt(Type value)β This constructor is defined as a member template. Any type that can be converted using a static cast to anunsigned longcan be used as argument to this constructor. Promotion is allowed, so in many situations whereBigInts are expected a plain numerical value can be used as well;BigInt(char const *bigEndian, size_t length, bool negative = false)β This constructor initializes aBigIntfromlengthbig-endian encoded bytes stored inbigEndian(having its most significant value at index 0). This constructor interprets thecharvalues pointed at bybigEndianas unsigned values. Use this constructor to reconstruct aBigIntobject from the data made available by thebigEndianmember (most significant byte at index 0). If the number represents a negative value, then provide a third argumenttrue;explicit BigInt(std::string const &bigEndian, bool negative = false)β This constructor initializes aBigIntfrom the bytes stored inbigEndian, which must be big-endian encoded (having its most significant value at index 0). This constructor interprets thecharvalues stored inbigEndianas unsigned values. If the number that is stored inbigEndianrepresents a negative value, then provide a second argumenttrue;BigInt(size_t length, char const *littleEndian, bool negative = false)β This constructor initializes aBigIntfromlengthlittle-endian encoded bytes stored inlittleEndian(having its least significant value at index 0). This constructor interprets thecharvalues pointed at bylittleEndianas unsigned values. Use this constructor to reconstruct aBigIntobject from the data made available by thelittleEndianmember (most significant byte at index 0). If the number represents a negative value, then provide a third argumenttrue;explicit BigInt(BigInt::Little endian, std::string littleEndian, bool negative = false)β This constructor initializes aBigIntfrom the bytes stored inlittleEndian, which must be little-endian encoded (having its least significant value at index 0). This constructor interprets thecharvalues stored inlittleEndianas unsigned values. If the number that is stored inlittleEndianrepresents a negative value, then provide a third argumenttrue. The consructor's first parameter is used to distinguish this constructor from the constructor expecting at(string)whose bytes represent a big-endian encoded value, and is not used by this constructor itself. It can be specified asBigInt::Little{}.
Copy and move constructors (and assignment operators) are available. π«Ά
π₯ MEMBER FUNCTIONS π₯
BigInt &addMod(BigInt const &rhs, BigInt const &mod)βrhsis added (modulomod) to the current object;BigInt addModc(BigInt const &rhs, BigInt const &mod)β The sum (modulomod) of the current object andrhsis returned;BigInt::Word at(size_t index) constβ Returns theWordatindex. E.g., on a 32 bit architecture, if theBigIntvalue equals2, thenat(0)returns0, andat(1)returns2. Ifindexequals or exceeds the value returned bynWordsanFBB::Exceptionis thrown;BIGNUM const &bignum() constβ A reference to theBIGNUMvalue maintained by the currentBigIntobject is returned;char *bigEndian() constβ The value represented by the current object is stored in a series ofchartyped values in big-endian order. If a value consists of 5 chars the eight most significant bits will be stored in thecharhaving index value0, the eight least significant bits will be stored in thecharhaving index value4. When needed simply swapchar[i]withchar[j](i = 0 .. nBytes/2,j = nBytes-1 .. nBytes/2) to convert to little-endian order or use the memberlittleEndianto receive the representation in little-endian order. The return value consists of a series ofsizeInBytes()(see below) dynamically allocatedcharvalues. The caller ofbigEndianowns the allocated memory and should eventually delete it again usingdelete[]. Note that the current object's sign cannot be inferred from the return value;BigInt &clearBit(size_t index)β The current object's bit at index positionindexis cleared;BigInt clearBit(size_t index) constβ A copy of the current object having its bit at index positionindexcleared;BigInt &div(BigInt *remainder, BigInt const &rhs)β The current object is divided byrhs. The division's remainder is returned in*remainder;BigInt divc(BigInt *remainder, BigInt const &rhs) constβ The quotient of the current object andrhsis returned. The division's remainder is returned in*remainder;int compare(BigInt const &rsh) constβ Using signed values, if the current object is smaller thanrhs-1is returned; if they are equal0is returned; if the current object is larger thanths1is returned (see alsouCompare);BigInt &exp(BigInt const &exponent)β The current object is raised to the powerexponent;BigInt expc(BigInt const &exponent) constβ The current object raised to the powerexponentis returned;BigInt &expMod(BigInt const &exponent, BigInt const &mod)β The current object is raised to the powerexponentmodulomod;BigInt expModc(BigInt const &exponent, BigInt const &mod) constβ The current object raised to the powerexponentmodulomodis returned;BigInt &gcd(BigInt const &rhs)β The greatest common divisor (gcd) of the current object andrhsis assigned to the current object. To compute the least common multiple (lcm) the following relationship can be used:
lcm(a, b) = a * b / a.gcd(b)
BigInt gcdc(BigInt const &rhs) constβ The greatest common divisor (gcd) of the current object andrhsis returned. To compute the least common multiple (lcm) the following relationship can be used:
lcm(a, b) = a * b / a.gcd(b)
okay bestie stay with me, we're only part of the way through this page β more parts are coming so don't go anywhere π
bool hasBit(size_t index)β returns true if the bit sitting at index position index has been set, and false if it hasn't. That's the whole vibe check. βBigInt &inverseMod(BigInt const &mod)β the inverse of the current object, modulo mod, gets assigned straight into the current object. Meaning it's the valueretwhere this iconic little equation holds:
(*this * ret) % mod = 1
BigInt inverseModc(BigInt const &mod) constβ same inverse-of-the-current-object-modulo-mod situation, except it just returns it, no touching the original. Queen behaviour. πbool isNegative() constβ true if the current object is holding a negative value, bestie.bool isOdd() constβ true if the current object is an odd value. very demure, very mindful. πbool isOne() constβ true if the current object equals one (1). The loneliest number got representation.BigInt &isqrt()β the current object's integer square root gets assigned to the current object. FYI the integer square root of a valuexis the biggest integral value whose square doesn't exceedx. Like,isqrt(17) == 4, no cap. And it throws anExceptionif the current object's value is smaller than one. π¨BigInt isqrtc() constβ returns the integer square root of the current object. Same deal: anExceptiongets thrown if the current object's value is smaller than one.bool isZero() constβ true if the current object equals zero (0).char *littleEndian() constβ the value in the current object gets stored as a series ofchartyped values in little-endian order. So if a value is 5 chars long, the eight least significant bits land in thecharwith index value0. Want big-endian instead? Use the memberbigEndian. What you get back is a series ofsizeInBytes()(scroll down bestie) dynamically allocatedcharvalues. The caller oflittleEndianowns that allocated memory and should eventuallydelete[]it. Also heads up: the current object's sign cannot be inferred from the return value. πBigInt &lshift()β the current object's bits get shifted one bit to the left. The object's sign stays exactly as it was, unaltered. β¨BigInt lshiftc()β returns the current object's bits shifted one bit to the left. The object's sign will equal the current object's sign.BigInt &lshift(size_t nBits)β the current object's bits get shifted nBits to the left. Sign remains unaltered.BigInt lshiftc(size_t nBits) constβ returns the current object's bits shifted nBits to the left. The object's sign will equal the current object's sign.BigInt &maskBits(size_t lowerNBits)β keeps only the lowerNBits lower bits of the current object and clears all the higher order bits. The object's sign is not affected. π«ΆBigInt maskBitsc(size_t lowerNBits) constβ returns a copy of the current object with everything but its lowerNBits lower bits cleared. The returned object's sign equals the current object's sign.size_t maxWordIndex() constβ returns the maximum Word-index thatatandsetWordcan use on the currentBigIntvalue.BigInt &mulMod(BigInt const &rhs, BigInt const &mod)β the current object gets multiplied by rhs, modulo mod.BigInt mulModc(BigInt const &rhs, BigInt const &mod) constβ returns the current object multiplied by rhs, modulo mod.BigInt &negate()β the current object's value gets negated, i.e. the value flips its sign. main character flip. πBigInt negatec() constβ returns the negated value of the current object.size_t nWords() constβ returns how manywordsare needed to store theBigIntvalue. Important: that number depends on how many bytes per word your architecture has. 32-bit architectures get four bytes per word, 64-bit architectures get eight bytes per word.BigInt &rshift()β the current object's bits get shifted one bit to the right. The object's sign remains unaltered.BigInt rshiftc()β returns the current object's bits shifted one bit to the right. The object's sign will equal the current object's sign.BigInt &rshift(size_t nBits)β the current object's bits get shifted nBits to the right. Sign remains unaltered.BigInt rshiftc(size_t nBits) constβ returns the current object's bits shifted nBits to the right. The object's sign will equal the current object's sign.BigInt &setBit(size_t index)β sets the bit at index position index.BigInt setBitc(size_t index) constβ returns a copy of the current object with its bit at index position index set.BigInt &setBit(size_t index, bool value)β sets the bit at index position index to value.BigInt setBitc(size_t index, bool value) constβ returns a copy of the current object with its bit at index position index set to value.BigInt &setNegative(bool negative)β the current object's sign becomes negative if the function's argument istrue, and positive if the argument isfalse.BigInt setNegativec(bool negative) constβ returns a copy of the current object with a negative sign if the argument istrueand a positive sign if the argument isfalse.void setWord(size_t index, BigInt::Word value)β assigns value to theWordat index. Example time: on a 32 bit architecture, if theBigIntvalue equals2, then aftersetWord(1, 1)the value has become2. And if index exceeds the value returned bynWords, anFBB::Exceptiongets thrown. π¨size_t size() constβ returns the number of significant bits required to store the currentBIGNUMvalue.size_t sizeInBytes() constβ returns the number of bytes required to store the currentBIGNUMvalue.size_t constexpr sizeOfWord() constβBigIntvalues are stored in units ofwords, which are unsigned long values, and those can consist of, like, 32 or 64 bits. This returns how many bytes onewordtakes up:4for a 32 bit value,8for a 64 bit value, and possibly other values depending on specific architecture peculiarities. So yeah, this return value is architecture dependent, periodt. ποΈBigInt &sqr()β the current object's value gets squared.BigInt sqrc() constβ returns the square of the current object.BigInt &sqrMod(BigInt const &mod) constβ the current object's value gets squared modulo mod.BigInt sqrModc(BigInt const &mod) constβ returns the square of the current object, modulo mod.BigInt &subMod(BigInt const &rhs, BigInt const &mod)β rhs gets subtracted from the current object, modulo mod.BigInt subModc(BigInt const &rhs, BigInt const &mod) constβ returns the difference between the current object and rhs, modulo mod.void swap(BigInt &other)β the current object swaps its value with other. trading places moment. πBigInt &tildeBits()β every bit in the bytes of the current object and the sign of the current object get toggled. So after
Bigint b(5);
b.tildeBits();
b contains the value -250. Also go read the discussion with operator~() below. π
BigInt tildeBitsc() constβ returns a copy of the current object with its bits toggled.BigInt &tildeInt()β thetildeoperation is performed on the current object using the standardintsemantics. Like,~5results in-6. Also check the discussion withoperator~()below.BigInt tildeIntc() constβ returns a copy of the current object with thetildeoperation performed on it using the standardintsemantics.unsigned long ulong() constβ returns the absolute value stored in the current object as anunsigned long. If it can't be represented by anunsigned long, it returns0xffffffffL. that's the oh-no signal bestie πint uCompare(BigInt const &rsh) constβ using absolute values: if the current object is smaller than rsh,-1is returned; if they're equal,0is returned; if the current object is larger than rsh β the page literally saysthsthere, we do not gatekeep typos π β1is returned (see alsouCompare).
β¨ OVERLOADED OPERATORS β¨
Okay bestie, so like, most of these operators just do the obvious thing, no drama π
. But when that's not completely true, we've added a lil explanatory note so you're not left confused. For example, operator*() multiplies two BigInts and might promote one of the operands; operator*=() multiplies the lhs by the rhs BigInt and might promote the rhs operand. Slay.
Here's the full list, no cap:
Unary operators π¦
bool operator bool() constβ returnstrueif theBigIntvalue is unequal zero, otherwisefalseis returned;BigInt &operator++()β unary prefix increment operator;BigInt operator++(int)β unary postfix increment operator;BigInt &operator--()β unary prefix decrement operator;BigInt operator--(int)β unary postfix decrement operator;BigInt operator-()β unary negation operator;int operator[](size_t idx) constβ withBigIntobjects it returns the bit-value of the object'sidxth bit as the value0or1;BigInt::Bit operator[](size_t idx)β with non-constBigIntobjects it returns a reference to the bit-value of the object'sidxth bit. When used as lvalue, assigning a0or non-zero value to the operator's return value will either clear or set the bit. Likewise, the following arithmetic assignment operators may be used: binary or (|=), binary and (&=) or binary xor (^=). When used as rvalue the value of the object'sidxth bit is returned as aboolvalue. When inserted into astd::ostreamthe bit's value is displayed as0or1;BigInt operator~()β bestie, this one is not implemented π and the reason is a whole saga:- When used on
intvalues this operator toggles all the int's bits. E.g.,~5represents-6, and~-6again equals five. The-6is the result of the sign bit ofintvalues. The obvious implementation ofBigInt::operator~()is to toggle all the value's bits and to toggle its sign bit. For5this would result in-250:5, being101(binary), fits in one byte, so~5becomes11111010(binary), which is250. Its sign must be reversed as well, so it becomes-250. This clearly differs from the value represented by the int constant~5: when constructingBigInt(~5), the value-6is obtained. - It is possible to change the implementation. E.g., after
- When used on
Bigint b(5);
b = ~b;
~b could be implemented so that it results in the value -6. But this too leads to unexpected results. While 5 & ~5 == 0, this would no longer hold true for BigInt objects: Assuming b contains 5 then b & ~b would expand to (binary) 101 & (negative)110 which equals (binary) 100;
- Since either implementation produces unexpected results
BigInt::operator~()was not implemented. Instead two members are offered:tildeBits(), toggling all the bits of all theBigIntbytes and toggling its sign (so
Bigint b(5);
b.tildeBits();
changes b's value into -250), and tildeInt() changing the object's value into the value that would have been obtained if a BigInt was a mere int (so
Bigint b(5);
b.tildeInt();
changes b's value into -6).
Binary operators π
BigInt operator*(BigInt const &lhs, BigInt const &rhs)β multiplies, obviously πBigInt operator/(BigInt const &lhs, BigInt const &rhs)β returns the quotient of thelhsobject divided by therhsobject. The remainder is lost π (the memberdivperforms the division and makes the remainder available as well);BigInt operator%(BigInt const &lhs, BigInt const &rhs)β modulo, you know the vibe;BigInt operator+(BigInt const &lhs, BigInt const &rhs)β addition, periodt;BigInt operator-(BigInt const &lhs, BigInt const &rhs)β subtraction, slay;BigInt operator<<(BigInt const &lhs, size_t nBits)β see also thelshiftmember;BigInt operator>>=(BigInt const &lhs, size_t nBits)β see also thershiftmember;BigInt operator&(BigInt const &lhs, BigInt const &rhs)β returns aBigIntvalue consisting of the bit_and-ed bits and sign flags oflhsandrhsoperands. Consequently, if one operand is positive, the resulting value will be positive;BigInt operator|(BigInt const &lhs, BigInt const &rhs)β returns aBigIntvalue consisting of the bit_or-ed bits and sign flags oflhsandrhsoperands. Consequently, if either operand is negative, the result will be negative;BigInt operator^(BigInt const &lhs, BigInt const &rhs)β returns aBigIntvalue consisting of the bit_xor-ed bits and sign flags oflhsandrhsoperands. Consequently, if exactly one operand is negative, the result will be negative.
(Arithmetic) assignment operator(s) π
BigInt &operator*=(BigInt const &rhs)β multiply-assign, go off;BigInt &operator/=(BigInt const &rhs)β assigns the result of the (integer) division of the currentBigIntobject bythisto the current object. The remainder is lost. The memberdivdivides and makes the remainder available as well;BigInt &operator%=(BigInt const &rhs)β modulo-assign, iconic;BigInt &operator+=(BigInt const &rhs)β add-assign, we love;BigInt &operator-=(BigInt const &rhs)β subtract-assign, bestie;BigInt &operator<<=(size_t nBits)β see also thelshiftmembers;BigInt &operator>>=(size_t nBits)β see also thershiftmembers;BigInt &operator&=(BigInt const &rhs)β bit_ands the bits and sign flags of the current object and therhsoperand;BigInt &operator|=(BigInt const &rhs)β bit_ors the bits and sign flags of the current object and therhsoperand;BigInt &operator^=(BigInt const &rhs)β bit_xors the bits and sign flags of the current object and therhsoperand.
β¨ STATIC MEMBERS β¨
Okay so bestie, every member that hands you back a BigInt and doesn't need an existing BigInt object to do its thing is a static member. And the very first diophantus member β the one that returns a long long β is static too. π
long long diophantus(long long *factor1, long long *factor2, long long value1, long long value2)β it computes the integral solution offactor1 * value1 + factor2 * value2 = gcd. The function returns the greatest common divisor (gcd) ofvalue1andvalue2, and drops their multiplication factors into*factor1and*factor2respectively. Warning bestie: the solution is not unique β you get another one by addingk * value2tofactor1and subtractingk * value1fromfactor2. For values exceedingstd::numeric_limits<long, long>::max()you gotta use the next member instead.BigInt diophantus(BigInt *factor1, BigInt *factor2, BigInt const &value1, BigInt const &value2)β same energy, BigInt edition π. It computes the integral solution offactor1 * value1 + factor2 * value2 = gcd, returns the greatest common divisor (gcd) ofvalue1andvalue2, and returns their multiplication factors in*factor1and*factor2. Again, not unique: addk * value2tofactor1and subtractk * value1fromfactor2for another solution.BigInt fromText(std::string text, int mode = 0)β this one turns a textual representation of a number into an actualBigIntvalue π¦. Conversion keeps going until the end oftext, or until it hits a character outside of an expected range.
You can preset that expected range by specifying mode as ios::dec, ios::oct, or ios::hex β or, by default, the expected range is figured out by fromText itself by snooping on the characters in text π.
Default behaviour, no cap: if text contains hexadecimal characters then fromText assumes the number is hexadecimal (e.g., "abc" becomes the decimal value 2748); if text starts with 0 and only contains characters in the range 0 until (including) 7 then it assumes octal (e.g., "01234" becomes the decimal value 668). Otherwise it assumes a decimal value.
And if text doesn't represent a valid numerical value (for the given extraction mode) then a FBB::Exception exception gets thrown β message: fromText: text does not represent a BigInt value. π«
BigInt rand(size_t size, Msb msb = MSB_IS_ONE, Lsb lsb = ODD)β returns a cryptographically strong pseudo-random number ofsizebits π. The most significant bit(s) can be controlled bymsb(defaultMSB_IS_ONE), and the least significant bit can be controlled bylsb(defaultODD). Important: before you call this one for real, the random number generator must have been seeded. Like, must.
Straight from the RAND_add(3ssl) man-page, bestie:
OpenSSL makes sure that the PRNG state is unique for each thread. On systems that provide/dev/urandom, the randomness device is used to seed the PRNG transparently. However, on all other systems, the application is responsible for seeding the PRNG by callingRAND_add(3ssl),RAND_egd(3ssl),RAND_load_file(3ssl), orRAND_seed(3ssl).
BigInt randRange(BigInt const &max)β returns a cryptographically strong pseudo-random number in the range0 <= number < max. Same deal as above: seed the random number generator before calling this for real (peeprand, described just up there) β¨.BigInt setBigEndian(std::string const &bytes)β thebytes.length()bytes ofbytesare used to compute aBigIntobject, which this function returns. The characters inbytesare read as a series of bytes in big-endian order. See also the member functionbigEndian()above (iykyk). The returnedBigInthas a positive value π.BigInt prime(size_t nBits, BigInt const *mod = 0, BigInt const *rem = 0, PrimeType primeType = ANY)β returns a prime number ofnBitsbits π. If bothmodandremare non-zero, then the conditionprime % mod == remholds. (E.g., useprime % mod == 1in order to suit a given generator.) TheprimeTypeparameter can beANY, in which case(prime - 1) / 2may or may not be a prime. If it'sSAFEthen(prime - 1) / 2will be a (so-called safe) prime.BigInt pseudoRand(size_t size, Msb msb = MSB_IS_ONE, Lsb lsb = ODD)β this member merely callsBigInt::rand. That's it. That's the whole vibe π.BigInt pseudoRandRange(BigInt const &max)β this member merely callsBigInt::randRange. Periodt.
πΈ FREE FUNCTIONS IN THE FBB NAMESPACE πΈ
std::ostream &operator<<(ostream &out, BigInt const &value)β insertsvalueinto the providedostream. If thehexmanipulator has been inserted into the stream before inserting theBigIntvalue, the value shows up as hexadecimal (with no leading0x); if theoctmanipulator has been inserted, the value is represented as octal (starting with a0). And it's shown as a decimal value if thedecmanipulator is active. If theBigIntvalue is negative, its value gets a-character in front of it.
Lowkey, this conversion isn't very fast π’. For faster conversion consider using the LDC class (cf. ldc(3bobcat)) in statements like:
BigInt value; // contains a positive value
// insert value using decimal digits:
std::cout << LDC{ value };
std::istream &operator>>(istream &in, BigInt &value)β extractsvaluefrom the providedistream. Depending on the currently set extraction mode (dec,oct, orhex), the matching set of characters is extracted frominand converted to a number, which is stored invalue. Extraction stops at EOF or at the first character outside the range of characters matching the extraction mode. If no numerical characters were extracted, the stream'sfailbitis set π. The extracted value may be preceded by a-character, which results in an extracted negative value.
π EXAMPLE π
#include <iostream>
#include <bobcat/bigint>
using namespace std;
using namespace FBB;
int main()
{
BigInt value(BigInt::prime(100));
BigInt mod(BigInt::rand(50));
BigInt inverse(value.inverseModc(mod));
cout << β(β << value << " * " << inverse << ") % " << mod << " = " <<
( value * inverse ) % mod << β\nβ;
}
// shows:
// (1258586273445895786081124957771 * 828997573545038) %
// 1007205247048889 = 1
π§ FILES π§
bobcat/bigintβ defines the class interface
β SEE ALSO β
bobcat(7), diffiehellman(3bobcat), ldc(3bobcat), RAND_add(3ssl), RAND_egd(3ssl), RAND_load_file(3ssl), RAND_seed(3).
For BIGNUM:
https://www.openssl.org/docs/man1.0.2/man3/bn_sub_words.html
π BUGS π
None Reported. Flawless behaviour, honestly π .
π BOBCAT PROJECT FILES π
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
π BOBCAT π
Bobcat is an acronym of `Brokkenβs Own Base Classes And Templatesβ.
π COPYRIGHT π
This is free software, distributed under the terms of the GNU General Public License (GPL).
π AUTHOR π
Frank B. Brokken (f.b.brokken@rug.nl).
Okay bestie that's the whole page, start to finish, and we ate fr fr πβ¨. This one ships in the libbobcat-dev package, version 6.15.01, and the party's been going since 2005 all the way through 2026 β so go forth, make big numbers, and stay seeded ππ¦π.
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms