All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dk.jonaslindstrom.ruffini.integers.structures.BigIntegersModuloN Maven / Gradle / Ivy

package dk.jonaslindstrom.ruffini.integers.structures;

import dk.jonaslindstrom.ruffini.common.algorithms.BarrettReduction;
import dk.jonaslindstrom.ruffini.common.structures.QuotientRing;

import java.math.BigInteger;

/**
 * This class is an implementation of ℤ / nℤ, e.g. the integers  modulo the principal
 * ideal generated by a given integer n.
 */
public class BigIntegersModuloN extends QuotientRing {

    public BigIntegersModuloN(BigInteger n) {
        super(BigIntegers.getInstance(), new BarrettReduction(n));
        this.mod = n;
    }

    public BigIntegersModuloN(int n) {
        this(BigInteger.valueOf(n));
    }

    public BigInteger getModulus() {
        return mod;
    }

    @Override
    public BigInteger power(BigInteger x, int e) {
        return x.modPow(BigInteger.valueOf(e), getModulus());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy