diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 117ff66..9b949b2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -57,7 +57,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pylint + pip install pylint==3.0.2 pip install black pip install . diff --git a/lightphe/cryptosystems/ElGamal.py b/lightphe/cryptosystems/ElGamal.py index d0f33b7..1ac8564 100644 --- a/lightphe/cryptosystems/ElGamal.py +++ b/lightphe/cryptosystems/ElGamal.py @@ -1,7 +1,12 @@ +# built-in dependencies import random -import math +import decimal from typing import Optional + +# 3rd party dependencies import sympy + +# project dependencies from lightphe.models.Homomorphic import Homomorphic from lightphe.commons.logger import Logger @@ -45,7 +50,8 @@ def generate_keys(self, key_size: int): p = sympy.randprime(100, 2 ** int(key_size / 2) - 1) # picking a generator g - g = random.randint(2, int(math.sqrt(p))) + # g = random.randint(2, int(math.sqrt(p))) # reaches int limit for 3072-bit key + g = int(random.uniform(2, float(decimal.Decimal(p).sqrt()))) # picking a private key x x = random.randint(1, p - 2) diff --git a/lightphe/cryptosystems/GoldwasserMicali.py b/lightphe/cryptosystems/GoldwasserMicali.py index 7bcc51c..307d6ed 100644 --- a/lightphe/cryptosystems/GoldwasserMicali.py +++ b/lightphe/cryptosystems/GoldwasserMicali.py @@ -128,7 +128,12 @@ def decrypt(self, ciphertext: list) -> int: xp = i % p xq = i % q - if pow(xp, int((p - 1) / 2), p) == 1 and pow(xq, int((q - 1) / 2), q) == 1: + # reaches int limit for 3072-bit key + # if pow(xp, int((p - 1) / 2), p) == 1 and pow(xq, int((q - 1) / 2), q) == 1: + if ( + pow(xp, int((p - 1) // 2), p) == 1 + and pow(xq, int((q - 1) // 2), q) == 1 + ): m_binaries.append("0") else: m_binaries.append("1")