A simple implementation of the Paillier cryptosystem
Project description
paillier-lib
This package provides a simple implementation of the Paillier cryptosystem using gmpy2.
Usage
import paillier
from gmpy2 import mpz
key_pair = paillier.keygen() # Optional param.: bit size (default = 2048)
m1 = mpz(10)
m2 = mpz(1)
c1 = paillier.encrypt(m1, key_pair.public_key)
c2 = paillier.encrypt(m2, key_pair.public_key)
# Example homomorphic operations
# Addition
paillier.decrypt(c1 + c2, key_pair.private_key) # => 11
paillier.decrypt(c1 - c2, key_pair.private_key) # => 9
paillier.decrypt(c1 + c1 + c2, key_pair.private_key) # => 21
# Multiplication (ciphertext with plaintext)
m3 = mpz(2)
paillier.decrypt(c1 * m3, key_pair.private_key) # => 20
Requirements
gmpy2 (tested v2.0.8)
Planned Work
- Encode inputs, rather than requiring GMP MPZ objects.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
paillierlib-0.0.1.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for paillierlib-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43e9f7b980a49f58d94020d576954ed2ce58d410467581ff6081e8a958f16960 |
|
MD5 | 820d353e8ffab4b94b9f44552892838f |
|
BLAKE2b-256 | 8b0b78176a076be40f0472f34694adeeed3bd9ca7e1898af79b40ba1984174d4 |