forked from codehouseindia/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffie Hellman Algorithm.py
More file actions
34 lines (22 loc) · 980 Bytes
/
Diffie Hellman Algorithm.py
File metadata and controls
34 lines (22 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#The Diffie-Hellman algorithm is being used to establish a shared secret
#that can be used for secret communications while exchanging data over a
#public network using the elliptic curve to generate points and get the secret key using the parameters
if __name__ == '__main__':
#Public Keys P and G
P = int(input("Enter Public Key P: "))
G = int(input("Enter Public Key G: "))
# Alice will choose the private key a
a = int(input("Enter Private Key for Alice: "))
# Bob will choose the private key b
b = int(input("Enter Private Key for Bob: "))
# gets the generated key
ga = int((G**a)%P)
# gets the generated key
gb = int((G**b)%P)
print("Exchanging Generated Keys")
# Secret key for Alice
ka = int((gb**a)%P)
# Secret key for Bob
kb = int((ga**b)%P)
print('Secret key for the Alice is : %d'%(ka))
print('Secret Key for the Bob is : %d'%(kb))