PyPtxt¶
- class Pyfhel.PyPtxt(PyPtxt copy_ptxt=None, Pyfhel pyfhel=None, fileName=None, bytestring=None, scheme=None)¶
Bases:
objectPlaintext class of Pyfhel, contains a value/vector of encoded ints/double.
This class references SEAL, PALISADE and HElib plaintexts, using the one corresponding to the backend selected in Pyfhel (SEAL by default).
- __init__(PyPtxt copy_ctxt=None, Pyfhel pyfhel=None, fileName=None, scheme=None)¶
Initializes an empty PyPtxt encoded plaintext.
- To fill the plaintext during initialization you can:
Provide a PyPtxt to deep copy.
Provide a pyfhel instance to act as its backend.
Provide a fileName and an scheme to load the data from a saved file.
- fileName¶
Load PyPtxt from this file. Requires non-empty scheme.
- Type:
str, pathlib.Path, optional
Methods
__repr__()Return repr(self).
__init__(PyPtxt copy_ctxt=None, ...[, ...])Initializes an empty PyPtxt encoded plaintext.
decode(self)decode()
encode(self, value)encode(value)
from_bytes(self, bytes content[, scheme])from_bytes(bytes content)
is_ntt_form(self)bool: Flag to quickly check if it is in NTT form
is_zero(self)bool: Flag to quickly check if it is empty
load(self, str fileName[, scheme])load(self, str fileName, scheme)
save(self, str fileName, str compr_mode=)save(str fileName)
set_scale(self, double new_scale)set_scale(double new_scale)
to_bytes(self, str compr_mode=)to_bytes()
to_poly_string(self)str: Polynomial representation of the plaintext
Attributes
mod_levelreturns the number of moduli consumed so far.
scalemultiplying factor to encode values in ckks.
scale_bitsnumber of bits in scale to encode values in ckks
schemereturns the scheme type.
API description
- __repr__()¶
Return repr(self).
- decode(self)¶
decode()
Decodes itself using _pyfhel.
See also
- encode(self, value)¶
encode(value)
Encodes the given value using _pyfhel.
See also
- from_bytes(self, bytes content, scheme=None) void¶
from_bytes(bytes content)
Recover the serialized plaintext from a binary/bytes string.
- Parameters:
content – (
bytes) Python bytes object containing the PyPtxt.scheme – (:obj: str) String or type describing the scheme: * (‘int’, ‘integer’, int, 1, scheme_t.bfv) -> integer scheme. * (‘float’, ‘double’, float, 2, scheme_t.ckks) -> fractional scheme. * (3, scheme_t.bgv) -> integer scheme.
- load(self, str fileName, scheme=None) void¶
load(self, str fileName, scheme)
Load the plaintext from a file.
- Parameters:
fileName – (str) Valid file where the plaintext is retrieved from.
- Returns:
None
See also
to_Scheme_t()
- save(self, str fileName, str compr_mode='zstd') void¶
save(str fileName)
Save the plaintext into a file. The file can new one or exist already, in which case it will be overwriten.
- Parameters:
fileName – (str) File where the plaintext will be stored.
compr_mode – (str) Compression mode. One of “none”, “zlib”, “zstd”.
- Returns:
None
- set_scale(self, double new_scale) void¶
set_scale(double new_scale)
Sets the scale of the ciphertext.
- Parameters:
scale (double) – new scale of the ciphertext.
- to_bytes(self, str compr_mode='none') bytes¶
to_bytes()
Serialize the plaintext into a binary/bytes string.
- Parameters:
compr_mode – (str) Compression mode. One of “none”, “zlib”, “zstd”
- Returns:
serialized plaintext
- Return type:
- to_poly_string(self) string¶
str: Polynomial representation of the plaintext
- _pyfhel¶
A pyfhel instance, used for operations
- mod_level¶
returns the number of moduli consumed so far.
Only usable in ckks.
- Type:
mod_level
- scale¶
multiplying factor to encode values in ckks.
- Type:
double
- scheme¶
returns the scheme type.
Can be set to: 0-none, 1-bfv, 2-ckks, 3-bgv
See also
to_Scheme_t()- Type:
scheme