Crypto++  5.6.4
Free C++ class library of cryptographic schemes
Classes | Friends | List of all members
PolynomialMod2 Class Reference

Polynomial with Coefficients in GF(2) More...


class  DivideByZero
 divide by zero exception More...


class GF2NT


typedef unsigned int RandomizationParameter


 PolynomialMod2 ()
 creates the zero polynomial
 PolynomialMod2 (const PolynomialMod2 &t)
 copy constructor
 PolynomialMod2 (word value, size_t bitLength=WORD_BITS)
 convert from word More...
 PolynomialMod2 (const byte *encodedPoly, size_t byteCount)
 convert from big-endian byte array
 PolynomialMod2 (BufferedTransformation &encodedPoly, size_t byteCount)
 convert from big-endian form stored in a BufferedTransformation
 PolynomialMod2 (RandomNumberGenerator &rng, size_t bitcount)
 create a random polynomial uniformly distributed over all polynomials with degree less than bitcount
static PolynomialMod2 Monomial (size_t i)
 return x^i
static PolynomialMod2 Trinomial (size_t t0, size_t t1, size_t t2)
 return x^t0 + x^t1 + x^t2
static PolynomialMod2 Pentanomial (size_t t0, size_t t1, size_t t2, size_t t3, size_t t4)
 return x^t0 + x^t1 + x^t2 + x^t3 + x^t4
static PolynomialMod2 AllOnes (size_t n)
 return x^(n-1) + ... + x + 1
static const PolynomialMod2Zero ()
static const PolynomialMod2One ()


unsigned int MinEncodedSize () const
 minimum number of bytes to encode this polynomial More...
void Encode (byte *output, size_t outputLen) const
 encode in big-endian format More...
void Encode (BufferedTransformation &bt, size_t outputLen) const
void Decode (const byte *input, size_t inputLen)
void Decode (BufferedTransformation &bt, size_t inputLen)
void DEREncodeAsOctetString (BufferedTransformation &bt, size_t length) const
 encode value as big-endian octet string
void BERDecodeAsOctetString (BufferedTransformation &bt, size_t length)
 decode value as big-endian octet string


unsigned int BitCount () const
 number of significant bits = Degree() + 1
unsigned int ByteCount () const
 number of significant bytes = ceiling(BitCount()/8)
unsigned int WordCount () const
 number of significant words = ceiling(ByteCount()/sizeof(word))
bool GetBit (size_t n) const
 return the n-th bit, n=0 being the least significant bit
byte GetByte (size_t n) const
 return the n-th byte
signed int Degree () const
 the zero polynomial will return a degree of -1
unsigned int CoefficientCount () const
 degree + 1
int GetCoefficient (size_t i) const
 return coefficient for x^i
int operator[] (unsigned int i) const
 return coefficient for x^i
bool IsZero () const
bool Equals (const PolynomialMod2 &rhs) const


PolynomialMod2operator= (const PolynomialMod2 &t)
PolynomialMod2operator&= (const PolynomialMod2 &t)
PolynomialMod2operator^= (const PolynomialMod2 &t)
PolynomialMod2operator+= (const PolynomialMod2 &t)
PolynomialMod2operator-= (const PolynomialMod2 &t)
PolynomialMod2operator*= (const PolynomialMod2 &t)
PolynomialMod2operator/= (const PolynomialMod2 &t)
PolynomialMod2operator%= (const PolynomialMod2 &t)
PolynomialMod2operator<<= (unsigned int)
PolynomialMod2operator>>= (unsigned int)
void Randomize (RandomNumberGenerator &rng, size_t bitcount)
void SetBit (size_t i, int value=1)
void SetByte (size_t n, byte value)
 set the n-th byte to value
void SetCoefficient (size_t i, int value)
void swap (PolynomialMod2 &a)


bool operator! () const
PolynomialMod2 operator+ () const
PolynomialMod2 operator- () const


PolynomialMod2 And (const PolynomialMod2 &b) const
PolynomialMod2 Xor (const PolynomialMod2 &b) const
PolynomialMod2 Plus (const PolynomialMod2 &b) const
PolynomialMod2 Minus (const PolynomialMod2 &b) const
PolynomialMod2 Times (const PolynomialMod2 &b) const
PolynomialMod2 DividedBy (const PolynomialMod2 &b) const
PolynomialMod2 Modulo (const PolynomialMod2 &b) const
PolynomialMod2 operator>> (unsigned int n) const
PolynomialMod2 operator<< (unsigned int n) const


unsigned int Parity () const
 sum modulo 2 of all coefficients
bool IsIrreducible () const
 check for irreducibility
PolynomialMod2 Doubled () const
 is always zero since we're working modulo 2
PolynomialMod2 Squared () const
bool IsUnit () const
 only 1 is a unit
PolynomialMod2 MultiplicativeInverse () const
 return inverse if *this is a unit, otherwise return 0
PolynomialMod2 InverseMod (const PolynomialMod2 &) const
 calculate multiplicative inverse of *this mod n
static PolynomialMod2 Gcd (const PolynomialMod2 &a, const PolynomialMod2 &n)
 greatest common divisor
static void Divide (PolynomialMod2 &r, PolynomialMod2 &q, const PolynomialMod2 &a, const PolynomialMod2 &d)
 calculate r and q such that (a == d*q + r) && (deg(r) < deg(d))


std::ostream & operator<< (std::ostream &out, const PolynomialMod2 &a)

Detailed Description

Polynomial with Coefficients in GF(2)

Definition at line 18 of file gf2n.h.

Constructor & Destructor Documentation

PolynomialMod2::PolynomialMod2 ( word  value,
size_t  bitLength = WORD_BITS 

convert from word

value should be encoded with the least significant bit as coefficient to x^0 and most significant bit as coefficient to x^(WORD_BITS-1) bitLength denotes how much memory to allocate initially

Definition at line 27 of file gf2n.cpp.

Member Function Documentation

unsigned int PolynomialMod2::MinEncodedSize ( ) const

minimum number of bytes to encode this polynomial

MinEncodedSize of 0 is 1

Definition at line 78 of file gf2n.h.

void PolynomialMod2::Encode ( byte *  output,
size_t  outputLen 
) const

encode in big-endian format

if outputLen < MinEncodedSize, the most significant bytes will be dropped if outputLen > MinEncodedSize, the most significant bytes will be padded

Definition at line 144 of file gf2n.cpp.

The documentation for this class was generated from the following files: