weighted_sum
Engine.weighted_sum(ciphertexts, weights)
- Computes a weighted weighted_sum of ciphertexts using given weights.
It evaluate \(a_0 + a_1x_1 + a_2x_2 + \cdots + a_nx_n\) for given ciphertexts \([x_1, x_2, \dots, x_n]\) and given weights \([a_0, a_1, \dots, a_n]\).
- Input:
- ciphertexts: an array of Ciphertexts
- weights: an array of int or double
- Output:
from liberate import Engine
engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
message1 = [1, 2, 3]
message2 = [4, 5, 6]
ciphertext1 = engine.encrypt(message1, public_key)
ciphertext2 = engine.encrypt(message2, public_key)
cipherexts = [ciphertext1, ciphertext2]
weights = [7, 8, 9]
weighted_sum = engine.weighted_sum(ciphertexts, weights)