/**************************************************************************\ MODULE: GF2 SUMMARY: The class GF2 represents the field GF(2). Computationally speaking, it is not a particularly useful class. Its main use is to make the interfaces to the various finite field classes as uniform as possible. \**************************************************************************/ #include class GF2 { public: GF2(); // initial value 0 GF2(const GF2& a); // copy constructor GF2& operator=(const GF2& a); // assignment GF2& operator=(long a); // assignment }; long rep(GF2 a); // read-only access to representation of a /**************************************************************************\ Comparison \**************************************************************************/ long operator==(GF2 a, GF2 b); long operator!=(GF2 a, GF2 b); long IsZero(GF2 a); // test for 0 long IsOne(GF2 a); // test for 1 // PROMOTIONS: operators ==, != promote long to GF2 on (a, b). /**************************************************************************\ Addition \**************************************************************************/ // operator notation: GF2 operator+(GF2 a, GF2 b); GF2 operator-(GF2 a, GF2 b); GF2 operator-(GF2 a); // unary - GF2& operator+=(GF2& x, GF2 a); GF2& operator+=(GF2& x, long a); GF2& operator-=(GF2& x, GF2 a); GF2& operator-=(GF2& x, long a); GF2& operator++(GF2& x); // prefix void operator++(GF2& x, int); // postfix GF2& operator--(GF2& x); // prefix void operator--(GF2& x, int); // postfix // procedural versions: void add(GF2& x, GF2 a, GF2 b); // x = a + b void sub(GF2& x, GF2 a, GF2 b); // x = a - b void negate(GF2& x, GF2 a); // x = -a // PROMOTIONS: binary +, -, and procedures add, sub promote // from long to GF2 on (a, b). /**************************************************************************\ Multiplication \**************************************************************************/ // operator notation: GF2 operator*(GF2 a, GF2 b); GF2& operator*=(GF2& x, GF2 a); GF2& operator*=(GF2& x, long a); // procedural versions: void mul(GF2& x, GF2 a, GF2 b); // x = a * b void sqr(GF2& x, GF2 a); // x = a^2 GF2 sqr(GF2 a); // PROMOTIONS: operator * and procedure mul promote from long to GF2 // on (a, b). /**************************************************************************\ Division \**************************************************************************/ operator notation: GF2 operator/(z_p a, GF2 b); GF2& operator/=(GF2& x, GF2 a); GF2& operator/=(GF2& x, long a); procedural versions: void div(GF2& x, GF2 a, GF2 b); // x = a/b void inv(GF2& x, GF2 a); GF2 inv(GF2 a); // x = 1/a // PROMOTIONS: operator / and procedure div promote from long to GF2 // on (a, b). /**************************************************************************\ Exponentiation \**************************************************************************/ void power(GF2& x, GF2 a, long e); // x = a^e (e may be negative) GF2 power(GF2 a, long e); /**************************************************************************\ Random Elements \**************************************************************************/ void random(GF2& x); GF2 random_GF2(); // x = random element in GF2. Uses RandomBnd from ZZ. /**************************************************************************\ Input/Output \**************************************************************************/ ostream& operator<<(ostream& s, GF2 a); istream& operator>>(istream& s, GF2& x); // a ZZ is read and reduced mod 2 /**************************************************************************\ Miscellany \**************************************************************************/ void clear(GF2& x); // x = 0 void set(GF2& x); // x = 1 void swap(GF2& x, GF2& y); // swap x and y static GF2 GF2::zero(); // GF2::zero() yields a read-only reference to zero static long GF2::modulus(); // GF2::modulus() returns the value 2