这是我的Paillier课程:
do.call
在加密方法中,变量 rin 未被计算和记录,之后的变量也是如此。 Android应用程序然后停止响应。我假设它是因为 c 返回空值。
输出如下,日志d不显示 rin 的值:
public class Paillier {
private static BigInteger Nv;
private static BigInteger Nc;
private static BigInteger b;
private static BigInteger p;
private static BigInteger q;
private static BigInteger n;
private static BigInteger nsquared;
private static BigInteger lambda;
private static BigInteger g;
private static BigInteger mu;
public Paillier(BigInteger cNv, BigInteger cNc, BigInteger cb, BigInteger cp, BigInteger cq) {
this.Nv = cNv;
this.Nc = cNc;
this.b = cb;
this.p = cp;
this.q = cq;
keyGeneration();
}
public static BigInteger getn() {
return n;
}
public static void keyGeneration() {
n = p.multiply(q);
nsquared = n.multiply(n);
lambda = carmichaelFunction();
g = new BigInteger("1578485334874745");
BigInteger gModPow = LFunction(g.modPow(lambda, nsquared));
mu = gModPow.modInverse(n);
/**System.out.print("Encryption key: (" + n + ", " + g + ") \n");
System.out.print("Decryption key: (" + lambda + ", " + mu + ") \n");**/
}
public static BigInteger carmichaelFunction() {
BigInteger product = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
BigInteger lamb = product.divide(p.subtract(BigInteger.ONE).gcd(q.subtract(BigInteger.ONE)));
return lamb;
}
public static BigInteger LFunction(BigInteger u) {
BigInteger L = u.subtract(BigInteger.ONE).divide(n);
return L;
}
public BigInteger encryption(int[] votes) {
BigInteger m = BigInteger.ZERO;
for (BigInteger i = BigInteger.ZERO; i.compareTo(Nc) == -1; i = i.add(BigInteger.ONE)) {
if (votes[i.intValue()] == 1)
m = m.add(b.pow(i.intValue()));
}
Log.d("MESSAGE","Message to be encrypted "+ m);
Log.d("n ", n.toString());
Log.d("nsquared ", nsquared.toString());
BigInteger r = randomZStarN();
Log.d("RandomZStarN ", r.toString());
BigInteger gmi = g.pow(m.intValue());
Log.d("gmi ", gmi.toString());
BigInteger rin = r.pow(n.intValue());
Log.d("rin ", rin.toString());
BigInteger gMr = gmi.multiply(rin);
Log.d("gMr ", gMr.toString());
BigInteger c = gMr.mod(nsquared);
Log.d("Ciphertext ", c.toString());
return c;
}
public static BigInteger randomZStarN() {
BigInteger r;
do {
r = new BigInteger(n.bitLength(), new Random());
} while (r.compareTo(n) >= 0 || r.gcd(n).intValue() != 1);
return r;
}
}
有人可以帮忙吗?