PyPoly

class Pyfhel.PyPoly(PyPoly other=None, PyCtxt ref=None, PyPtxt ptxt=None, size_t index=0)

Bases: object

Polynomial class of Pyfhel with the underlying data of a PyCtxt/PyPtxt.

other_ptxt

Other PyPtxt to deep copy

Type:

PyPtxt, optional

__init__()

Initializes a PyPoly polynomial.

To fill the polynomial during initialization you can either:
  • Provide a PyPoly to deep copy.

  • Provide a reference PyCtxt and (optionally) an index for the i-th

    polynomial in the cipertext or (optionally) a source PyPtxt.

other

Other PyPoly to deep copy.

Type:

PyPoly, optional

ref

PyCtxt instance needed as reference.

Type:

PyCtxt, optional

size_t

extract i-th polynomial from ciphertext ref.

Type:

int, optional

ptxt

plaintext used as source.

Type:

PyPtxt, optional

Methods

__add__

Sums this pollynomial with another polynomial.

__sub__

Subtracts other polynomial from this polynomial.

__mul__

Multiplies this polynomial with another polynomial.

__invert__

Inverts this polynomial.

__repr__()

Return repr(self).

__init__

Initializes a PyPoly polynomial.

check_afpoly(self)

Checks if afpoly was initialized or not

from_bytes(-> void)

Recover the serialized polynomial from a binary/bytes string.

from_coeff_list(self, ...)

Sets all the coefficients at once.

get_coeff(self, size_t i)

Gets the chosen coefficient in position i.

load(-> void)

Load the polynomial from a file.

save(-> void)

Save the polynomial into a file.

set_coeff(self, cy_complex coeff, size_t i)

Sets the given complex value as coefficient in position i.

to_bytes(-> bytes)

Serialize the polynomial into a binary/bytes string.

to_coeff_list(self)

List of complex coefficients of the polynomial

Attributes

coeff_count

coeff_modulus_count

API description

__add__()

Sums this pollynomial with another polynomial.

Sums with a PyPoly, storing the result in a new PyPoly.

Parameters:

other (PyPoly) – Second summand.

Returns:

Polynomial resulting of addition.

Return type:

PyPoly

See also

poly_add()

__invert__()

Inverts this polynomial.

See also

poly_invert()

__mul__()

Multiplies this polynomial with another polynomial.

Multiplies with a PyPoly, storing the result in a new PyPoly.

Parameters:

other (PyPoly) – multiplier polynomial.

Returns:

Polynomial resulting of multiplication.

Return type:

PyPoly

See also

poly_multiply()

__repr__()

Return repr(self).

__sub__()

Subtracts other polynomial from this polynomial.

Subtracts with a PyPoly, storing the result in this PyPoly.

Parameters:

other (PyPoly) – Substrahend, to be subtracted from this polynomial.

Returns:

Polynomial resulting of subtraction.

Return type:

PyPoly

See also

poly_subtract()

check_afpoly(self) void

Checks if afpoly was initialized or not

from_bytes(self, bytes content, encoding) void
from_bytes(bytes content) None

Recover the serialized polynomial from a binary/bytes string.

Parameters:
  • content – (bytes) Python bytes object containing the PyPoly.

  • encoding – (:obj: str) String or type describing the encoding: * (‘int’, ‘integer’, int, 1, scheme_t.INTEGER) -> integer encoding. * (‘float’, ‘double’, float, 2, scheme_t.FRACTIONAL) -> fractional encoding. * (‘array’, ‘batch’, ‘matrix’, list, 3, scheme_t.BATCH) -> batch encoding.

from_coeff_list(self, vector[cy_complex] coeff_list, PyCtxt ref) void

Sets all the coefficients at once.

Parameters:

coeff_list (List(complex)) – list of coefficients

Returns:

value decrypted.

Return type:

int, float, np.array

See also

decode()

get_coeff(self, size_t i) cy_complex

Gets the chosen coefficient in position i.

Parameters:

i (int) – coefficient position

Returns:

coefficient value

Return type:

complex

load(self, unicode fileName, encoding) void
load(self, str fileName, encoding) None

Load the polynomial from a file.

Parameters:
  • fileName – (str) Valid file where the polynomial is retrieved from.

  • encoding – (str, type, int, scheme_t) One of the following: * (‘int’, ‘integer’, int, 1, scheme_t.INTEGER) -> integer encoding. * (‘float’, ‘double’, float, 2, scheme_t.FRACTIONAL) -> fractional encoding.

Returns:

None

See also

to_scheme_t()

save(self, unicode fileName) void
save(str fileName) None

Save the polynomial into a file. The file can new one or exist already, in which case it will be overwriten.

Parameters:

fileName – (str) File where the polynomial will be stored.

Returns:

None

set_coeff(self, cy_complex coeff, size_t i) void

Sets the given complex value as coefficient in position i.

Parameters:

coeff (complex) – new coefficient value

Returns:

None

to_bytes(self) bytes
to_bytes() None

Serialize the polynomial into a binary/bytes string.

Returns:

serialized polynomial

Return type:

bytes

to_coeff_list(self) vector[cy_complex]

List of complex coefficients of the polynomial

_pyfhel

A pyfhel instance, used for operations

_scheme

returns the scheme type.

Can be set to: 0-None, 1-BFV, 2-CKKS, 3-BGV.

See also

to_scheme_t()

Type:

_scheme