add
Engine.add(x, y)
- Returns a ciphertext that is the sum of the two inputs. Does not consume any level.
- Input:
- x: int, double, complex double, array_like, Plaintext, or Ciphertext
- y: int, double, complex double, array_like, Plaintext, or Ciphertext
- out: optional Ciphertext
- If
out
is provided, the operation is performed in-place on theout
ciphertext, which must be eitherx
ory
. - This is only supported when both
x
andy
are Ciphertexts
- If
- If one of the inputs is a scalar, its value is added to every element of the other input.
- At least one of the inputs must be a Ciphertext.
- Input:
- Ciphertext
Examples
Addition of two ciphertexts
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)
added = engine.add(ciphertext1, ciphertext2)
Addition 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)
added1 = engine.add(ciphertext1, message2)
added2 = engine.add(message1, ciphertext2)
Addition 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)
message1 = [1, 2, 3]
ciphertext1 = engine.encrypt(message1, public_key)
message2 = [4, 5, 6]
ciphertext2 = engine.encrypt(message2, public_key)
added1 = engine.add(ciphertext1, 2)
added2 = engine.add(2, ciphertext2)
Addition 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)
added1 = engine.add(ciphertext1, plaintext2)
added2 = engine.add(plaintext1, ciphertext2)
Addition of two ciphertexts in-place
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)
engine.add(ciphertext1, ciphertext2, out=ciphertext1)
decrypted = engine.decrypt(ciphertext1, secret_key) # [5, 7, 9]
Addition of two ciphertexts in-place with return
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)
ciphertext1 = engine.add(ciphertext1, ciphertext2, out=ciphertext1)
decrypted = engine.decrypt(ciphertext1, secret_key) # [5, 7, 9]