sum

Engine.sum(ciphertext, roll_key, axis)
입력 암호문을 지정된 축을 기준으로 합 연산을 수행한 암호문을 반환합니다. 부트스트랩용으로 생성된 엔진이 아니면서 최대 레벨인 경우에만 레벨을 소모합니다.
  • 인풋:
    • Ciphertext
    • RollKey
      • 0-축 의 경우에는 RollKey가 필요하지 않습니다.
    • Axis: int | None
      • 합 연산을 수행할 축입니다. 전달하지 않을 경우 모든 값의 총합이 모든 슬롯에 기입됩니다.
  • 아웃풋:
    • Ciphertext
      • 합의 값들이 모든 슬롯에 저장되어있습니다.
      • 암호문의 길이가 1로 줄어듭니다.

Warning

  • 행렬 엔진은 이 연산을 아직 지원하지 않습니다.

Examples

모든 축에 대한 합 연산

from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
roll_key = engine.create_roll_key(secret_key)

message_4 = [1, 2, 3, 4]
ciphertext_4 = engine.encrypt(message_4, secret_key)

# ciphertext_4의 내부:
# [[1, 2, 3, 4]]

sum_of_ciphertext_4 = engine.sum(ciphertext_4, roll_key)

# sum_of_ciphertext_4의 내부:
# [[10, 10, 10, 10]]

message_8 = [1, 2, 3, 4, 5, 6, 7, 8]
ciphertext_8 = engine.encrypt(message_8, secret_key)

# ciphertext_8의 내부:
# [[1, 2, 3, 4],
#  [5, 6, 7, 8]]

sum_of_ciphertext_8 = engine.sum(ciphertext_8, roll_key)

# sum_of_ciphertext_8의 내부:
# [[36, 36, 36, 36]]

0-축에 대한 합 연산

from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
roll_key = engine.create_roll_key(secret_key)

message_4 = [1, 2, 3, 4]
ciphertext_4 = engine.encrypt(message_4, secret_key)

# ciphertext_4의 내부:
# [[1, 2, 3, 4]]

sum_of_ciphertext_4 = engine.sum(ciphertext_4, roll_key, axis=0)

# sum_of_ciphertext_4의 내부:
# [[1, 2, 3, 4]]

message_8 = [1, 2, 3, 4, 5, 6, 7, 8]
ciphertext_8 = engine.encrypt(message_8, secret_key)

# ciphertext_8의 내부:
# [[1, 2, 3, 4],
#  [5, 6, 7, 8]]

sum_of_ciphertext_8 = engine.sum(ciphertext_8, roll_key, axis=0)

# sum_of_ciphertext_8의 내부:
# [[6, 8, 10, 12]]

1-축에 대한 합 연산

from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
roll_key = engine.create_roll_key(secret_key)

message_4 = [1, 2, 3, 4]
ciphertext_4 = engine.encrypt(message_4, secret_key)

# ciphertext_4의 내부:
# [[1, 2, 3, 4]]

sum_of_ciphertext_4 = engine.sum(ciphertext_4, roll_key, axis=1)

# sum_of_ciphertext_4의 내부:
# [[10, 10, 10, 10]]

message_8 = [1, 2, 3, 4, 5, 6, 7, 8]
ciphertext_8 = engine.encrypt(message_8, secret_key)

# ciphertext_8의 내부:
# [[1, 2, 3, 4],
#  [5, 6, 7, 8]]

sum_of_ciphertext_8 = engine.sum(ciphertext_8, roll_key, axis=1)

# sum_of_ciphertext_8의 내부:
# [[10, 10, 10, 10],
#  [26, 26, 26, 26]]

Engine.sum(ciphertext, evaluation_key, axis)
연산 키에 포함된 순환 키를 사용하여, 입력 암호문을 지정된 축을 기준으로 합 연산을 수행한 암호문을 반환합니다. 부트스트랩용으로 생성된 엔진이 아니면서 최대 레벨인 경우에만 레벨을 소모합니다.
  • 인풋:
    • Ciphertext
    • EvaluationKey
    • Axis: int | None
      • 합 연산을 수행할 축입니다. 전달하지 않을 경우 모든 값의 총합이 모든 슬롯에 기입됩니다.
  • 아웃풋:
    • Ciphertext
      • 합의 값들이 모든 슬롯에 저장되어있습니다.
      • 암호문의 길이가 1로 줄어듭니다.

Warning

  • 행렬 엔진은 이 연산을 아직 지원하지 않습니다.
from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
evaluation_key = engine.create_evaluation_key(secret_key)

message_4 = [1, 2, 3, 4]
ciphertext_4 = engine.encrypt(message_4, secret_key)

# ciphertext_4의 내부:
# [[1, 2, 3, 4]]

sum_of_ciphertext_4 = engine.sum(ciphertext_4, evaluation_key)

# sum_of_ciphertext_4의 내부:
# [[10, 10, 10, 10]]