I am trying to do some calculations with the Paillier Homomorphic encryption scheme. Specifically, given three plain text integers, x1, x2,and x3. I want to first encrypt them, getting their corresponding ciphertexts, say c1, c2 and c3. I want to find the results of (x1+x2+x3)/3 by utilizing c1, c2, c3 and the homomorphic property of Paillier.
I found a post here, which was answered quite a long time ago. When I try the toy example in the accepted answer in this link myself, I can not get the provided result. Specifically, for the following step:
I can calculate the value of k^(-1) mod N with powermod function correctly, but I can not calculate [\mu] correctly. Here is what I did:
- Say
temp = powermod(k, -1, N), CalculateA = powermod(c1*c2*c3, temp, N^2). - Calculate
B = powermod(r, N, N^2). - Calculate
[\mu] = mod(A*B, N^2).
This gives me wrong results, I also try replacing powermod with mod, but this time the answer is going to NaN.
Can anyone help me with this, please? Thanks in advance!
Ais different from the one you have (Bis the same), any ideas? (I can confirm when I call the function, the values ofc1, c2andc3are correct and I have319242668083forA) – Sea_ Jun 26 '23 at 16:44tempis? – Daniel S Jun 26 '23 at 17:47tempis also the same as the one you show... – Sea_ Jun 26 '23 at 17:51Ais the only one that is not correct when using Matlab? I do not think the reason is the number precision... – Sea_ Jun 26 '23 at 17:57