Huelse / SEAL-Python

Microsoft SEAL 4.X For Python
MIT License
312 stars 66 forks source link

Signed integers not supported? #12

Closed carlee0 closed 4 years ago

carlee0 commented 4 years ago

Hi, it seems that signed integers are not supported. Is this the case? Please see the example below and the error message.

>>> p1 = seal.Plaintext("5")
>>> p3 = seal.Plaintext("-5")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unable to parse hex_poly
>>> p2 = seal.Plaintext(-5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. seal.Plaintext()
    2. seal.Plaintext(arg0: int)
    3. seal.Plaintext(arg0: int, arg1: int)
    4. seal.Plaintext(arg0: str)
    5. seal.Plaintext(arg0: seal.Plaintext)
Invoked with: -5

I am new to c++ but I have some experience with c and quite comfortable with Python. I could give it a go to find a fix if you could point me to the direction. :)

Huelse commented 4 years ago

You can use it like this

encoder = IntegerEncoder(context)
value2 = -7
plain2 = Plaintext(encoder.encode(value2))

plain1 = Plaintext("6")

The data for the plaintext is a polynomial with coefficients modulo the plaintext modulus, see SEAL/native/src/seal/plaintext.h for details.

carlee0 commented 4 years ago

Thanks! :)