-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (24 loc) · 1.16 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from mpc.core import MPCAddition, MPCAverage
from mpc.party import Party
from mpc.utils import generate_secret_shares, sum_of_values
import logging
logging.basicConfig(level=logging.INFO)
def main():
clients = int(input("Enter the number of participants: "))
client_values = [int(input(f"Enter the value for client {i + 1}: ")) for i in range(clients)]
modulo = int(input("Enter the modulo: "))
share_count = int(input("Enter the number of shares to be generated: "))
client_shares = [generate_secret_shares(value, share_count, modulo) for value in client_values]
for client_share in client_shares:
logging.info(client_share)
client_shares_vertical = list(zip(*client_shares))
for client_share in client_shares_vertical:
logging.info(client_share)
parties = [Party(share, modulo) for share in client_shares_vertical]
mpc_addition = MPCAddition(parties)
mpc_average = MPCAverage(parties)
logging.info(f"Actual sum: {sum_of_values(client_values)}")
logging.info(f"MPC computed sum: {mpc_addition.compute()}")
logging.info(f'MPC Computed Average: {mpc_average.compute()}')
if __name__ == "__main__":
main()