multiply

Engine.multiply(x, y, relinearization_key)
Returns the ciphertext resulting from the multiplication of two inputs.
  • Input:
    • x: int, double, complex double, array_like, Plaintext, or Ciphertext
    • y: int, double, complex double, array_like, Plaintext, or Ciphertext
    • If either input is a scalar, the same value is multiplied across all elements of the other input.
    • One of the inputs must be a ciphertext.
    • RelinearizationKey, optional
      • If provided, the resulting ciphertext undergoes relinearization. This is recommended to facilitate subsequent operations.
      • If one of the inputs is a constant, a relinearization key is not required.
  • Output:
    • Ciphertext

Examples

Multiplication of two ciphertexts

from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
relinearization_key = engine.create_relinearization_key(secret_key)

message1 = [1, 2, 3]
ciphertext1 = engine.encrypt(message1, public_key)

message2 = [4, 5, 6]
ciphertext2 = engine.encrypt(message2, public_key)

multiplied = engine.multiply(ciphertext1, ciphertext2, relinearization_key)

Multiplication of a ciphertext and a list

from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)

message1 = [1, 2, 3]
ciphertext1 = engine.encrypt(message1, public_key)

message2 = [4, 5, 6]
ciphertext2 = engine.encrypt(message2, public_key)

multiplied1 = engine.multiply(ciphertext1, message2)
multiplied2 = engine.multiply(message1, ciphertext2)

Multiplication of a ciphertext and a scalar

from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)

message = [1, 2, 3]
ciphertext = engine.encrypt(plaintext, public_key)

multiplied1 = engine.multiply(ciphertext, 2)
multiplied2 = engine.multiply(2, ciphertext)

Multiplication of a ciphertext and a plaintext

from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)

message1 = [1, 2, 3]
plaintext1 = engine.encode(message1)
ciphertext1 = engine.encrypt(plaintext1, public_key)

message2 = [4, 5, 6]
plaintext2 = engine.encode(message2)
ciphertext2 = engine.encrypt(plaintext2, public_key)

multiplied1 = engine.multiply(ciphertext1, plaintext2)
multiplied2 = engine.multiply(plaintext1, ciphertext2)

Even without relinearization, addition, subtraction, and decryption are still possible. However, when performing addition or subtraction between ciphertexts, their dimensions must match.