subtract

GLEngine.subtract(x, y)
Returns a ciphertext that represents the result of subtracting two inputs. Does not consume any level.
  • Input:
    • x: 3D array of double or complex double, GLPlaintext, or GLCiphertext
    • y: 3D array of double or complex double, GLPlaintext, or GLCiphertext
    • At least one of the inputs must be a GLCiphertext.
  • Output:
    • GLCiphertext

Examples

Subtraction between two ciphertexts

import numpy as np

from desilofhe import GLEngine

engine = GLEngine()
shape = engine.shape
secret_key = engine.create_secret_key()

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

message2 = np.ones(shape, dtype=np.float64) * 2
ciphertext2 = engine.encrypt(message2, secret_key)

subtracted = engine.subtract(ciphertext1, ciphertext2)

Subtraction of a 3d matrix from a ciphertext

import numpy as np

from desilofhe import GLEngine

engine = GLEngine()
shape = engine.shape
secret_key = engine.create_secret_key()

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

message2 = np.ones(shape, dtype=np.float64) * 2
ciphertext2 = engine.encrypt(message2, secret_key)

subtracted1 = engine.subtract(ciphertext1, message2)
subtracted2 = engine.subtract(message1, ciphertext2)

Subtraction of a plaintext from a ciphertext

import numpy as np

from desilofhe import GLEngine

engine = GLEngine()
shape = engine.shape
secret_key = engine.create_secret_key()

message1 = np.ones(shape, dtype=np.float64)
plaintext1 = engine.encode(message1)
ciphertext1 = engine.encrypt(plaintext1, secret_key)

message2 = np.ones(shape, dtype=np.float64) * 2
plaintext2 = engine.encode(message2)
ciphertext2 = engine.encrypt(plaintext2, secret_key)

subtracted1 = engine.subtract(ciphertext1, plaintext2)
subtracted2 = engine.subtract(plaintext1, ciphertext2)