rotate

고정 회전 키를 통한 회전

Engine.rotate(ciphertext, fixed_rotation_key)
암호문을 고정 회전 키의 지정된 delta 만큼 오른쪽으로 회전시켜서 반환합니다. [1, 2, 3, 4] 를 1만큼 회전시키면 [4, 1, 2, 3] 이 됩니다.
  • 인풋:
    • Ciphertext
    • FixedRotationKey
  • 아웃풋:
    • Ciphertext
from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
fixed_rotation_key = engine.create_fixed_rotation_key(secret_key, delta=1)

message = [1, 2, 3]
ciphertext = engine.encrypt(message, public_key)
rotated_ciphertext = engine.rotate(ciphertext, fixed_rotation_key)

고정 회전 키의 지정된 델타만큼만 회전이 가능하기 때문에, 다양한 회전이 필요하다면 1짜리의 고정 회전 키로 회전을 여러번 하는 것 보다는 회전 키를 사용한 회전을 하는 것이 효율적입니다. 하지만 회전 키는 \(2^n\)이 아닌 회전의 경우 내부적으로 여러번 회전을 해야하기 때문에 특정한 값의 회전을 자주 행해야 한다면 해당 값의 고정 회전 키를 생성하는 것이 효율적입니다.

일반적으로는 암호문의 레벨을 소모하지 않지만, 암호문의 레벨이 각 파라미터 설정의 최대 레벨의 경우 레벨이 하나 사용됩니다.

회전 키를 통한 회전

Engine.rotate(ciphertext, rotation_key, delta)
암호문을 지정된 delta 만큼 오른쪽으로 회전시켜서 반환합니다. [1, 2, 3, 4] 를 1만큼 회전시키면 [4, 1, 2, 3] 이 됩니다.
  • 인풋:
    • Ciphertext
    • RotationKey
    • delta: int
  • 아웃풋:
    • Ciphertext
from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
rotation_key = engine.create_rotation_key(secret_key)

message = [1, 2, 3]
ciphertext = engine.encrypt(message, public_key)
rotated_ciphertext = engine.rotate(ciphertext, rotation_key, delta=1)

회전 키는 \(2^n\)의 키들로 구성이 되어있고, 델타값이 \(2^n\)이 아닌 경우에는 해당 델타값의 회전을 달성하기 위해서 내부적으로 여러번 회전을 합니다. 여러가지 다양한 회전을 해야하는 경우에는 회전 키를 사용하는 것이 효율적이고, 특정한 값의 회전을 자주 행해야 한다면 해당 값의 회전 키를 생성하는 것이 효율적입니다.

일반적으로는 암호문의 레벨을 소모하지 않지만, 암호문의 레벨이 각 파라미터 설정의 최대 레벨의 경우 레벨이 하나 사용됩니다.

인코딩된 평문의 회전

Engine.rotate(plaintext, delta)
인코딩된 평문을 지정된 delta 만큼 오른쪽으로 회전시켜서 반환합니다.
  • 인풋:
    • Plaintext
    • delta: int
  • 아웃풋:
    • Plaintext
from desilofhe import Engine

engine = Engine()

message = [1, 2, 3]
plaintext = engine.encode(message)
rotated_plaintext = engine.rotate(plaintext, delta=1)