-
Notifications
You must be signed in to change notification settings - Fork 0
/
p2p_vpn.py
23 lines (20 loc) · 903 Bytes
/
p2p_vpn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import torch
import socket
# Connect to the VPN server
server_address = ('vpn.example.com', 12345)
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client_socket.sendto(b'0:' + b','.join(map(str, public_key.tolist())), server_address)
# Receive the public keys of other users
peer_public_keys = {}
while len(peer_public_keys) < 9:
data, address = client_socket.recvfrom(1024)
user_id, public_key = data.split(':')
user_id = int(user_id)
public_key = torch.tensor(list(map(float, public_key.split(','))))
peer_public_keys[user_id] = public_key
# Encrypt and send data to other users
while True:
data = input('Enter data to send: ')
for user_id, public_key in peer_public_keys.items():
encrypted_data = public_key * torch.tensor(list(map(float, data.split(','))))
client_socket.sendto(encrypted_data.tolist(), users[user_id]['peer_address'])