Skip to main content

Paillier encryption

Project description

Paillier encryption

python3.8 package for Paillier encryption.

Example usage

Setup

from paillier.keygen import generate_keys
from paillier.crypto import encrypt, decrypt

pk, sk = generate_keys()

Basic encryption and decryption

m1 = 45336
ciphertext = encrypt(pk, m1)
assert m1 == decrypt(pk, sk, ciphertext)

Homomorphic things

from paillier.crypto import secure_addition, scalar_multiplication, secure_subtraction

n, _ = pk
m2 = 30381

# Secure addition
e1 = encrypt(pk, m1)
e2 = encrypt(pk, m2)
addition = secure_addition(e1, e2, n)
assert m1 + m2 == decrypt(pk, sk, addition)

# Scalar multiplication
k = 23  # some scalar
e1 = encrypt(pk, m1)
multiplied = scalar_multiplication(e1, k, n)
assert (m1 * k) % n == decrypt(pk, sk, multiplied)

# Secure subtraction
assert m1 > m2, "m2 should be bigger than m1 in order to subtract m2 from m1"
e1 = encrypt(pk, m1)
e2 = encrypt(pk, m2)
subtracted = secure_subtraction(e1, e2, n)
assert m1 - m2 == decrypt(pk, sk, subtracted)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rens-paillier-1.2.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rens_paillier-1.2.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file rens-paillier-1.2.1.tar.gz.

File metadata

  • Download URL: rens-paillier-1.2.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

File hashes

Hashes for rens-paillier-1.2.1.tar.gz
Algorithm Hash digest
SHA256 6ec32f2c7c62847dc718ec8202366ea865241d4d5ad8d7df50eb08ecc848c34d
MD5 cfa97a8a34afb65eb1436831e67bf91f
BLAKE2b-256 c9c542cd97642e5202e0be034059f3b0c3aac2ffe193fcaa0cc32499938dedd4

See more details on using hashes here.

File details

Details for the file rens_paillier-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: rens_paillier-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

File hashes

Hashes for rens_paillier-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65f124620db3424ce35735b9d815be44f0799146c99c0735e274883b13547315
MD5 e8b685ef2f26e26cf739044e4825ccfd
BLAKE2b-256 69c847ab733b79e9eedff792f51ae443def03822eb04945e428db9f2fb9f1c66

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page