Skip to content

Commit 652707b

Browse files
committed
Restructure the repo
1 parent cae7c6c commit 652707b

9 files changed

+499
-0
lines changed
File renamed without changes.

fly-20x20.jpg assets/fly-20x20.jpg

File renamed without changes.

fly-50x50.jpg assets/fly-50x50.jpg

File renamed without changes.

fly.jpg assets/fly.jpg

File renamed without changes.

src/client.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import socket
2+
import pickle
3+
import tenseal as ts
4+
5+
def start_client():
6+
host = '127.0.0.1'
7+
port = 12345
8+
9+
# Create socket object
10+
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
11+
12+
# Connect to server
13+
client_socket.connect((host, port))
14+
print(f"Connected to {host}:{port}")
15+
16+
# Create Tenseal context and encrypt data
17+
context = ts.context(scheme="CKKS", bits_scale=30)
18+
encoder = ts.encoder(context)
19+
data = encoder.encode([1.2, 2.4, 3.6])
20+
encrypted_data = ts.encrypt(data, context)
21+
22+
# Send encrypted data and context to server
23+
message = pickle.dumps((encrypted_data, context))
24+
client_socket.send(message)
25+
26+
# Receive encrypted data and context from server
27+
response = client_socket.recv(4096)
28+
encrypted_data, context = pickle.loads(response)
29+
30+
# Decrypt received data
31+
decrypted_data = ts.decrypt(encrypted_data, context)
32+
print("Decrypted data:", decrypted_data)
33+
34+
client_socket.close()
35+
36+
if __name__ == "__main__":
37+
start_client()

sec.py src/sec.py

File renamed without changes.

src/server.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import socket
2+
import pickle
3+
4+
def start_server():
5+
host = '127.0.0.1'
6+
port = 12345
7+
8+
# Create socket object
9+
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10+
11+
# Bind socket to host and port
12+
server_socket.bind((host, port))
13+
14+
# Listen for incoming connections
15+
server_socket.listen(5)
16+
print(f"Server listening on {host}:{port}")
17+
18+
while True:
19+
client_socket, address = server_socket.accept()
20+
print(f"Connected to {address}")
21+
22+
# Receive encrypted data and context from client
23+
data = client_socket.recv(4096)
24+
encrypted_data, context = pickle.loads(data)
25+
26+
# Process encrypted data (e.g., perform computations)
27+
# For simplicity, just return the same encrypted data
28+
29+
# Send encrypted data and context back to client
30+
response = pickle.dumps((encrypted_data, context))
31+
client_socket.send(response)
32+
33+
client_socket.close()
34+
35+
if __name__ == "__main__":
36+
start_server()

src/sift.py

+426
Large diffs are not rendered by default.

test.py src/test.py

File renamed without changes.

0 commit comments

Comments
 (0)