Converting some Java code to Matlab

3 次查看(过去 30 天)
Faraz
Faraz 2018-5-31
评论: Faraz 2018-6-4
Hi,
I need some help in converting some java code to Matlab. I have absolutely no knowledge of java and hope anyone here with more knowledge in java than me can better interpret some of the functions used.
I am basically trying to perform euclidean distance calculation in the encrypted domain (Paillier encryption). Using the homomorphic properties of Paillier, the squared euclidean distance formula can be written as:
I found someone facing the same problem trying to implement this, and he provided his code solution in java here.
If anyone with knowledge of java could please convert this to matlab, I would really appreciate it.
I have already implemented the "PallierEncrypt" function in matlab, it is the distance calculation below that is proving to be difficult.
Many thanks
public BigInteger secureEuDistanceMD(int[] p, int[] q){
// Server (Owner of q) - PART 1
BigInteger[] enc_Q = new BigInteger[q.length];
BigInteger sumsqrQ = BigInteger.ZERO;
BigInteger enc_sumsqrQ;
for (int i = 0; i < q.length; i++) {
BigInteger bigQ = new BigInteger("" + q[i]);
enc_Q[i] = paillier.Encryption(bigQ);
sumsqrQ = sumsqrQ.add(bigQ.multiply(bigQ));
}
enc_sumsqrQ = paillier.Encryption(sumsqrQ);
// Client (Owner of p) - PART 2
BigInteger sumsqrP = BigInteger.ZERO;
BigInteger enc_sumsqrP;
BigInteger enc_sumPQ = BigInteger.ONE;
for (int i = 0; i < p.length; i++) {
BigInteger bigP = new BigInteger("" + p[i]);
sumsqrP = sumsqrP.add(bigP.multiply(bigP));
enc_sumPQ = enc_sumPQ.multiply(enc_Q[i].modPow(new BigInteger("-2").multiply(bigP), paillier.nsquare));
}
enc_sumsqrP = paillier.Encryption(sumsqrP);
BigInteger enc_euDist = enc_sumsqrP.multiply(enc_sumsqrQ).multiply(enc_sumPQ);
// Server - PART 3 (Decryption)
return paillier.Decryption(enc_euDist);
}

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by