# Creating a new socket by which we can speak to the other client clientSocket = factory.socket(factory.AF_INET, factory.SOCK_STREAM) clientSocket.bind((HOST, clientId)) print('Listening for the client that wants to chat') clientSocket.listen() # Accept the connection conn, addr = clientSocket.accept() print('Accepted connection from peer') # Getting Hello peerId = functions.stringToJSON(functions.read_from_socket(conn).decode('utf-8'))['peer'] pubKey = functions.stringToIntList(functions.createCommunication(socket, peerId)) # Sending ACK functions.send_msg(conn, json.dumps({"ACK" : 1})) # Defining the phrase which will be used by the Solitaire encryption print('Select a phrase for encryption:') phrase = input() # Sending and reading phrase with which we will use the Solitaire encryptions formatedPhrase = functions.intListToString(knap.encrypt(phrase, pubKey)) functions.send_msg(conn, formatedPhrase) # Assembling the secret phrase phrase = knap.decrypt(functions.stringToIntList(functions.read_from_socket(conn))).decode('utf-8') + phrase print('Assembled the encrypting phrase with my peer') print(phrase) # Creating the Solitaire encryption tool
import socket import time import functions HOST = '192.168.1.33' PORT = functions.PORT s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) print('Connected to {}:{}'.format(HOST, PORT)) starttime = time.time() while True: msg = 'Hi.' functions.send_msg(s, msg) time.sleep(5.0 - ((time.time() - starttime) % 5.0))
# Getting the users publicKey pubKey = functions.createCommunication(socket, c2Id) pubKey = functions.stringToIntList(pubKey) # Creating a new socket by which we can speak to the other client clientSocket = factory.socket(factory.AF_INET, factory.SOCK_STREAM) server_address = (HOST, c2Id) # Connecting to the other client clientSocket.connect(server_address) print('Connected to the peer we want to speak with') # Sending hello print('Sending hello to the other client') functions.send_msg(clientSocket, json.dumps({"peer": clientId})) # Waiting for hello ack = functions.read_from_socket(clientSocket).decode('utf-8') print(ack) print('Select a phrase for encryption:') phrase = input() # Sending the phrase that which we will use in Solitaire encryptions formatedPhrase = functions.intListToString(knap.encrypt(phrase, pubKey)) functions.send_msg(clientSocket, formatedPhrase) # Assembling the phrase phrase += knap.decrypt( functions.stringToIntList( functions.read_from_socket(clientSocket))).decode('utf-8')