1 package civitas.crypto.parameters.encoder;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Controller;
5
6 import civitas.crypto.parameters.ElGamalParameters;
7 import civitas.crypto.parameters.LegendreSymbol;
8 import civitas.util.CivitasBigInteger;
9
10 @Controller
11 public class SafePrimeEncode {
12
13 @Autowired
14 LegendreSymbol legendreSymbol;
15
16 public CivitasBigInteger apply(final CivitasBigInteger x, final ElGamalParameters elGamalParameters) {
17 CivitasBigInteger encoding = x;
18 if (legendreSymbol.apply(encoding, elGamalParameters.p, elGamalParameters.q) == -1) {
19 encoding = elGamalParameters.p.subtract(encoding);
20 }
21 return encoding;
22 }
23 }