encrypt
Encryption with Python Data
Engine.encrypt(message, secret_key, level)- Directly encrypts a list or numpy array using a secret key.
This function is not supported in multiparty computation.
The message is encrypted in segments of length
Engine.slot_count. If the message length is not divisible by the slot count, the remaining slots are padded with zeros during 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()
message = [1, 2, 3]
ciphertext = engine.encrypt(message, secret_key)
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
message = [1, 2, 3]
ciphertext = engine.encrypt(message, secret_key, level=3)
Engine.encrypt(message, public_key, level)- Directly encrypts a list or numpy array using a public key.
The message is encrypted in segments of length
Engine.slot_count. If the message length is not divisible by the slot count, the remaining slots are padded with zeros during encryption.
- Input:
- data: A Python list, numpy array, or plaintext. Supported data types include int, double, and complex double.
- PublicKey
- 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, secret_key)- Encrypts an already encoded plaintext using a secret key. This function is not supported in multiparty computation. 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()
message = [1, 2, 3]
plaintext = engine.encode(message)
ciphertext = engine.encrypt(encoded, secret_key)
Engine.encrypt(plaintext, public_key)- Encrypts an already encoded plaintext using a public key. The ciphertext's maximum multiplication depth will match the specified level of the plaintext.
- Input:
- Plaintext
- PublicKey
- 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.