HElib
HElib copied to clipboard
How could i judge the number which i decrypted is positive number or negative number?
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.
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 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 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.
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?