Next Previous Table of Contents

# The MontyRep Class

    #include <linteger/montyrep.hxx>

## Overview

The goal of the MontyRep class (with the help of the MontyRing class) is to provide support for arithmetic in residue rings of odd cardinality. A ring is set by the user, and arithmetic involving residue classes then takes place inside this ring until it is changed. Multiplication in these special rings can be performed more rapidly than in general by using an internal representation due to Montgomery (1985). Currently, only enough functionality is provided to allow an instantiation of the LC_Exp function.

Warning: The residue ring that computations involving `MontRep` instances are to take place in is completely independent of the residue ring that computations involving `ResidueClass` instances are to take place in. To emphasize this fact, the ring in which computations involving Montgomery representations are to take place in will be refered to as the "Montgomery residue ring".

## Public Methods

### Default Constructor

    MontyRep::MontyRep();

This constructor creates a NULL instance, which represent no residue class in the current Montgomery residue ring. Be sure to assign a proper value to this instance before using it.

### Constructor from an `LInteger`

    MontyRep::MontyRep(const LInteger& x);

This constructor creates an instance representing the residue class within the current Montgomery residue ring that contains the integer that x represents.

### Copy Constructor

    MontyRep::MontyRep(const MontyRep& x);

The copy constructor creates an instance representing the same residue class that x represents.

### Destructor

    MontyRep::~MontyRep();

The destructor deletes memory dynamically allocated to the instance.

### Assignment from a `MontyRep`

    MontyRep& MontyRep::operator=(const MontyRep& x);

This assignment makes the calling instance represent the same residue class that x represents. A reference to the modified calling instance is returned.

### MultiplicativeIdentity

    static inline MontyRep MontyRep::MultiplicativeIdentity();

This method returns an instance representing the residue class which is the multiplicative identity of the current Montgomery residue ring.

### Ring

    static inline const MontyRing& MontyRep::Ring();

This method returns a `MontyRing` that contains precomputation information for the residue ring in which arithmetic involving Montgomery representations is to take place.

### SetRing

    static MontyRing MontyRep::SetRing(const MontyRing& newRing);

This method sets the residue ring in which arithmetic involving Montgomery representations is to take place equal to the ring that newRing represents. A `MontyRing` representing the ring that arithmetic involving Montgomery representations was previously taking place in is returned.

### Times Equals: `y*=x`

    MontyRep& operator*=(const MontyRep& x);

This operator makes the calling instance represent the product (in the current Montgomery residue ring) of the residue class it represented before the call and the residue class that x represents. A reference to the modified calling instance is returned.

### Square

    MontyRep& MontyRep::Square();

This method makes the calling instance represent the square (in the current Montgomery residue ring) of residue class it represented before the call, and returns a reference to the modified calling instance.

### ToLInteger

    LInteger MontyRep::ToLInteger();

This method returns an `LInteger` representing the principal residue in the residue class that the calling instance represents. That is to say, that if the current Montgomery residue ring has x elements, then this method will return the member of the residue class that the calling instance represents that is greater than or equal to 0, but less than x.

Next Previous Table of Contents