encode
GLEngine.encode(message, level)- Encodes a message into a plaintext format for encryption.
The shape of message that can be encoded is determined by
GLEngine.shape. The dimension of the 0-axis could be smaller. For example, if the shape of the engine is(256, 32, 32), messages with shape(n, 32, 32)wheren <= 256can be encoded. If the message length exceeds this size of shape, an error is raised. If it is smaller, the message is padded with zeros during encoding.
- Input:
- message: A Python list or numpy array. Data types supported include int, double, and complex double.
- level: optional
- Specifies the maximum multiplication level for encoding. Lower levels reduce space usage but also reduce the maximum multiplication depth.
- Output:
- GLPlaintext
import numpy as np
from desilofhe import GLEngine
engine = GLEngine()
message = np.ones(engine.shape)
encoded = engine.encode(message)
import numpy as np
from desilofhe import GLEngine
engine = GLEngine()
message = np.ones(engine.shape)
encoded = engine.encode(message, level=3)
import numpy as np
from desilofhe import GLEngine
engine = GLEngine()
# message with smaller batch
message = np.ones(23, 32, 32)
encoded = engine.encode(message)
Typically, the encrypt function handles encoding automatically.
Pre-encoding a message can improve efficiency when the same message is reused across multiple operations, as it avoids redundant encoding.