Computer Network
Computer Network
Code:
Diffie-Hellman:
def prime_checker(n):
for i in range(2, n):
if(n % i == 0):
return True
return False
present[number] = True
return False
x = pow(g, a) % p
y = pow(g, b) % p
alice_secret_key = pow(y, a) % p
bob_secret_key = pow(x, b) % p
print(alice_secret_key)
print(bob_secret_key)
Output:
MITM:
import random
class A:
def __init__(self):
# Generating a random private number selected by alice
self.n = random.randint(1, p)
def publish(self):
# generating public values
return (g**self.n)%p
class B:
def __init__(self):
self.a = random.randint(1, p)
self.b = random.randint(1, p)
self.arr = [self.a,self.b]
alice = A()
bob = A()
eve = B()
Output: