sum
Engine.sum(ciphertext, roll_key, axis)- 입력 암호문을 지정된 축을 기준으로 합 연산을 수행한 암호문을 반환합니다. 부트스트랩용으로 생성된 엔진이 아니면서 최대 레벨인 경우에만 레벨을 소모합니다.
- 인풋:
CiphertextRollKey- 0-축 의 경우에는 RollKey가 필요하지 않습니다.
- axis:
int, optional- 합 연산을 수행할 축입니다. 전달하지 않을 경우 모든 값의 총합이 모든 슬롯에 기입됩니다.
- 아웃풋:
Ciphertext- 암호문의 각 행은
Engine.slot_count개의 슬롯을 가집니다. - axis=None이면 전체 합이 한 행의 모든 슬롯에 저장됩니다.
- axis=0이면 각 행을 슬롯별로 더한 한 행이 됩니다.
- axis=1이면 각 행의 합이 그 행의 모든 슬롯에 저장되며, 행의 수는 그대로입니다.
- 암호문의 각 행은
Warning
- 행렬 엔진은 이 연산을 아직 지원하지 않습니다.
예시
모든 축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
roll_key = engine.create_roll_key(secret_key)
slot_count = engine.slot_count # 8192
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (8192)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, roll_key)
# summed의 내부:
# [[24576, 24576, ..., 24576]]
0-축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
roll_key = engine.create_roll_key(secret_key)
slot_count = engine.slot_count # 8192
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (8192)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, roll_key, axis=0)
# summed의 내부:
# [[3, 3, ..., 3]]
1-축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
roll_key = engine.create_roll_key(secret_key)
slot_count = engine.slot_count # 8192
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (8192)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, roll_key, axis=1)
# summed의 내부:
# [[8192, 8192, ..., 8192],
# [16384, 16384, ..., 16384]]
Engine.sum(ciphertext, axis)- 키 없이 입력 암호문의 행들을 더한 암호문을 반환합니다.
axis=0만 지원합니다.
- 인풋:
Ciphertext- axis:
int0이어야 합니다.
- 아웃풋:
Ciphertext
Warning
- 행렬 엔진은 이 연산을 아직 지원하지 않습니다.
import numpy as np
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
slot_count = engine.slot_count # 8192
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
summed = engine.sum(ciphertext, axis=0)
# [[3, 3, ..., 3]]
Engine.sum(ciphertext, evaluation_key, axis)- 연산 키에 포함된 순환 키를 사용하여, 입력 암호문을 지정된 축을 기준으로 합 연산을 수행한 암호문을 반환합니다. 부트스트랩용으로 생성된 엔진이 아니면서 최대 레벨인 경우에만 레벨을 소모합니다.
- 인풋:
CiphertextEvaluationKey- axis:
int, optional- 합 연산을 수행할 축입니다. 전달하지 않을 경우 모든 값의 총합이 모든 슬롯에 기입됩니다.
- 아웃풋:
Ciphertext- 암호문의 각 행은
Engine.slot_count개의 슬롯을 가집니다. - axis=None이면 전체 합이 한 행의 모든 슬롯에 저장됩니다.
- axis=0이면 각 행을 슬롯별로 더한 한 행이 됩니다.
- axis=1이면 각 행의 합이 그 행의 모든 슬롯에 저장되며, 행의 수는 그대로입니다.
- 암호문의 각 행은
Warning
- 행렬 엔진은 이 연산을 아직 지원하지 않습니다.
Examples
모든 축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
evaluation_key = engine.create_evaluation_key(secret_key)
slot_count = engine.slot_count # 8192
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (8192)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, evaluation_key)
# summed의 내부:
# [[24576, 24576, ..., 24576]]
0-축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
evaluation_key = engine.create_evaluation_key(secret_key)
slot_count = engine.slot_count # 8192
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (8192)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, evaluation_key, axis=0)
# summed의 내부:
# [[3, 3, ..., 3]]
1-축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
evaluation_key = engine.create_evaluation_key(secret_key)
slot_count = engine.slot_count # 8192
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (8192)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, evaluation_key, axis=1)
# summed의 내부:
# [[8192, 8192, ..., 8192],
# [16384, 16384, ..., 16384]]
Engine.sum(ciphertext, bootstrap_key, axis=None)- 부트스트랩 키에 포함된 고정 순환 키를 사용하여, 입력 암호문을 지정된 축을 기준으로 합 연산을 수행한 암호문을 반환합니다.
Engine(bootstrap=True)로 생성한 엔진에서만 사용할 수 있습니다.
- 인풋:
CiphertextBootstrapKey- axis:
int, optional- 합 연산을 수행할 축입니다. 전달하지 않을 경우 모든 값의 총합이 모든 슬롯에 기입됩니다.
- 아웃풋:
Ciphertext- 암호문의 각 행은
Engine.slot_count개의 슬롯을 가집니다. - axis=None이면 전체 합이 한 행의 모든 슬롯에 저장됩니다.
- axis=0이면 각 행을 슬롯별로 더한 한 행이 됩니다.
- axis=1이면 각 행의 합이 그 행의 모든 슬롯에 저장되며, 행의 수는 그대로입니다.
- 암호문의 각 행은
Warning
- 행렬 엔진은 이 연산을 아직 지원하지 않습니다.
Examples
모든 축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine(bootstrap=True)
secret_key = engine.create_secret_key()
bootstrap_key = engine.create_bootstrap_key(secret_key)
slot_count = engine.slot_count # 32768
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (32768)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, bootstrap_key)
# summed의 내부:
# [[98304, 98304, ..., 98304]]
0-축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine(bootstrap=True)
secret_key = engine.create_secret_key()
bootstrap_key = engine.create_bootstrap_key(secret_key)
slot_count = engine.slot_count # 32768
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (32768)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, bootstrap_key, axis=0)
# summed의 내부:
# [[3, 3, ..., 3]]
1-축에 대한 합 연산
import numpy as np
from desilofhe import Engine
engine = Engine(bootstrap=True)
secret_key = engine.create_secret_key()
bootstrap_key = engine.create_bootstrap_key(secret_key)
slot_count = engine.slot_count # 32768
message = np.repeat([1, 2], slot_count)
ciphertext = engine.encrypt(message, secret_key)
# 각 행은 engine.slot_count (32768)개의 슬롯을 가집니다
# ciphertext의 내부:
# [[1, 1, ..., 1],
# [2, 2, ..., 2]]
summed = engine.sum(ciphertext, bootstrap_key, axis=1)
# summed의 내부:
# [[32768, 32768, ..., 32768],
# [65536, 65536, ..., 65536]]