Lightweight Partially Homomorphic Encryption Library for Python

0.0.23 · active · verified Thu Apr 16

LightPHE is a lightweight partially homomorphic encryption library for Python. It is a hybrid homomorphic encryption library wrapping many schemes such as RSA, ElGamal, Paillier, and more. It offers a more efficient and practical choice compared to fully homomorphic encryption for tasks that demand partial homomorphic capabilities, being faster, demanding fewer computational resources, and generating smaller ciphertexts. The library is actively maintained, with its latest release in March 2026.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a partially homomorphic cryptosystem (Paillier), encrypt two plaintexts, perform a homomorphic addition on their ciphertexts, and decrypt the result to confirm it matches the sum of the original plaintexts.

from lightphe import LightPHE

# Build an additively homomorphic cryptosystem (e.g., Paillier)
# Other options: 'RSA', 'ElGamal', 'Exponential-ElGamal', 'Damgard-Jurik', etc.
cs = LightPHE(algorithm_name = "Paillier")

# Define plaintexts
m1 = 17
m2 = 21

# Encrypt plaintexts (private key is not required for encryption)
c1 = cs.encrypt(m1)
c2 = cs.encrypt(m2)

# Perform homomorphic addition on ciphertexts
c3 = c1 + c2

# Decrypt the result to get the sum of plaintexts
d3 = cs.decrypt(c3)

print(f"Plaintext 1: {m1}")
print(f"Plaintext 2: {m2}")
print(f"Ciphertext 1: {c1}")
print(f"Ciphertext 2: {c2}")
print(f"Homomorphic Sum (c1 + c2): {c3}")
print(f"Decrypted Sum: {d3}")

assert d3 == m1 + m2, "Decrypted sum does not match plaintext sum"
print("Assertion successful: Decrypted sum matches expected value.")

view raw JSON →