Converting some Java code to Matlab
조회 수: 1 (최근 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!