Registry / auth-security / lightphe

lightphe

JSON →
library0.0.25pypypi✓ verified 85d ago

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.

pip install lightphe
INSTALL
IMPORT
SIG · LIGHTPHE
L
lightphe
auth-securitypythonv0.0.25
Install
6.6s avg
Import
1112ms
Disk
90MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.25 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.139s · 79.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 6.6s · import 1.085s · 80MB
90MB installed
● package 90MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LightPHE
from lightphe import LightPHE
from lightphe.schemes import Paillier
The `LightPHE` class acts as a factory to build cryptosystems for various algorithms; direct import of internal scheme modules is not the intended public API.

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.")
Debug
Known issues
gotchaAttempting homomorphic operations not supported by the chosen algorithm will raise an exception. For example, Paillier is additively homomorphic but not multiplicatively homomorphic for two ciphertexts.
fix
Consult the library's documentation (e.g., GitHub README table) to verify which homomorphic operations (addition, multiplication, scalar multiplication, XOR) are supported by each specific algorithm (RSA, Paillier, ElGamal, etc.) before performing operations.
affects: All versions
gotchaDecryption for some algorithms, like Exponential ElGamal or Elliptic Curve ElGamal, involves solving the discrete logarithm problem. While the library handles this, very large plaintexts might impact practical decryption times or even theoretical feasibility if not carefully considered.
fix
Be mindful of the plaintext value range and the computational implications for algorithms relying on discrete logarithm for decryption, especially in performance-sensitive applications.
affects: All versions
Errors
Common errors & fixes
TypeError: unsupported operand type(s) for *: 'Ciphertext' and 'Ciphertext'
You are attempting to multiply two `Ciphertext` objects using an algorithm (e.g., Paillier) that is not multiplicatively homomorphic for ciphertexts.
fix
Ensure the chosen algorithm supports the desired homomorphic operation. For multiplicative operations on ciphertexts, consider algorithms like RSA. For scalar multiplication (ciphertext by a known plain constant), many additively homomorphic schemes like Paillier support it. Refer to the 'Summary of Homomorphic Features' in the LightPHE documentation.
Message does not get decrypted in Python with LightPHE
This generic error often occurs if the cryptosystem was built with one algorithm but operations or decryption are attempted in a way incompatible with that algorithm's properties, or if the keys are mismatched/corrupted. Another common cause is attempting an operation that, while syntactically correct, breaks the homomorphic properties for the specific scheme.
fix
Double-check that the `algorithm_name` used during `LightPHE` initialization is appropriate for your desired operations. Ensure that the `encrypt` and `decrypt` calls use the same `LightPHE` instance (or correctly serialized/deserialized keys). Verify that intermediate homomorphic operations respect the limitations of the chosen scheme (e.g., not performing multiplication if only addition is supported).
Upgrade
Version history
0.0.25latest on PyPI · released May 12, 2026
Audit
Dependencies
pythonrequiredRequired for execution
Agent activity
21 hits · last 30 days
node
20
OpenAI (training)
1
Resources
lightphe — pip install lightphe · libregistry