rotate
Fixed Rotation Key-Based Rotation
Engine.rotate(ciphertext, fixed_rotation_key)
- Rotates the input ciphertext to the right by the delta value specified in the fixed rotation key. For example, rotating
[1, 2, 3, 4]
by 1 results in[4, 1, 2, 3]
.
- Input:
- Ciphertext
- FixedRotationKey
- Output:
- 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)
Fixed rotation keys allow rotation by a specific delta value only. If you need various rotations, using multiple rotations with fixed rotation key of delta 1 is less efficient than employing general rotation keys. However, if a specific rotation is frequently performed, generating a fixed rotation key for that value is more optimal.
The levels of the input and output ciphertexts are usually equal. However, if the level of the input ciphertext is at the maximum possible value for a given parameter set, the level of the output ciphertext is reduced by one.
Rotation Key-Based Rotation
Engine.rotate(ciphertext, rotation_key, delta)
- Rotates the input ciphertext to the right by the specified delta value. For example, rotating
[1, 2, 3, 4]
by 1 results in[4, 1, 2, 3]
.
- Input:
- Ciphertext
- RotationKey
- delta: int
- Output:
- 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)
Rotation keys are constructed using a set of \(2^n\) rotations. When the delta is not a power of 2, the rotation is achieved internally through multiple rotations. If many different rotations are needed, general rotation keys are more efficient. For frequent rotations by specific values, generating a fixed rotation key for that value is more optimal.
The levels of the input and output ciphertexts are usually equal. However, if the level of the input ciphertext is at the maximum possible value for a given parameter set, the level of the output ciphertext is reduced by one.
Plaintext Rotation
Engine.rotate(plaintext, delta)
- Rotates the input plaintext to the right by the specified delta value. For example, rotating
[1, 2, 3, 4]
by 1 results in[4, 1, 2, 3]
.
- Input:
- Plaintext
- delta: int
- Output:
- Plaintext