-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
82 lines (61 loc) · 2.01 KB
/
client.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#AUTHOR :: HARSHIT KAPOOR
# Import socket module
import socket
import aes_en
import rsa
import sys
host = '127.0.0.1'
# Define the port on which you want to connect
port = 12345
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
def Main():
# connect to server on local computer
s.connect((host,port))
# message you send to server
message = "Send server public key"
while True:
# message sent to server
s.send(message.encode('ascii'))
# messaga received from server
data = s.recv(1024)
server_key = str(data.decode('ascii'))
# print the received message
# here it would be a reverse of sent message
print('Public key received from the server :',str(data.decode('ascii')))
# ask the client whether he wants to continue
ans = input('\nDo you want to continue(y/n) :')
if ans == 'y':
while True:
plaintext = int(input("\n\nMESSAGE : "))
key = int(input("KEY : "))
aes_en.keyExp(key)
#assert encrypt(plaintext) == ciphertext
ciphertext = str(aes_en.aes_encrypt(plaintext))
#e,n public key parameters
e,n = map(int,input("PUBLIC KEY PARAMETERS (e,n) : ").split(","))
#d private key parameter
d = int(input("PRIVATE KEY PARAMETER (d) : "))
#encrypting secret key
encKey = rsa.RSA(key,server_key,n)
print("ENCRYPTED SECRET KEY :",encKey)
print("CIPHER TEXT :", ciphertext)
#message hash
digest = rsa.Digest(plaintext)
#convert digest to ascii
digest1 = rsa.conv_digest_ascii(digest)
print("DIGEST :",digest1)
#client signature generation
client_sign = rsa.RSA(digest1[6],d,n)
print("DIGITAL SIGNATURE : ",client_sign)
file = [ciphertext,encKey,client_sign,n,e]
s.send(file[0].encode('ascii'))
s.send(file[1].encode('ascii'))
s.send(file[2].encode('ascii'))
s.send(str(file[3]).encode('ascii'))
s.send(str(file[4]).encode('ascii'))
else:
break
# close the connection
s.close()
if __name__ == '__main__':
Main()