HElib icon indicating copy to clipboard operation
HElib copied to clipboard

How could i judge the number which i decrypted is positive number or negative number?

Open justtWu opened this issue 6 years ago • 4 comments

Technical Lead: Expected Effort (Days, Weeks or Months): Expected Start Date: People or Skills Needed:

Brief Description: I work in Machine Learning with Security.Usually i would compare a number with zero.As is known to everyone here,HELib work in modulus domain,so, when i got a decrypted data i can't judge whether it is bigger than zero or not.

justtWu avatar Dec 10 '18 05:12 justtWu

It is just a definition thing.

For a \in [0, p), we can also view it as a \in [-p/2, p/2). Also, HElib will give the decryption in the domain of [0, p). So we can recast values in that domain to [-p/2, p/2) by comparing with p/2. If the decrypting value is x >= p/2, we just view it as a negative value x - p.

fionser avatar Dec 10 '18 06:12 fionser

@fionser Thanks.But i think the premise of doing that is the modulus is bigger enough.As i test and view,the precision of plaintext can't be bigger than long's precision .Is that so?

justtWu avatar Dec 10 '18 11:12 justtWu

@justtWu Why can't it be bigger than long's precision? Surely for p=2 and r>=64 one does get equal or more than 64bit number precision. Using this practically and initializing a context with such big values is another thing. You can also achieve greater than long's precision using different encoding - namely binary. Example is to encrypt a 70 bit number as NTL:Vec<Ctxt> with length 70 where each Ctxt in this vector holds encryption of only a single bit. You can then use HElib's binary routines. As for positive or negative, fionser explained it perfectly. In the bit-wise encoding example you could say that MSB encodes the sign - 0 positive, 1 negative.

boev avatar Feb 15 '19 11:02 boev

It is weird that for p=4999, we can get both 4998-0=4998 and 3-4=-1=4998. It is obvious that 4998>0, while 3<4. How to distinguish these 4998 and -1?

MingliWu avatar Sep 10 '20 16:09 MingliWu