CTile#

class CTile#

A class representing a ciphertext.

It’s called a CTile because from a high-level point of view we’ll usually use several of these combined for holding a more complicated object such as a matrix. For a lower level documentation of different functionalities (such as the effect on chainIndex), see documentation of the underlying encryption scheme.

add(self: pyhelayers.CTile, other: pyhelayers.CTile) None#

Add content of another ciphertext to this one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use add_raw() to get the scheme’s raw addition operation.

Parameters:

other – Other ciphertext to add.

add_plain(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

Add content of another PTile to this one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use add_plain_raw() to get the scheme’s raw addition operation.

Parameters:

other – Other PTile to add.

add_plain_raw(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

See add_plain().

Parameters:

other – Other PTile to add.

add_raw(self: pyhelayers.CTile, other: pyhelayers.CTile) None#

See add().

Parameters:

other – Other ciphertext to add.

add_scalar(*args, **kwargs)#

Overloaded function.

  1. add_scalar(self: pyhelayers.CTile, scalar: float) -> None

    Adds a double scalar value to all slots in this ciphertext.

    param scalar:

    value to add.

    type scalar:

    float

  2. add_scalar(self: pyhelayers.CTile, scalar: int) -> None

    Adds an integer scalar value to all slots in this ciphertext.

    param scalar:

    integer value to add.

    type scalar:

    int

add_tile(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

Calls add(CTile) or add_plain(PTile) depending on argument type.

Parameters:

other – Other object to add.

add_tile_raw(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

See add_tile().

Parameters:

other – Other object to add.

conjugate(self: pyhelayers.CTile) None#

Conjugates contents of this CTile in place, elementwise. For non-complex numbers this has no effect. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use conjugate_raw() to get the scheme’s raw conjugate operation.

conjugate_raw(self: pyhelayers.CTile) None#

See conjugate().

get_current_device(self: pyhelayers.CTile) pyhelayers.DeviceType#

Returns the current device of this CTile.

Return type:

DeviceType

get_multiply(self: pyhelayers.CTile, other: pyhelayers.CTile) pyhelayers.CTile#

Returns the result of multiplication of this and other CTile. Relies on CTile::multiply().

Parameters:

other – Other ciphertext to multiply.

inner_sum(self: pyhelayers.CTile, rot1: int, rot2: int, reverse: bool = False) None#

Computes the inner sum of some of the ciphertext’s slots. Performs the computation by repeated rotations and additions, with rotations rot1, 2*rot1, 4*rot2, up to rot2 (exclusive). Using this method properly is complicated, and is used by some higher level algorithms.

Parameters:
  • rot1 – First rotation in the rotate-and-add loop.

  • rot2 (int) – Last rotation (exclusive) in the rotate-and-add loop.

  • reverse (bool) – If true, flips all rotations (left to right and vice versa). Defaults to false.

is_empty(self: pyhelayers.CTile) bool#

Returns true if this CTile does not include an encryption of any value, and false otherwise.

multiply(self: pyhelayers.CTile, other: pyhelayers.CTile) None#

Multiply another ciphertext with this one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use multiplyRaw() to get the scheme’s raw addition operation.

Parameters:

other – Other ciphertext to multiply.

multiply_by_chainging_scale(self: pyhelayers.CTile, factor: float) None#

Multiply this ciphertext by a scalar double value, elementwise, by a light-weight scale changing. This multiplies every slot by the given factor. The operation is done by changing the scale meta-data combined with this ciphertext, and is therefore extermely fast. It is not available for all underlying schemes, and also may cause difficulties down the line due to mismatching scales.

Parameters:

factor (float) – factor to multiply with.

Raises:

RuntimeError – If not supported.

multiply_imaginary_unit(self: pyhelayers.CTile) None#

Multiplies all slots in this ciphertext with the imaginary unit (i).

multiply_plain(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

Multiply the content this PTile by another one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use multiply_plain_raw() to get the scheme’s raw multiplication operation.

Parameters:

other – Other PTile to multiply.

multiply_plain_raw(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

See multiply_plain().

Parameters:

other – Other PTile to multiply.

multiply_raw(self: pyhelayers.CTile, other: pyhelayers.CTile) None#

See multiply().

Parameters:

other – Other ciphertext to multiply.

multiply_scalar(*args, **kwargs)#

Overloaded function.

  1. multiply_scalar(self: pyhelayers.CTile, scalar: int) -> None

    Multiplies all slots in this ciphertext with an integer scalar value.

    param scalar:

    integer value to multiply.

    type scalar:

    int

  2. multiply_scalar(self: pyhelayers.CTile, scalar: float) -> None

    Multiplies all slots in this ciphertext with a double scalar value.

    param scalar:

    value to multiply.

    type scalar:

    float

multiply_tile(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

Calls multiply(CTile) or multiply_plain(PTile) depending on argument type.

Parameters:

other – Other object to multiply.

multiply_tile_raw(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

See multiply_tile().

Parameters:

other – Other object to multiply.

negate(self: pyhelayers.CTile) None#

Negates content of this ciphertext.

nullify_imaginary_part(self: pyhelayers.CTile) None#

Nullify the imaginary part of each slot in this ciphertext.

relinearize(self: pyhelayers.CTile) None#

Performs a relinearize operation (reducing ciphertext size after multiplication) The non-raw version of multiplication takes care of this automatically when needed. Ignored if not needed or not supported.

rescale(self: pyhelayers.CTile) None#

Performs a rescale operation (reducing ciphertext modulus bits and attached meta data scale). The non-raw version of multiplication takes care of this automatically. Ignored if not needed or not supported. Note that depending on scheme, this method may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use rescale_raw() to get the scheme’s raw rescale operation.

rescale_raw(self: pyhelayers.CTile) None#

See rescale().

rotate(self: pyhelayers.CTile, n: int) None#

Rotate left. For an offset of n, the element at slots 10 will move to slot 10-n. The first n elements are rotated back to be last.

Parameters:

n – Rotate offset.

square(self: pyhelayers.CTile) None#

squares contents of this CTile in place, elementwise. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use square_raw() to get the scheme’s raw square operation.

square_raw(self: pyhelayers.CTile) None#

See square().

sub(self: pyhelayers.CTile, other: pyhelayers.CTile) None#

Subtract the content of another CTile from this one, element-wise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use sub_raw() to get the scheme’s raw subtraction operation.

Parameters:

other – Other ciphertext to sub.

sub_plain(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

sub content of another PTile to this one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use sub_plain_raw() to get the scheme’s raw subtraction operation.

Parameters:

other – Other PTile to sub.

sub_plain_raw(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

See sub_plain().

Parameters:

other – Other PTile to sub.

sub_raw(self: pyhelayers.CTile, other: pyhelayers.CTile) None#

See sub().

Parameters:

other – Other ciphertext to sub.

sub_tile(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

Calls sub(CTile) or sub_plain(PTile) depending on argument type.

Parameters:

other – Other object to subtract.

sub_tile_raw(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

See sub_tile().

Parameters:

other – Other object to subtract.

sum_exp_by_squaring_left_to_right(self: pyhelayers.CTile, n: int) None#

Sums n slots of this ciphertext. After summing, slot i will contain the sum of slots i, i+1, i+2, …, i+n-1, where indices are cyclic, i.e., roll back to the start if run out over the edge. Summation is done similar to left-to-right repeated squaring algorithm.

Parameters:

n – number of elements to summarize.

sum_exp_by_squaring_right_to_left(self: pyhelayers.CTile, n: int) None#

Sums n slots of this ciphertext. After summing, slot i will contain the sum of slots i, i+1, i+2, …, i+n-1, where indices are cyclic, i.e., roll back to the start if run out over the edge. Summation is done similar to right-to-left repeated squaring algorithm.

Parameters:

n – number of elements to summarize.

to_device(self: pyhelayers.CTile, device: pyhelayers.DeviceType) None#

Move this CTile to another device.

Parameters:

device – The device type to move to.