View Javadoc
1   package civitas.crypto.parameters.encoder;
2   
3   import civitas.crypto.CryptoException;
4   import civitas.crypto.parameters.ElGamalParameters;
5   import civitas.util.CivitasBigInteger;
6   
7   public class SafePrimeDecode {
8   	public CivitasBigInteger apply(CivitasBigInteger i, final ElGamalParameters elGamalParameters)
9   			throws CryptoException {
10  		if (i.compareTo(elGamalParameters.p) > 0) {
11  			throw new CryptoException("Message is too large for parameters");
12  		}
13  		if (i.compareTo(elGamalParameters.q) > 0) {
14  			i = elGamalParameters.p.subtract(i);
15  		}
16  		return i;
17  	}
18  }