matrix_multiply

Engine.matrix_multiply(x, y, matrix_multiplication_key)
Returns the ciphertext resulting from the matrix multiplication of two inputs. Consumes a level.
  • Input:
    • x: Plaintext or Ciphertext
    • y: Plaintext or Ciphertext
    • One of the inputs must be a Ciphertext.
    • MatrixMultiplicationKey
  • Output:
    • Ciphertext

Warning

  • The vector form does not support this operation.

Examples

Matrix multiplication of two ciphertexts

import numpy as np
from desilofhe import Engine

engine = Engine(form="matrix")
secret_key = engine.create_secret_key()
matrix_multiplication_key = engine.create_matrix_multiplication_key(secret_key)

message1 = np.ones(engine.shape)
ciphertext1 = engine.encrypt(message1, secret_key)

message2 = np.ones(engine.shape)
ciphertext2 = engine.encrypt(message2, secret_key)

multiplied = engine.matrix_multiply(
    ciphertext1, ciphertext2, matrix_multiplication_key
)

Matrix multiplication of a ciphertext and a plaintext

import numpy as np
from desilofhe import Engine

engine = Engine(form="matrix")
secret_key = engine.create_secret_key()
matrix_multiplication_key = engine.create_matrix_multiplication_key(secret_key)

message1 = np.ones(engine.shape)
ciphertext1 = engine.encrypt(message1, secret_key)

message2 = np.ones(engine.shape)
plaintext2 = engine.encode(message2)

multiplied = engine.matrix_multiply(
    ciphertext1, plaintext2, matrix_multiplication_key
)

Matrix multiplication of a plaintext and a ciphertext

import numpy as np
from desilofhe import Engine

engine = Engine(form="matrix")
secret_key = engine.create_secret_key()
matrix_multiplication_key = engine.create_matrix_multiplication_key(secret_key)

message1 = np.ones(engine.shape)
plaintext1 = engine.encode(message1)

message2 = np.ones(engine.shape)
ciphertext2 = engine.encrypt(message2, secret_key)

multiplied = engine.matrix_multiply(
    plaintext1, ciphertext2, matrix_multiplication_key
)