Created
June 29, 2022 09:21
-
-
Save LiorB-D/c77fde040193c2001e7ff5921dc40663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
p = 520 | |
g = 4 | |
class Person: | |
def __init__(self, name): | |
self.name = name | |
self.priv_key = random.randint(500, 4000) | |
def computeOffer(pers, g, p): | |
return (g ** pers.priv_key) % p | |
def computeKey(pers, offer, p): | |
K = (offer ** pers.priv_key) % p | |
pers.cKey = K | |
return K | |
annie = Person("Annie") | |
billy = Person("Billy") | |
print("Private Keys: ") | |
print(annie.priv_key) | |
print(billy.priv_key) | |
A = annie.computeOffer(g, p) | |
B = billy.computeOffer(g, p) | |
print("Offers in the Insecure Channel: ") | |
print(A) | |
print(B) | |
print("Cryptographic Keys:") | |
print(annie.computeKey(B, p)) | |
print(billy.computeKey(A, p)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment