You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
59 lines
1.2 KiB
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Sun Mar 19 17:32:56 2023
|
|
|
|
@author: simon
|
|
"""
|
|
|
|
from Crypto.PublicKey import DSA
|
|
import random
|
|
|
|
DSAkey=DSA.generate(int(1024))
|
|
p = DSAkey.p
|
|
q = DSAkey.q
|
|
|
|
print("p = {}".format(hex(p)))
|
|
print("q = {}".format(hex(q)))
|
|
#p = 59
|
|
#q = 29
|
|
foundAlpha = True
|
|
while not foundAlpha:
|
|
#for alpha in range(2,p-1):
|
|
alpha = random.randint(2,p-1)
|
|
#alpha = DSAkey.y
|
|
if pow(alpha,q,p) == 1:
|
|
# check if smaller integer k exists
|
|
for k in range(1,q):
|
|
if pow(alpha,k,p) == 1:
|
|
if k == q:
|
|
foundAlpha = True
|
|
break
|
|
else:
|
|
break
|
|
if foundAlpha == True:
|
|
break
|
|
alpha = DSAkey.y
|
|
if foundAlpha:
|
|
print("found alpha={}, where ord(alpha)=q".format(alpha))
|
|
else:
|
|
print("unable to find alpha")
|
|
exit(1)
|
|
|
|
d = random.randint(1, q-1)
|
|
#d = 7
|
|
print("d={}".format(d))
|
|
for beta in range(1,p):
|
|
if (beta % p) == pow(alpha,d,p):
|
|
break
|
|
print("beta={}".format(beta))
|
|
|
|
ke = random.randint(1, q-1)
|
|
ke = 10
|
|
|
|
for r in range(1,p-1):
|
|
if pow(pow(alpha,ke,p),1,q) == pow(r,1,q):
|
|
break
|
|
print("r={}".format(r))
|
|
|
|
|
|
|