labendsem
This commit is contained in:
		
							parent
							
								
									040219580e
								
							
						
					
					
						commit
						9d70a80337
					
				
					 9 changed files with 1349 additions and 0 deletions
				
			
		
							
								
								
									
										47
									
								
								IS/Lab/Eval-Endsem/client.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								IS/Lab/Eval-Endsem/client.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,47 @@ | |||
| import os | ||||
| import json | ||||
| import socket | ||||
| import base64 | ||||
| import hashlib | ||||
| from datetime import datetime | ||||
| from Crypto.PublicKey import RSA, ElGamal | ||||
| from Crypto.Random import get_random_bytes | ||||
| from Crypto.Util.number import inverse, GCD | ||||
| from Crypto.Cipher import AES, PKCS1_OAEP | ||||
| from phe import paillier | ||||
| 
 | ||||
| SERVER_HOST = "127.0.0.1" | ||||
| SERVER_PORT = 5000 | ||||
| INPUT_DIR = "inputdata" | ||||
| KEYS_DIR = "client_keys" | ||||
| 
 | ||||
| server_info = {}  # filled by get_public_info | ||||
| cached_paillier_pub = None | ||||
| 
 | ||||
| def ensure_dirs(): | ||||
|     os.makedirs(INPUT_DIR, exist_ok=True) | ||||
|     os.makedirs(KEYS_DIR, exist_ok=True) | ||||
| 
 | ||||
| def b64e(b: bytes) -> str: | ||||
|     return base64.b64encode(b).decode() | ||||
| 
 | ||||
| def b64d(s: str) -> bytes: | ||||
|     return base64.b64decode(s.encode()) | ||||
| 
 | ||||
| def send_request(action, role, body): | ||||
|     req = {"action": action, "role": role, "body": body} | ||||
|     with socket.create_connection((SERVER_HOST, SERVER_PORT), timeout=5) as s: | ||||
|         s.sendall((json.dumps(req) + "\n").encode()) | ||||
|         data = s.recv(1024*1024) | ||||
|     resp = json.loads(data.decode()) | ||||
|     if resp.get("status") != "ok": | ||||
|         print("server error:", resp.get("error")) | ||||
|         return None | ||||
|     return resp.get("data") if "data" in resp else {} | ||||
| 
 | ||||
| def get_public_info(): | ||||
|     global server_info, cached_paillier_pub | ||||
|     data = send_request("get result:") | ||||
|     if data is None: | ||||
| 
 | ||||
| def rs | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 student
						student