IS Lab Pallier Fix
This commit is contained in:
parent
23af6d5b1d
commit
672cb43d49
1 changed files with 7 additions and 8 deletions
|
@ -1,13 +1,11 @@
|
|||
import random
|
||||
from math import gcd
|
||||
from sympy import isprime, lcm
|
||||
from math import gcd, lcm
|
||||
from sympy import isprime, randprime
|
||||
|
||||
|
||||
def generate_prime(bits=512):
|
||||
while True:
|
||||
num = random.getrandbits(bits)
|
||||
if isprime(num):
|
||||
return num
|
||||
# Use sympy's randprime for efficiency
|
||||
return randprime(2 ** (bits - 1), 2**bits)
|
||||
|
||||
|
||||
def generate_keypair(bits=512):
|
||||
|
@ -23,10 +21,11 @@ def generate_keypair(bits=512):
|
|||
def L(x):
|
||||
return (x - 1) // n
|
||||
|
||||
mu = pow(L(pow(g, lambda_n, n_squared)), -1, n)
|
||||
# Convert to int to avoid sympy Integer type issues
|
||||
mu = pow(int(L(pow(g, int(lambda_n), n_squared))), -1, n)
|
||||
|
||||
public_key = (n, g)
|
||||
private_key = (lambda_n, mu)
|
||||
private_key = (int(lambda_n), mu)
|
||||
|
||||
return public_key, private_key
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue