-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdhserv.py
More file actions
56 lines (42 loc) · 1014 Bytes
/
dhserv.py
File metadata and controls
56 lines (42 loc) · 1014 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def keygen():
import random
p,g=map(int,raw_input("Enter Public keys: ").split())
#p=int(x[0])
#g=int(x[1])
b=random.randint(0,50)
key1=g**b%p
print "Generated key: ",key1
print "Private key: ",b
return str(key1),p,b
def seckey(msg,p,b):
sk=(int(msg)**b)%p
print "Secret Keys: ",sk
return sk
def keycheck(msg,sk):
if sk==int(msg):
print "Keys Matched!!!"
else:
print "keys not matched!!!"
import socket
serv=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host=socket.gethostbyname("")
port=9999
serv.bind((host,port))
serv.listen(5)
print "\t******************"
print "\t*SERVER IS ONLINE*"
print "\t******************\n"
while True:
cli,addr=serv.accept()
print "--------------------------------------------"
print "\t\tClient Connected\n"
k,p,b=keygen()
cli.send(k)
msg=cli.recv(4096)
s=seckey(msg,p,b)
msg=cli.recv(4096)
print "received secret key: ",msg
keycheck(msg,s)
print "\n\t\t Client Left"
print "--------------------------------------------"
cli.close()