MINE IS BAD
This commit is contained in:
1 parent
b07c85e8cb
commit
711c6474cc
1 file changed
+7
-2
@@ -1,9 +1,14 @@
|
|||||||
|
"""
|
||||||
|
stuff sent over could be forged by a middleman,
|
||||||
|
this and DSA ensures that with msg, pubkey, and something else, you can verify msg was signed by OG.
|
||||||
|
"""
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
|
||||||
class Elgamal:
|
class Elgamal:
|
||||||
def __init__(self, p: int, alpha: int, d: int) -> None:
|
def __init__(self, p: int, alpha: int, d: int) -> None:
|
||||||
"contract: p is prime, and"
|
"contract: p is prime, and..."
|
||||||
if not 0 <= alpha < p or math.gcd(alpha, p) != 1:
|
if not 0 <= alpha < p or math.gcd(alpha, p) != 1:
|
||||||
# set Z*_n is all i [0, n) st gcd(i, n) = 1, if n is prime thats jus the whole thing
|
# set Z*_n is all i [0, n) st gcd(i, n) = 1, if n is prime thats jus the whole thing
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
@@ -24,7 +29,7 @@ class Elgamal:
|
|||||||
if not 2 <= ke <= self.p - 2 or math.gcd(ke, self.p - 1) != 1:
|
if not 2 <= ke <= self.p - 2 or math.gcd(ke, self.p - 1) != 1:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
r = pow(self.alpha, ke, self.p)
|
r = pow(self.alpha, ke, self.p)
|
||||||
kei = pow(ke, -1, self.p - 1) # mod p - 1
|
kei = pow(ke, -1, self.p - 1) # mod p - 1
|
||||||
s = ((x - self.d * r) * kei) % (self.p - 1)
|
s = ((x - self.d * r) * kei) % (self.p - 1)
|
||||||
return r, s
|
return r, s
|
||||||
|
|
||||||
Reference in new issue
Block a user