rotate
Fixed Rotation Key-Based Rotation
Engine.rotate(ciphertext, fixed_rotation_key)- Rotates the input ciphertext to the left by the delta value specified in the fixed rotation key.
For example, rotating
[1, 2, 3, 4]by 1 results in[2, 3, 4, 1]. In general, does not consume any level. A level is consumed only if the engine is not configured for bootstrapping and the ciphertext is at the maximum allowable level for a given parameter.
- Input:
CiphertextFixedRotationKey
- Output:
Ciphertext
Warning
- The matrix form does not support this operation.
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 only allow rotation by a specific delta value. 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 left by the specified delta value.
For example, rotating
[1, 2, 3, 4]by 1 results in[2, 3, 4, 1]. In general, does not consume any level. A level is consumed only if the engine is not configured for bootstrapping and the ciphertext is at the maximum allowable level for a given parameter.
- Input:
CiphertextRotationKey- delta:
int
- Output:
Ciphertext
Warning
- The matrix form does not support this operation.
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 fixed rotation keys with \(2^n\) deltas. When rotating with a delta that is not a power of 2, multiple rotations each with a power of two delta are done internally. If many different rotations are needed, general rotation keys are more efficient. For frequent rotations by specific deltas, generating a fixed rotation key for that value is more optimal.
Bootstrap Key-Based Rotation
Engine.rotate(ciphertext, bootstrap_key, delta)- Rotates the input ciphertext to the left by the specified delta value, using the fixed roll keys contained in the bootstrap key.
For example, rotating
[1, 2, 3, 4]by 1 results in[2, 3, 4, 1]. The engine must be created withEngine(bootstrap=True).
- Input:
CiphertextBootstrapKey- delta:
int
- Output:
Ciphertext
Warning
- The matrix form does not support this operation.
from desilofhe import Engine
engine = Engine(bootstrap=True)
secret_key = engine.create_secret_key()
bootstrap_key = engine.create_bootstrap_key(secret_key)
message = [1, 2, 3]
ciphertext = engine.encrypt(message, secret_key)
rotated_ciphertext = engine.rotate(ciphertext, bootstrap_key, delta=1)
Evaluation Key-Based Rotation
Engine.rotate(ciphertext, evaluation_key, delta)- Rotates the input ciphertext to the left by the specified delta value, using the keys bundled in the evaluation key.
For example, rotating
[1, 2, 3, 4]by 1 results in[2, 3, 4, 1]. In general, does not consume any level. A level is consumed only if the engine is not configured for bootstrapping and the ciphertext is at the maximum allowable level for a given parameter.
- Input:
CiphertextEvaluationKey- delta:
int
- Output:
Ciphertext
Warning
- The matrix form does not support this operation.
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
evaluation_key = engine.create_evaluation_key(secret_key)
message = [1, 2, 3]
ciphertext = engine.encrypt(message, secret_key)
rotated_ciphertext = engine.rotate(ciphertext, evaluation_key, delta=1)
Plaintext Rotation
Engine.rotate(plaintext, delta)- Rotates the input plaintext to the left by the specified delta value.
For example, rotating
[1, 2, 3, 4]by 1 results in[2, 3, 4, 1].
Warning
- The matrix form does not support this operation.
- Input:
Plaintext- delta:
int
- Output:
Plaintext