forked from cy1c0n9/SecureMultiPartyComputation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (57 loc) · 2.15 KB
/
main.py
File metadata and controls
80 lines (57 loc) · 2.15 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# yao garbled circuit evaluation v1. simple version based on smart
# yicong chen, dept of computing, imperial college, november 2018
import json # load
import sys # argv
import ot # alice, bob
import util # ClientSocket, log, ServerSocket
import yao # Circuit
import Alice
import Bob
# Alice is the circuit generator (client) __________________________________
def alice(filename):
file = open("out.txt", "a")
file.write("python3 " + sys.argv[0] + " " + sys.argv[1] + " " + sys.argv[2] + "\n\n")
file.close()
with open(filename) as json_file:
json_circuits = json.load(json_file)
a = Alice.Alice(json_circuits)
# Bob is the circuit evaluator (server) ____________________________________
def bob():
util.log(f'Bob: Listening ...')
file = open("out.txt", "w")
file.close()
b = Bob.Bob()
b.listen()
# local test of circuit generation and evaluation, no transfers_____________
def local_test(filename):
with open(filename) as json_file:
json_circuits = json.load(json_file)
for json_circuit in json_circuits['circuits']:
# print(json_circuit["name"])
name = json_circuit["name"]
a = yao.get_attribute(json_circuit, "alice", [])
b = yao.get_attribute(json_circuit, "bob", [])
out = json_circuit["out"]
cir = yao.AliceCircuits(name, a, b, out, json_circuit["gates"])
# cir.print_out()
# print(json_circuit["gates"])
pass
# gc_json = "json_out/circuit from Smart, figure 2.2, page 443.json"
gc_json = "json_out/AND gate.json"
with open(gc_json) as json_file:
json_circuits = json.load(json_file)
yao.BobCircuits(json_circuits)
# yao.Bob("json_out/AND gate.json")
# << removed >>
# main _____________________________________________________________________
def main():
behaviour = sys.argv[1]
if behaviour == 'alice':
alice(filename=sys.argv[2])
elif behaviour == 'bob':
bob()
elif behaviour == 'local':
local_test(filename=sys.argv[2])
if __name__ == '__main__':
main()
# __________________________________________________________________________