// ============================================================ // // ZnD.h // // Copyright 2002, Dennis Meilicke and Rene Peralta // // ============================================================ // // Definition: // // Template class for modular arithmetic. // // ============================================================ #ifndef __nttlHeader_ZnD__ #define __nttlHeader_ZnD__ #include #include template< class T, int seq = 0 > class Zn { public: Zn( ); Zn( const Zn& x ); Zn( const T& x ); Zn& operator=( const Zn& x ); Zn& operator=( const T& x ); Zn operator+ ( const Zn& x ) const; Zn& operator+=( const Zn& x ); Zn& operator++( ); // pre Zn operator++( int ); // post Zn operator- ( const Zn& x ) const; Zn& operator-=( const Zn& x ); Zn& operator--( ); // pre Zn operator--( int ); // post Zn operator* ( const Zn& x ) const; Zn& operator*=( const Zn& x ); Zn operator/ ( const Zn& x ) const; Zn& operator/=( const Zn& x ); bool operator==( const Zn& x ) const; bool operator!=( const Zn& x ) const; bool operator< ( const Zn& x ) const; bool operator<=( const Zn& x ) const; bool operator> ( const Zn& x ) const; bool operator>=( const Zn& x ) const; Zn operator<< ( size_t d ) const; Zn& operator<<=( size_t d ); Zn operator>> ( size_t d ) const; Zn& operator>>=( size_t d ); Zn Square( ) const; void Normalize( bool addition = false ); void SetValue( const T& x ); T GetValue( void ) const; static void SetModulus( const T& m ) { (*Zn::Modulus()) = m; } static T GetModulus( void ) { return (*Zn::Modulus()); } ostream& Print( ostream& stream ) const; istream& Read( istream& stream ); private: T _x; static T* Modulus( const T* const m = (T*)0 ) { static T mod = 0; if( m != (T*)0 ) mod = *m; return &mod; } }; #endif // __nttlHeader_ZnD__