Skip to content

Instantly share code, notes, and snippets.

@LiorB-D
Created June 29, 2022 09:21
Show Gist options
  • Save LiorB-D/c77fde040193c2001e7ff5921dc40663 to your computer and use it in GitHub Desktop.
Save LiorB-D/c77fde040193c2001e7ff5921dc40663 to your computer and use it in GitHub Desktop.
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