add

Engine.add(x, y)
두 인자를 더한 암호문을 반환합니다. 레벨을 소모하지 않습니다.
  • 인풋:
    • x: int, double, complex double, array_like, Plaintext, or Ciphertext
    • y: int, double, complex double, array_like, Plaintext, or Ciphertext
    • out: optional Ciphertext
      • out이 지정되면, 연산은 out에 대해 in-place로 수행되며 out 암호문은 x 또는 y 중 하나여야 합니다.
      • 이 기능은 xy가 모두 Ciphertext일 때만 지원됩니다.
    • 인자가 scalar이면 나머지 인자의 모든 값에 같은 값이 더해집니다.
    • 인풋 둘 중 하나는 Ciphertext여야 합니다.
  • 아웃풋:
    • 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)

added = engine.add(ciphertext1, ciphertext2)

암호문과 리스트의 덧셈

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)

암호문과 상수의 덧셈

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)

암호문과 평문간 덧셈

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)

암호문 간 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]

암호문 간 반환값이 있는 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)

ciphertext1 = engine.add(ciphertext1, ciphertext2, out=ciphertext1)

decrypted = engine.decrypt(ciphertext1, secret_key)  # [5, 7, 9]