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.

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)

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

binaryDecode
void binaryDecode(const(Vector!(ubyte, ALLOC))* buf)
Undocumented in source. Be warned that the author may not have intended to support it.
binaryDecode
void binaryDecode(RefCounted!(Vector!(ubyte, ALLOC), ALLOC) buf)

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

binaryDecode
void binaryDecode(const(RefCounted!(Vector!(ubyte, ALLOC), ALLOC))* buf)
Undocumented in source. Be warned that the author may not have intended to support it.
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(const(BigInt)* other, bool check_signs)

Compare this to another BigInt

cmp
int cmp(BigInt other, bool check_signs)
Undocumented in source. Be warned that the author may not have intended to support it.
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
void opAssign(T number)
Undocumented in source. Be warned that the author may not have intended to support it.
opAssign
BigInt opAssign(size_t other)

Move constructor

opAssign
void opAssign(T other)

Move assignment

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

Move assignment

opAssign
void opAssign(BigInt other)

Move assignment

opBinary
BigInt opBinary(const(BigInt)* y)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
BigInt opBinary(const(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(const(BigInt)* 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(const(BigInt)* 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(const(BigInt)* 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(const(BigInt)* mod)
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

opCmp
int opCmp(const(BigInt)* b)
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(const(BigInt)* b)
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(const(BigInt)* y)

+= operator

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

-= operator

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

*= operator

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

/= operator

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

Modulo operator

opOpAssign
void opOpAssign(BigInt mod)
Undocumented in source. Be warned that the author may not have intended to support it.
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(T other_)

Swap this value with another

swap
void swap(BigInt* other_)
Undocumented in source. Be warned that the author may not have intended to support it.
swap
void swap(BigInt other_)
Undocumented in source. Be warned that the author may not have intended to support it.
swap
void swap(BigInt other_)
Undocumented in source. Be warned that the author may not have intended to support it.
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

clone
BigInt clone [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
dup
BigInt dup [@property getter]
Undocumented in source.
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

decode
BigInt decode(const(Vector!(ubyte, ALLOC)*) buf, Base base)
Undocumented in source. Be warned that the author may not have intended to support it.
encode
Vector!ubyte encode(const(BigInt)* n, Base base)

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

encode
Vector!ubyte encode(BigInt n, Base base)
Undocumented in source. Be warned that the author may not have intended to support it.
encode
void encode(ubyte* output, const(BigInt)* n, Base base)

Encode the integer value from a BigInt to a ubyte array

encode
void encode(ubyte* output, BigInt n, Base base)
Undocumented in source. Be warned that the author may not have intended to support it.
encode1363
SecureVector!ubyte encode1363(const(BigInt)* n, size_t bytes)

Encode a BigInt to a ubyte array according to IEEE 1363

encode1363
SecureVector!ubyte encode1363(BigInt n, size_t bytes)
Undocumented in source. Be warned that the author may not have intended to support it.
encodeLocked
SecureVector!ubyte encodeLocked(const(BigInt)* n, Base base)

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

encodeLocked
SecureVector!ubyte encodeLocked(BigInt n, Base base)
Undocumented in source. Be warned that the author may not have intended to support it.
powerOf2
BigInt powerOf2(size_t n)

Create a power of two

randomInteger
BigInt randomInteger(RandomNumberGenerator rng, const(BigInt)* min, const(BigInt)* max)
randomInteger
BigInt randomInteger(RandomNumberGenerator rng, BigInt min, BigInt max)
Undocumented in source. Be warned that the author may not have intended to support it.

Meta