last day (15 days later) » 

12:13
0
Q: Division of a number in Pailier encrytion which yields decimal result

MubeeI am very new to start with Paillier encryption system. I have used the homomorphic nature of this scheme, which allows addition of two encrypted numbers. I was wondering is it possible to divide two encrypted numbers which results in decimal ? Like I have tried one method which allows me to di...

If it works with even numbers, can't you just add $n^2$ to your odd number so that it's even?
What $is$ the desired output? Are you sure you didn't compute the value $(x_1+x_2) \cdot 2^{-1}$, because the inverse of 2 is actually (n+1)/2
Like which number ? I am only taking mode inverse of a divisor and doing a mod pow operation with encrypted number .
Like which number ? I am only taking mode inverse of a divisor and doing a mod pow operation with encrypted number as shown in the above answer either I sum two encrypted numbers or take a single encrypted number, the results are the same.
can you share a sample of results which you think are not correct? (n,value encrypted,value decrypted after division by 2)
assume n and nsquare are generated from Paillier public keys BigInteger sum=BigInteger.valueOf(141) BigInteger two=BigInteger.valueOf(2) BigInteger bigInteger= two.modInverse(n); BigInteger res=sum.modPow(bigInteger, nsquare); System.out.print(res) // not correct
what is n and what do you get? you should obtain 141*(n+1)/2
12:13
n is the Pallier public key and sum is obtained with Paillier addition and it is encrypted in my case when I passed this value as in my method. I post my code in the post may be it will give you better understanding about problem.
I'm pretty sure you're getting the correct answer, but are unable to understand it is correct
Yes, may be I am getting correct answer, but I dont know why I can not decrypt the result in case of odd sum is divided by 2 (like when the sum is even I can not decrypt the result ) and my method only works in case of even sum. As you can see my code
@Mubee, you cannot divide two encrypted numbers. You can only divide by an unencrypted number.
Even then, you will not get a decimal answer.
12:41
Sorry I did not get your point because in case of my number is encrypted and if original number is divisble by two in that case I get correct division result when I decrypted it but my problem is if the original number is not divisble by two then the result is decimal so I can not decrypt in that case.
try multiplying the result by 2, and reducing modulo N, and you should get the sum of the two messages you started with
when you divide by two, you actually divide by two in the ring Z_N
I think the message you decrypt is correct, and what is wrong is the message you expect
In my case wrong thing is that I can not decrypt decimal result or I do not know is division is being done or not because in case of two encrypted numbers which generate odd sum and when I pass that encrypted sum which is not divisble by two. Then in that case it should generate decimal result and Paillier does not work in this scanario.
Just for simplicity or clearance I want to sure that Is is possible to divide a number which yield decimal result and Paillier encryption support this kind of divsion ?
13:09
@Mubee, in your question you state I was wondering is it possible to divide two encrypted numbers which results in decimal ?. I'm saying that it is not possible to divide two encrypted numbers. Now, in your code, you are not dividing 2 encrypted numbers, you are dividing the sum of 2 encrypted numbers by the plaintext value 2.
anyways, back to your code. You are correct, dividing an encrypted value that is even by 2 will result in what you expect. Dividing an encrypted value that is odd will not result in what you expect, but it does result in what I expect.
Yes, you are right I am dividing the sum of two encrypted numbers by plain integer 2 and I think you understood my problem How I can solve this issue any idea ?
Consider this, say I am working in the integers mod 11. So possible value are {0,1,2,3,4,5,6,7,8,9,10}. Lets say I want to compute (2+4)/2 (mod 11). That is the same as 6/2 (mod 11), which is the same as 6*2^{-1} (mod 11)
What is 2^{-1} (mod 11)?
It is not 0.5, but rather 6.
So, 6*2^{-1} is equivalent to 6*6 (mod 11). 36 is equivalent to 3 (mod 11).
Which is the answer you would have expected, right?
Now, where it gets tricky is if the sum is not divisible by 2. Let say instead you had 7*2^{-1} (mod 11). Well that is the same thing as 7*6 (mod 11), which is 42 (mod 11). And 42 is equivalent to 9 mod 11. So, 7/2 (mod 11) is 9. Not what you expected, right?
Notice that there are no decimal values in my original set ({0,1,2,3,4,5,6,7,8,9,10}), so you cannot get something like 3.5.
Does this all make sense up to now?
Yes, you are right ..... It makes sense the modular airthmatic the answer can not be in decimal so it should exist the value set and decimal is not possible as far as I got it from your point.
Yep.
Îf the decimal is not possible then it means the result I am getting from the division can not be decrypted ?
13:23
You should be able to decrypt it. The decryption might just not really be what you are expecting.
In my case I can not decrypt
So in the example I gave you above, you would decrypt and get 9. You'd see that and think, "that is not what I was expecting, why is decryption failing". When in fact, decryption is not failing.
Are you getting an exception or something when trying to decrypt?
No thre is not an exception in the code the normal decyption method which does not work in decimal case
public BigInteger Decryption(BigInteger c) {
BigInteger u = g.modPow(lambda, nsquare).subtract(BigInteger.ONE).divide(n).modInverse(n);
return c.modPow(lambda, nsquare).subtract(BigInteger.ONE).divide(n).multiply(u).mod(n);
}
n and g are the public keys and lambda private key
I'm confused as to what you are expecting. What do you expect to be seeing?
May be I am not aware of my problem as well or can not precisely tell you the problem because for me the decryption of decimal result is still the problem.
13:34
So in your code example, you are expecting that last System.out.println to produce 70.5?
Or is your question more of how to modify the decryption function such that you get 70.5?
Yes, but its not possible as in modular airthmatic you told me but what ever is the result I should see it in the decryption.
So what are you seeing?
Are you just getting a blank line? Or are you getting a random number?
I am getting a random number
package com.sap.test;
/**
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
What I'm saying is that what you think is a random number is not actually random. It is in fact the right answer. For example, in the numbers I wrote above, you might have seen 9 and thought "man, why I am I getting this random number 9, that doesn't make sense." But 9 is in fact the right answer.
Do I need to take modular of answer ?
with n
13:41
No, I'm saying that as far as I can tell, you are getting the right answer. Nothing else to do.
If you want to verify, do the math on the unencrypted values. (141*2.modInverse(n)).mod(n), that sort of thing.

last day (15 days later) »