serengil / LightPHE

A Lightweight Partially Homomorphic Encryption Library for Python
https://bit.ly/46vWz9w
MIT License
53 stars 5 forks source link

Multiplication with a Plain Constant doesn't work #20

Closed renguomin closed 6 months ago

renguomin commented 6 months ago

plain constant multiplication doesn't work for the algorithms that are supported for this operation, i.e. Paillier, Damgard-Jurik, etc.

Run the sample code in the README,

from lightphe import LightPHE
cs = LightPHE(algorithm_name = "Paillier")
m1 = 17
c1 = cs.encrypt(m1)
k = 1.05

assert cs.decrypt(k * c1) == k * m1

I get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

I think this is due to the type of k. If k is integer, e.g. 5, the above code works. I tested in 3 environment, the result is the same:

  1. py3.10 64bit mac
  2. py3.12 64bit mac
  3. py3.10 32bit windows
serengil commented 6 months ago

The issue is that multiplication of 17 and 1.05 is not integer independent from k.

Try it for m=10000 and k=1.05

renguomin commented 6 months ago

I see. Is this (the multiplication must be integer) the limitation of the algorithms or your implementation?

serengil commented 6 months ago

Yes. These algorithms are working on integers. Even float numbers can be represented as integers as well.

renguomin commented 6 months ago

These algorithms are working on integers

Sorry I don't quite understand your answer. Are you saying the (mathematical) algorithms themselves can't deal with float numbers? Or is it just your implementation (your code) doesn't work with float?

serengil commented 6 months ago

Algorithms' limitations

renguomin commented 6 months ago

Got it, thanks for the clarification.