Skip to content

Commit

Permalink
clean up and sample output
Browse files Browse the repository at this point in the history
  • Loading branch information
zhewen shen committed Aug 6, 2024
1 parent 4c360d9 commit b2b6221
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,30 @@ A project for COMP6453.
- [How to Cite](#how-to-cite)

## Installation

Ensure you have Python 3.9 installed on your system. Then follow these steps:
1. Clone the repository:

```bash
git clone https://github.com/zhewenshen/applied-cryptography-project.git
```
2. Navigate to the project directory:

```bash
cd applied-cryptography-project
```
3. Install the required dependencies:

```bash
pip3 install -r requirements.txt
```

1. Clone the repository:

```bash
git clone https://github.com/zhewenshen/applied-cryptography-project.git
```

2. Navigate to the project directory:

```bash
cd applied-cryptography-project
```

3. Install the required dependencies:

```bash
pip3 install -r requirements.txt
```

## Usage
For sample usage please refer to [`src/main.py`](src/main.py)

For sample usage please refer to [`src/main.py`](src/main.py). Expected output can be found at [`demo_output.txt`](demo_output.txt).

## License

Expand All @@ -49,4 +55,3 @@ If you use this project in your work, please cite it as follows:
url = {https://github.com/zhewenshen/applied-cryptography-project},
}
```

3 changes: 1 addition & 2 deletions src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ def send_request(self, server: 'Server', request: Dict[str, Any]) -> Dict[str, A
encrypted_request = self.nacl_encrypt(serialize(request))
encrypted_response = server.handle_request(encrypted_request)
response = self.nacl_decrypt(encrypted_response)
response_dict = deserialize(response) # FIXME: validate response
response_dict = deserialize(response)

if 'result' in response_dict:
if isinstance(response_dict['result'], str):
response_dict['result'] = self.decrypt_data(
response_dict['result'], context)
elif isinstance(response_dict['result'], list):
print(type(response_dict['result']))
response_dict['result'] = [self.decrypt_data(
r, context) for r in response_dict['result']]

Expand Down
23 changes: 8 additions & 15 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

def test_statistical_computations(client, server):
datasets = [
[random.uniform(0, 100) for _ in range(347)],
[random.uniform(0, 100) for _ in range(443)],
[random.uniform(0, 100) for _ in range(42)]
[random.uniform(0, 6453) for _ in range(347)],
[random.uniform(0, 6453) for _ in range(443)],
[random.uniform(0, 6453) for _ in range(42)]
]

all_data = []
Expand Down Expand Up @@ -57,14 +57,6 @@ def test_statistical_computations(client, server):
print(f"\nCompute variance response: {response}")
print(f"Actual variance: {np.var(datasets[1])}")

response = client.send_request(server, {
'action': 'sd',
'request_type': 'normal',
'key': 'dataset_2'
})
print(f"\nCompute standard deviation response: {response}")
print(f"Actual standard deviation: {np.std(datasets[2])}")


def test_machine_learning(client, server):
california = fetch_california_housing()
Expand Down Expand Up @@ -119,8 +111,11 @@ def test_machine_learning(client, server):


if __name__ == "__main__":
# FIXME: it's probably better to pass key and init ratchet in constructor
# rather than calling them manually
# This is just a simulation of the protocol
# In a real-world scenario, the client and server would be running on different machines and communicating over a secure channel
# The ML model would need to be trained on a full sized dataset with many epochs
# it is just a toy example here - hence inference is not accurate

client = Client()
server = Server()

Expand All @@ -133,8 +128,6 @@ def test_machine_learning(client, server):
server.set_server_key_pair(server_pk, server_sk)
server.set_client_pk(client_pk)

# C -> S: "Client Hello" || client-header
# S -> C: "Server Hello || server-header
client.hello(server)

print("Testing Statistical Computations:")
Expand Down
2 changes: 1 addition & 1 deletion src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def hello(self, request):

def handle_request(self, encrypted_request: bytes) -> bytes:
request = self.nacl_decrypt(encrypted_request)
request_dict = deserialize(request) # FIXME: validate request
request_dict = deserialize(request)
context = ts.context_from(bytes.fromhex(request_dict['context']))

if request_dict['action'] == 'store':
Expand Down

0 comments on commit b2b6221

Please sign in to comment.