roll

Ciphertext Roll

Engine.roll(ciphertext, roll_key, shift, axis=None)
Rolls the input ciphertext to the right by the specified shift value. For example, rolling [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 engine is not configured for bootstrapping and the ciphertext is at the maximum allowable level for a given parameter.
  • Input:
    • Ciphertext
    • RollKey
    • shift: int
    • axis: int, optional
      • For the vector form, it must be None.
      • For the matrix form, it is the axis to roll along: 0 (batch), 1 (row), or 2 (column).
  • Output:
    • Ciphertext
from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
roll_key = engine.create_roll_key(secret_key)

message = [1, 2, 3]
ciphertext = engine.encrypt(message, public_key)
rolled_ciphertext = engine.roll(ciphertext, roll_key, shift=1)
import numpy as np
from desilofhe import Engine

engine = Engine(form="matrix")
secret_key = engine.create_secret_key()
roll_key = engine.create_roll_key(secret_key)

message = np.arange(np.prod(engine.shape)).reshape(engine.shape)
ciphertext = engine.encrypt(message, secret_key)
batch_rolled = engine.roll(ciphertext, roll_key, shift=1, axis=0)
row_rolled = engine.roll(ciphertext, roll_key, shift=1, axis=1)
column_rolled = engine.roll(ciphertext, roll_key, shift=1, axis=2)
Engine.roll(ciphertext, fixed_roll_key)
Rolls the input ciphertext by the shift value and along the axis of the fixed roll key. 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:
    • Ciphertext
    • FixedRollKey
  • Output:
    • Ciphertext
from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
fixed_roll_key = engine.create_fixed_roll_key(secret_key, shift=1)

message = [1, 2, 3]
ciphertext = engine.encrypt(message, secret_key)
rolled_ciphertext = engine.roll(ciphertext, fixed_roll_key)
Engine.roll(ciphertext, shift, axis)
Rolls the input ciphertext of the matrix form along the column axis without a key. Only axis=2 is supported.
  • Input:
    • Ciphertext
    • shift: int
    • axis: int
      • Must be 2 (column).
  • Output:
    • Ciphertext

Warning

  • The vector form does not support this operation.
import numpy as np
from desilofhe import Engine

engine = Engine(form="matrix")
secret_key = engine.create_secret_key()

message = np.arange(np.prod(engine.shape)).reshape(engine.shape)
ciphertext = engine.encrypt(message, secret_key)
column_rolled = engine.roll(ciphertext, shift=1, axis=2)
Engine.roll(ciphertext, bootstrap_key, shift, axis=None)
Rolls the input ciphertext to the right by the specified shift value, using the fixed roll keys contained in the bootstrap key. The engine must be created with Engine(bootstrap=True). For example, rolling [1, 2, 3, 4] by 1 results in [4, 1, 2, 3].
  • Input:
    • Ciphertext
    • BootstrapKey
    • shift: int
    • axis: None, optional
  • Output:
    • Ciphertext

Warning

  • The matrix form does not yet 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)
rolled_ciphertext = engine.roll(ciphertext, bootstrap_key, shift=1)
Engine.roll(ciphertext, evaluation_key, shift, axis=None)
Rolls the input ciphertext to the right by the specified shift value, using the roll key bundled in the evaluation key. For example, rolling [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 engine is not configured for bootstrapping and the ciphertext is at the maximum allowable level for a given parameter.
  • Input:
    • Ciphertext
    • EvaluationKey
    • shift: int
    • axis: None, optional
  • Output:
    • Ciphertext

Warning

  • The matrix form does not yet support this operation.
from desilofhe import Engine

engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
evaluation_key = engine.create_evaluation_key(secret_key)

message = [1, 2, 3]
ciphertext = engine.encrypt(message, public_key)
rolled_ciphertext = engine.roll(ciphertext, evaluation_key, shift=1)

Plaintext Roll

Engine.roll(plaintext, shift, axis=None)
Rolls the input plaintext to the right by the specified shift value. For example, rolling [1, 2, 3, 4] by 1 results in [4, 1, 2, 3].
  • Input:
    • Plaintext
    • shift: int
    • axis: None, optional
  • Output:
    • Plaintext

Warning

  • The matrix form does not yet support this operation.
from desilofhe import Engine

engine = Engine()

message = [1, 2, 3]
plaintext = engine.encode(message)
rolled_plaintext = engine.roll(plaintext, shift=1)