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 lightpheVerified import paths — ran on the pinned version, not inferred.
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.
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.
Be mindful of the plaintext value range and the computational implications for algorithms relying on discrete logarithm for decryption, especially in performance-sensitive applications.
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.
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).