encrypt_pytorch_tensor
Encryption with PyTorch Tensors
Engine.encrypt_pytorch_tensor(tensor, secret_key, level)- Directly encrypts a PyTorch tensor using a secret key.
This function is not supported in multiparty computation.
The tensor's device can be either CPU or CUDA and must match that of the engine.
The message is encoded 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 encoding.
- Input:
- data: torch.Tensor
- SecretKey
- level: optional
- Specifies the desired multiplication level. Lower levels reduce space usage but also reduce the maximum multiplication depth.
- Output:
- Plaintext
Examples
CPU
import torch
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
tensor = torch.tensor([1, 2, 3, 4])
ciphertext = engine.encrypt_pytorch_tensor(tensor, secret_key)
ciphertext_level_2 = engine.encrypt_pytorch_tensor(tensor, secret_key, level=2)
GPU
import torch
from desilofhe import Engine
engine = Engine(mode="gpu")
secret_key = engine.create_secret_key()
tensor = torch.tensor([1, 2, 3, 4], device="cuda")
ciphertext = engine.encrypt_pytorch_tensor(tensor, secret_key)
Engine.encrypt_pytorch_tensor(message, public_key, level)- Directly encrypts a PyTorch tensor using a public key.
The tensor's device can be either CPU or CUDA and must match that of the engine.
The message is encoded 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 encoding.
- Input:
- data: torch.Tensor
- PublicKey
- level: optional
- Specifies the desired multiplication level. Lower levels reduce space usage but also reduce the maximum multiplication depth.
- Output:
- Plaintext
Examples
CPU
import torch
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
tensor = torch.tensor([1, 2, 3, 4])
ciphertext = engine.encrypt_pytorch_tensor(tensor, public_key)
ciphertext_level_2 = engine.encrypt_pytorch_tensor(tensor, public_key, level=2)
GPU