package aalgTest;

import java.math.BigInteger;

import aalg.algebra.DlDomainParameters;
import aalg.algebra.IGroup;
import aalg.algebra.InvertibleSubGroup;
import aalg.algebra.MultiGroup;
import aalg.algebra.MultiMonoidElement;
import aalg.algebra.PrimeField;
import aalg.algebra.PrimeFieldElement;
import aalg.algebra.SubGroupDefinition;

public class PrimeGroupCreator implements IGroupCreator<PrimeFieldElement> {

	private final static BigInteger PRIME = BigInteger.valueOf(257*260+1);
	
	private final static BigInteger FULL_GENERATOR_ORDER = PRIME.subtract(BigInteger.ONE);
	private final static BigInteger FULL_GENERATOR = BigInteger.valueOf(2);
	
	private final static BigInteger PRIME_GENERATOR_ORDER = BigInteger.valueOf(257);
	private final static BigInteger PRIME_GENERATOR = FULL_GENERATOR.modPow(FULL_GENERATOR_ORDER.divide(PRIME_GENERATOR_ORDER), PRIME);
	
	@Override
	public DlDomainParameters<PrimeFieldElement> createGroup() {
		final PrimeField field = new PrimeField(PRIME);
		final PrimeFieldElement fullGenerator = new PrimeFieldElement(FULL_GENERATOR);
		final PrimeFieldElement primeGenerator = new PrimeFieldElement(PRIME_GENERATOR);
		
		final SubGroupDefinition<PrimeFieldElement> fullSubGroup = new SubGroupDefinition<PrimeFieldElement>(
			field.getMultiplicativeGroup(), fullGenerator, FULL_GENERATOR_ORDER
		);

		final SubGroupDefinition<PrimeFieldElement> primeSubGroup = new SubGroupDefinition<PrimeFieldElement>(
			field.getMultiplicativeGroup(), primeGenerator, PRIME_GENERATOR_ORDER
		);

		return new DlDomainParameters<PrimeFieldElement>(
			field.getMultiplicativeGroup(), fullSubGroup, primeSubGroup
		);
	}
}
