Converting some Java code to Matlab
2 次查看(过去 30 天)
显示 更早的评论
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);
}
2 个评论
Walter Roberson
2018-5-31
To be able to do BigInteger, you will need the Symbolic Toolbox, or you will need https://www.mathworks.com/matlabcentral/fileexchange/47497-big-integer-arithmetic or https://www.mathworks.com/matlabcentral/fileexchange/6446-multiple-precision-toolbox-for-matlab or https://www.mathworks.com/matlabcentral/fileexchange/22725-variable-precision-integer-arithmetic
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!