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!