forked from thuva4/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffieHellman.py
More file actions
32 lines (25 loc) · 1.01 KB
/
DiffieHellman.py
File metadata and controls
32 lines (25 loc) · 1.01 KB
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
# use Python 3 print function
# this allows this code to run on python 2.x and 3.x
# Variables Used
sharedPrime = 23 # p - prime
sharedBase = 5 # g - generator
aliceSecret = 6 # a
bobSecret = 15 # b
# Begin
print( "Publicly Shared Variables:")
print( " Publicly Shared Prime: " , sharedPrime )
print( " Publicly Shared Base: " , sharedBase )
# Alice Sends Bob A = g^a mod p
A = (sharedBase**aliceSecret) % sharedPrime
print( "\n Alice Sends Over Public Channel: " , A )
# Bob Sends Alice B = g^b mod p
B = (sharedBase ** bobSecret) % sharedPrime
print(" Bob Sends Over Public Channel: ", B )
print( "\n----------------------------------------\n" )
print( "Privately Calculated Shared Secret:" )
# Alice Computes Shared Secret: s = B^a mod p
aliceSharedSecret = (B ** aliceSecret) % sharedPrime
print( " Alice Shared Secret: ", aliceSharedSecret )
# Bob Computes Shared Secret: s = A^b mod p
bobSharedSecret = (A**bobSecret) % sharedPrime
print( " Bob Shared Secret: ", bobSharedSecret )