encrypt

Encryption with Python Data

Engine.encrypt(message, public_key, level)
Directly encrypts a list or numpy array. The maximum size that can be encrypted is determined by Engine.slot_count. Messages exceeding this size will raise an error. Shorter messages are padded with zeros before encryption.
  • Input:
    • data: A Python list, numpy array, or plaintext. Supported data types include int, double, and complex double.
    • SecretKey
    • level: optional
      • Specifies the desired multiplication level. Lower levels reduce space usage but also reduce the maximum multiplication depth.
  • Output:
    • Plaintext
from desilofhe import Engine

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

message = [1, 2, 3]
ciphertext = engine.encrypt(message, public_key)
from desilofhe import Engine

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

message = [1, 2, 3]
ciphertext = engine.encrypt(message, public_key, level=3)

Encryption with Plaintext

Engine.encrypt(plaintext, public_key)
Encrypts an already encoded plaintext. The ciphertext's maximum multiplication depth will match the specified level of the plaintext.
  • Input:
    • Plaintext
    • SecretKey
  • Output:
    • Ciphertext
from desilofhe import Engine

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

message = [1, 2, 3]
plaintext = engine.encode(message)
ciphertext = engine.encrypt(encoded, public_key)

Using an API that combines encoding and encryption is generally faster. This function is recommended when you need to encrypt the same message multiple times or when the message is pre-encoded for other purposes.