-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
25 lines (25 loc) · 982 Bytes
/
client.py
File metadata and controls
25 lines (25 loc) · 982 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
import socket
import os
from xmlrpc.client import Server
import time
if __name__ == '__main__':
s = socket.socket()
port=4999
address='127.0.0.1'
s= socket.socket (socket.AF_INET, socket.SOCK_STREAM)
#connecting server to socket(ip+portnumber)
s.connect((address,port))
recievedmessage = s.recv(1024).decode('ASCII') #data is received
ServerPublicKey, ServerN = recievedmessage.split(":")
print("We recieved ServerPublicKey: ",ServerPublicKey)
plainText = int(input("Enter plainText: "))
print("********Encrypting*********")
encrypt_starttime = time.time()
cipherText = ((plainText)**int(ServerPublicKey)) % int(ServerN)
print("CipherText generated is: ",cipherText)
time.sleep(0.004)
encrypt_endtime = time.time()
print(f"encrption time : {(encrypt_endtime-encrypt_starttime)}")
messageToSend = str(cipherText)
print("Sent the message to client: ",messageToSend)
s.send(messageToSend.encode('ASCII'))