Skip to content

Problem with encoding a very large BigInteger or BigDecimal without fraction #41

@mpnd

Description

@mpnd

We have an issue to encode a very large BigDecimal. For example, when I tried to encode 7.533938258014959827307132527342E+545 I got the following error:

Error com.n1analytics.paillier.EncodeException: Input value cannot be encoded.
   at com.n1analytics.paillier.StandardEncodingScheme.encode(StandardEncodingScheme.java:115)
   at com.n1analytics.paillier.StandardEncodingScheme.encode(StandardEncodingScheme.java:239)
   ...

The reason why I got the error is as follows:

  1. The number is a BigDecimal, however because it doesn't have a fraction part, Javallier encodes the number as a BigInteger to prevent precision loss. (StandardEncodingScheme line 224-240)
  2. When encoding a non-zero BigInteger, the number is repeatedly divided by the encoding base until the number is not divisible by the encoding base anymore. At each step, the exponent is incremented by one. (StandardEncodingScheme line 107-113)
  3. If the resulting number is greater than the PaillierContext's maxSignificand OR is less than the minSignificand then EncodeException is thrown. In this case the number is greater than maxSignificand. (StandardEncodingScheme line 114-116).

The problem is when encoding a BigInteger greater than maxSignificand OR less than the minSignificand, some of these numbers cannot be encoded either because the number is not divisible by the encoding base or the result of the repeat division (as mentioned in step 2 above) is not in the minSignificand to maxSignificand range.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions