BigInt

Arbitrary precision integer

struct BigInt {}

Constructors

this
this(T n)

Create BigInt from any integer

this
this(string str)

Create BigInt from a string. If the string starts with 0x the rest of the string will be interpreted as hexadecimal digits. Otherwise, it will be interpreted as a decimal number.

this
this(const(ubyte)* input, size_t length, Base base)

Create a BigInt from an integer in a ubyte array

this
this(RandomNumberGenerator rng, size_t bits, bool set_high_bit)

Create a random BigInt of the specified size

this
this(Sign s, size_t size)

Create BigInt of specified size, all zeros

this
this(BigInt other)

Move constructor

this
this(Vector!(ubyte, ALLOC) payload, Sign sign)
Undocumented in source.
this
this(RefCounted!(Vector!(ubyte, ALLOC), ALLOC) payload, Sign sign)
Undocumented in source.
this
this(SecureVector!word reg, Sign sign)
Undocumented in source.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Aliases

Base
alias Base = int
Undocumented in source.
Sign
alias Sign = bool
Undocumented in source.

Classes

DivideByZero
class DivideByZero

DivideByZero Exception

Enums

Decimal
anonymousenum Decimal

Base enumerator for encoding and decoding

Negative
anonymousenum Negative

Sign symbol definitions for positive and negative numbers

Functions

abs
BigInt abs()
binaryDecode
void binaryDecode(const(ubyte)* buf, size_t length)

Read integer value from a ubyte array with given size

binaryDecode
void binaryDecode(Vector!(ubyte, ALLOC) buf)
void binaryDecode(RefCounted!(Vector!(ubyte, ALLOC), ALLOC) buf)

Read integer value from a ubyte array (SecureVector!ubyte)

binaryEncode
void binaryEncode(ubyte* output)

Store BigInt-value in a given ubyte array

bits
size_t bits()

Get the bit length of the integer

byteAt
ubyte byteAt(size_t n)
bytes
size_t bytes()

Give ubyte length of the integer

clear
void clear()

Zeroize the BigInt. The size of the underlying register is not modified.

clearBit
void clearBit(size_t n)

Clear bit at specified position

cmp
int cmp(BigInt other, bool check_signs)

Compare this to another BigInt

encodedSize
size_t encodedSize(Base base)
flipSign
void flipSign()

Flip the sign of this BigInt

getBit
bool getBit(size_t n)

Return bit value at specified position

getSubstring
uint getSubstring(size_t offset, size_t length)

Return (a maximum of) 32 bits of the complete value

growTo
void growTo(size_t n)

Increase internal register buffer to at least n words

isEven
bool isEven()

Test if the integer has an even value

isNegative
bool isNegative()

Tests if the sign of the integer is negative

isNonzero
bool isNonzero()

Test if the integer is not zero

isOdd
bool isOdd()

Test if the integer has an odd value

isPositive
bool isPositive()

Tests if the sign of the integer is positive

isZero
bool isZero()

Test if the integer is zero

length
size_t length()
Undocumented in source. Be warned that the author may not have intended to support it.
load
void load(BigInt other)

Copy constructor

maskBits
void maskBits(size_t n)

Clear all but the lowest n bits

mutablePtr
word* mutablePtr()

Return a mutable pointer to the register

opAssign
BigInt opAssign(size_t other)

Move constructor

opAssign
void opAssign(BigInt other)

Move assignment

opBinary
BigInt opBinary(BigInt y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(word y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(BigInt y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(word y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(BigInt y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(word y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(BigInt y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(word y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(BigInt mod)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
word opBinary(word mod)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(size_t shift)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(size_t shift)
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
T opCast()

bool cast

opCast
T opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCmp
int opCmp(BigInt b)
Undocumented in source. Be warned that the author may not have intended to support it.
opCmp
int opCmp(size_t n)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(BigInt b)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(size_t n)
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(BigInt y)

+= operator

opOpAssign
void opOpAssign(word y)
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(BigInt y)

-= operator

opOpAssign
void opOpAssign(word y)
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(BigInt y)

*= operator

opOpAssign
void opOpAssign(word y)
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(BigInt y)

/= operator

opOpAssign
void opOpAssign(word y)
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(BigInt mod)

Modulo operator

opOpAssign
void opOpAssign(word mod)

Modulo operator

opOpAssign
void opOpAssign(size_t shift)

Left shift operator

opOpAssign
void opOpAssign(size_t shift)

Right shift operator

opUnary
BigInt opUnary()

Increment operator

opUnary
BigInt opUnary()

Decrement operator

opUnary
BigInt opUnary()

Unary negation operator

randomize
void randomize(RandomNumberGenerator rng, size_t bitsize, bool set_high_bit)

Fill BigInt with a random number with size of bitsize If set_high_bit is true, the highest bit will be set, which causes the entropy to be bits-1. Otherwise the highest bit is randomly choosen by the rng, causing the entropy to be bits.

reserve
void reserve(size_t n)
Undocumented in source. Be warned that the author may not have intended to support it.
reverseSign
Sign reverseSign()
setBit
void setBit(size_t n)

Set bit at specified position

setSign
void setSign(Sign s)

Set sign of the integer

sigWords
size_t sigWords()

Return how many words we need to hold this value

sign
Sign sign()

Return the sign of the integer

size
size_t size()

Give size of internal register

swap
void swap(BigInt other)

Swap this value with another

swapReg
void swapReg(SecureVector!word reg)
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString(Base base)
Undocumented in source. Be warned that the author may not have intended to support it.
toUint
uint toUint()

Convert this value into a uint, if it is in the range [0 ... 2**32-1], or otherwise throw new an exception.

toVector
Vector!char toVector(Base base)
Undocumented in source. Be warned that the author may not have intended to support it.
wordAt
word wordAt(size_t n)

Return the word at a specified position of the internal register

Properties

dup
BigInt dup [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
move
BigInt move [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
ptr
const(word*) ptr [@property getter]

Return a const pointer to the register

Static functions

decode
BigInt decode(const(ubyte)* buf, size_t length, Base base)

Create a BigInt from an integer in a ubyte array

decode
BigInt decode(RefCounted!(Vector!(ubyte, ALLOC), ALLOC) buf, Base base)

Create a BigInt from an integer in a ubyte array

decode
BigInt decode(Vector!(ubyte, ALLOC) buf, Base base)

Create a BigInt from an integer in a ubyte array

encode
Vector!ubyte encode(BigInt n, Base base)

Encode the integer value from a BigInt to an Array of bytes

encode
void encode(ubyte* output, BigInt n, Base base)

Encode the integer value from a BigInt to a ubyte array

encode1363
SecureVector!ubyte encode1363(BigInt n, size_t bytes)

Encode a BigInt to a ubyte array according to IEEE 1363

encodeLocked
SecureVector!ubyte encodeLocked(BigInt n, Base base)

Encode the integer value from a BigInt to a Secure Array of bytes

powerOf2
BigInt powerOf2(size_t n)

Create a power of two

randomInteger
BigInt randomInteger(RandomNumberGenerator rng, BigInt min, BigInt max)

Meta