PyPtxt¶
- class Pyfhel.PyPtxt(PyPtxt copy_ptxt=None, Pyfhel pyfhel=None, fileName=None, bytestring=None, scheme=None)¶
Bases:
object
Plaintext 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
()Decodes itself using _pyfhel.
encode
()Encodes the given value using _pyfhel.
from_bytes
(-> void)Recover the serialized plaintext from a binary/bytes string.
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
(-> void)Load the plaintext from a file.
save
(-> void)Save the plaintext into a file.
set_scale
(-> void)Sets the scale of the ciphertext.
to_bytes
(-> bytes)Serialize the plaintext into a binary/bytes string.
to_poly_string
(self)str: Polynomial representation of the plaintext
Attributes
mod_level
returns the number of moduli consumed so far.
scale
multiplying factor to encode values in ckks.
scale_bits
number of bits in scale to encode values in ckks
scheme
returns the scheme type.
API description
- __repr__()¶
Return repr(self).
- from_bytes(self, bytes content, scheme=None) void ¶
- from_bytes(bytes content) None
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, unicode fileName, scheme=None) void ¶
- load(self, str fileName, scheme) None
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, unicode fileName, unicode compr_mode=u'zstd') void ¶
- save(str fileName) None
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) None
Sets the scale of the ciphertext.
- Parameters:
scale (double) – new scale of the ciphertext.
- to_bytes(self, unicode compr_mode=u'none') bytes ¶
- to_bytes() None
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