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]
. In general, does not consume any level. A level is consumed only if the operation is not a multiparty computation and the ciphertext is at the maximum allowable level for a given parameter.
- 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.
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]
. In general, does not consume any level. A level is consumed only if the operation is not a multiparty computation and the ciphertext is at the maximum allowable level for a given parameter.
- 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.
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