subtract
Engine.subtract(x, y)
- Returns a ciphertext that represents the result of subtracting 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 scalar is subtracted from every value of the other input.
- At least one of the inputs must be a ciphertext.
- Output:
- ciphertext
Examples
Subtraction between 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)
subtracted = engine.subtract(ciphertext1, ciphertext2)
Subtraction of a message from a ciphertext
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)
subtracted1 = engine.subtract(ciphertext1, message2)
subtracted2 = engine.subtract(message1, ciphertext2)
Subtraction of a scalar from a ciphertext
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(message, public_key)
subtracted1 = engine.subtract(ciphertext, 2)
subtracted2 = engine.subtract(2, ciphertext)
Subtraction of a plaintext from a ciphertext
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)
subtracted1 = engine.subtract(ciphertext1, plaintext2)
subtracted2 = engine.subtract(plaintext1, ciphertext2)