필터 지우기
필터 지우기

Converting some Java code to Matlab

조회 수: 1 (최근 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