def run(self): print('starting party ', self.i) self.get_triplets() self.tt = self.get_share('b') ## DISTRIBUTE INPUT for j in range(ite): # data = dd[j] # print('Data: ', data) while True: if not self.q2.empty(): data = self.q2.get() break print('measured pressure:', data) self.distribute_shares(data) ## GET INPUT_SHARES input_shares = self.get_shares('input') # Find minimum using Legendre Comparison: c = self.legendreComp(input_shares[2], input_shares[3]) a = self.mult_shares(1 - c, input_shares[2]) + self.mult_shares( c, input_shares[3]) temp = a for i in range(2): c = self.legendreComp(a, input_shares[i]) a = self.mult_shares(1 - c, a) + self.mult_shares( c, input_shares[i]) output3 = temp - a # booster 1 output0 = a # Booster 2 output1 = input_shares[0] - output0 # cons 3 output2 = input_shares[1] - output0 # cons 4 output4 = input_shares[2] - output0 - output3 # cons 1 output5 = input_shares[3] - output0 - output3 # cons 2 output = [output0, output1, output2, output3, output4, output5] for i in range(len(output)): sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['output' + str(self.i), int(str(output[i]))]) out = int(str(self.reconstruct_secret('output'))) / 100. sock.UDPclient(self.server_addr[self.i][0], self.server_addr[self.i][1], out) print('Control output party {}, round {}: {}'.format( self.i, j, out)) # time.sleep(1) #self.recv = {} self.c = 0 self.comr = 0
def __init__(self, F, n, t, numTrip): self.n = n b = ss.share(F, np.random.choice([-1, 1]), t, n) self.distribute_shares('b', b) triplets = [proc.triplet(F, n, t) for i in range(numTrip)] for i in range(n): l = [] for j in range(numTrip): l.append(triplets[j][i]) sock.TCPclient(party_addr[i][0], party_addr[i][1], ['triplets', l])
def run(self): for j in range(ite): out = int(str(self.reconstruct_secret('output'))) / 100. sock.UDPclient(self.server_addr[self.i][0], self.server_addr[self.i][1], out) self.q4.put([2, out]) print('Control ouput: ', out) # time.sleep(1) # self.recv = {} self.c = 0 self.comr = 0
def run(self): #Create TCP socket tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcpsock.bind(tuple(self.server_info)) #Communication loop - Wait->Receive->Put to queue while not self.stop: Rx_packet = sock.TCPserver(tcpsock) if not self.q.full(): self.q.put(Rx_packet) print("Exiting " + self.name)
def run(self): print('Pump ', self.i - 3, ' online') for j in range(ite): outMAT = int(str(self.reconstruct_secret('outputMAT'))) / 100. outLOC = int(str(self.reconstruct_secret('outputLOC'))) / 100. sock.UDPclient(self.server_addr[self.i][0], self.server_addr[self.i][1], outMAT) self.q4.put([2, outLOC]) print('Control ouput: ', outLOC) # time.sleep(1) # self.recv = {} self.c = 0 self.comr = 0
def run(self): print("Starting " + self.name) #Create UDP socket udpsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udpsock.bind((self.server_info[0], self.server_info[1])) print('UDP Server Started:', self.server_info[0], self.server_info[1]) #Communication loop - Wait->Receive->Put to queue while True: Rx_data = sock.UDPserver(udpsock)[0] if not q2.full(): q2.put(int(Rx_data * 100)) udpsock.close() print("Exiting " + self.name)
def broadcast(self, name, s): for i in range(self.n): sock.TCPclient( self.party_addr[i][0], self.party_addr[i][1], [name + str(self.i), int(str(s))])
def distribute_shares(self, sec): shares = ss.share(self.F, sec, self.t, self.n) for i in range(self.n): sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['input' + str(self.i), int(str(shares[i]))])
def distribute_shares(self, name, s): for i in range(self.n): sock.TCPclient(party_addr[i][0], party_addr[i][1], [name, int(str(s[i]))])
q = que.Queue() q2 = que.Queue() q3 = que.Queue() server_info = party_addr[pnr] #(TCP_IP, TCP_PORT) t1_comms = commsThread(1, "Communication Thread", server_info, q) p = party(F, int(x), n, t, pnr, q, q2, q3, party_addr, server_addr) t1_comms.start() for i in range(n): while True: try: sock.TCPclient(party_addr[i][0], party_addr[i][1], ['flag', 1]) break except: time.sleep(1) continue print('Data owner, autonomous vehicle') print(' ') print('Connection established') deal = dealer(F, n, t, 50) time_start = time.clock() p.start() p.join() #time_elapsed=(time.clock()-time_start) #comment all print commands before timing #print('time elapsed:', time_elapsed)
q3 = que.Queue() #Initialization.. #TCP_IP = '192.168.100.246' #TCP_PORT = 62 UDP_PORT2 = 3000 server_info = ips.party_addr[pnr] #(TCP_IP, TCP_PORT) server2_info = (ipv4, UDP_PORT2) # Create new threads.. t1_comms = commsThread(1, "Communication Thread", server_info, q) #t2_commsSimulink = UDPcommsThread(2, "t2_commsSimulink", server2_info) ploting = plotter(q3) ploting.start() p = party(F, int(x), n, t, pnr, q, q2, q3, ips.party_addr, ips.server_addr) # Start new Threads #t2_commsSimulink.start() t1_comms.start() for i in ips.party_addr: while True: try: sock.TCPclient(i[0], i[1], ['flag', 1]) break except: time.sleep(1) continue p.start()
def run(self): print('Consumer ', self.i + 1, ' online') self.get_triplets() self.tt = self.get_share('b') ## DISTRIBUTE INPUT for j in range(ite): # data = dd[j] # print('Data: ', data) while True: if not self.q2.empty(): dat = self.q2.get() break try: # CtrPres data = int(dat[0] * 100) if j > 0: self.q4.put([1, dat[1]]) except: print(j) data = int(dat * 100) print('measured pressure:', data / 100) # data = data self.distribute_shares(data) ## GET INPUT_SHARES input_shares = self.get_shares('input') # Find minimum using Legendre Comparison: c = self.legendreComp(input_shares[0], input_shares[1]) a = self.mult_shares(1 - c, input_shares[0]) + self.mult_shares( c, input_shares[1]) temp = a for i in range(2, 4): c = self.legendreComp(a, input_shares[i]) a = self.mult_shares(1 - c, a) + self.mult_shares( c, input_shares[i]) output4 = temp - a # booster 1 4 output1 = a # Booster 2 # 1 output2 = input_shares[0] - output1 # cons 3 2 output3 = input_shares[1] - output1 # cons 4 3 output5 = input_shares[2] - output1 - output4 # cons 1 5 output6 = input_shares[3] - output1 - output4 # cons 2 6 outputMATLAB = [ output1, output2, output3, output4, output5, output6 ] outputLOCAL = [ output6, output5, output3, output2, output4, output1 ] for i in range(len(outputMATLAB)): sock.TCPclient( self.party_addr[i][0], self.party_addr[i][1], ['outputMAT' + str(self.i), int(str(outputMATLAB[i]))]) sock.TCPclient( self.party_addr[i][0], self.party_addr[i][1], ['outputLOC' + str(self.i), int(str(outputLOCAL[i]))]) outMAT = int(str(self.reconstruct_secret('outputMAT'))) / 100. outLOC = int(str(self.reconstruct_secret('outputLOC'))) / 100. sock.UDPclient(self.server_addr[self.i][0], self.server_addr[self.i][1], outMAT) print('Control output party {}, round {}: {}'.format( self.i, j, outLOC)) self.q4.put([2, outLOC]) # time.sleep(1) #self.recv = {} self.c = 0 self.comr = 0
def run(self): n=3 m = 2 # number of A rows nn = 2 # number of A coloums l = 1 # number of b rows mu=min(nn,m) #obs, must be randomly generated in real life L=np.array(([1,0],[11,11])) U=np.array(([1,8],[0,1])) A00=2 A01=3 A10=4 A11=9 b0=6 b1=15 I00= 1 I01= 0 I10= 0 I11= 1 shareh=1 sharet=1 ran=7 AA=np.array([[A00, A01],[A10, A11]]) bb= np.array([[b0],[b1]]) print(' ') print('Input matrix A:') print(AA) print('Observation vector b:') print(bb) AB=np.hstack((AA,bb)) rankAB=np.array(matrix_rank(AB)) rankA= np.array(matrix_rank(AA)) if rankA == rankAB: print('Preconditions satisfied: the system is solvable') else: print('Preconditioning fails, system not solvable') s_A00= ss.share(self.F, A00, self.t, self.n) s_A01= ss.share(self.F, A01, self.t, self.n) s_A10= ss.share(self.F, A10, self.t, self.n) s_A11= ss.share(self.F, A11, self.t, self.n) s_b0= ss.share(self.F, b0, self.t, self.n) s_b1= ss.share(self.F, b1, self.t, self.n) s_h= ss.share(self.F, shareh, self.t, self.n) s_t= ss.share(self.F, sharet, self.t, self.n) s_r= ss.share(self.F, ran, self.t, self.n) s_I00=ss.share(self.F, I00, self.t, self.n) s_I01=ss.share(self.F, I01, self.t, self.n) s_I10=ss.share(self.F, I10, self.t, self.n) s_I11= ss.share(self.F, I11, self.t, self.n) for i in range(n): sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['hh'+str(i) , int(str(s_h[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['tt'+str(i) , int(str(s_t[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['ran'+str(i) , int(str(s_r[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['b0'+str(i) , int(str(s_b0[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['b1'+str(i) , int(str(s_b1[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['A00'+str(i) , int(str(s_A00[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['A01'+str(i) , int(str(s_A01[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['A10'+str(i) , int(str(s_A10[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['A11'+str(i) , int(str(s_A11[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['I00'+str(i) , int(str(s_I00[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['I01'+str(i) , int(str(s_I01[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['I10'+str(i) , int(str(s_I10[i]))]) sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['I11'+str(i) , int(str(s_I11[i]))]) print(' ') print('Shares have been send to cloud servers') resx1= self.get_shares('x1') resx2= self.get_shares('x2') print('...') print('...') print('Shares of computed result received') x1_res=ss.rec(self.F, resx1) x2_res=ss.rec(self.F, resx2) res1=int(str(x1_res)) res2=int(str(x2_res)) dummy3 =10E13 if res1 > dummy3: res1 = res1 -792606555396977 if res2 > dummy3: res2 = res2 -792606555396977 finalX1=res1/10E10 finalX2=res2/10E10 print(' ') print('Solution:') print(np.array([[finalX1],[finalX2]]))
def run(self): print('starting party ', self.i) self.get_triplets() self.tt = self.get_share('b') ## DISTRIBUTE INPUT max_open = 2.5 # Max open valve scale = max_open / 2. cons = 2 * scale pump = 1 for j in range(ite): # data = dd[j] # print('Data: ', data) if j == 0: dataT = [1, 0.0] else: while True: if not self.q2.empty(): dataT = self.q2.get() break print('measured pressure:', dataT) self.q4.put([1, float(dataT[-1])]) data = int(dataT[0] * 100) self.distribute_shares(data) ## GET INPUT_SHARES input_shares = self.get_shares('input') # Find minimum using Legendre Comparison: c = self.legendreComp(input_shares[2], input_shares[3]) a = self.mult_shares(1 - c, input_shares[2]) + self.mult_shares( c, input_shares[3]) temp = a for i in range(2): c = self.legendreComp(a, input_shares[i]) a = self.mult_shares(1 - c, a) + self.mult_shares( c, input_shares[i]) output3 = temp - a output0 = a output1 = input_shares[0] - output0 output2 = input_shares[1] - output0 output4 = input_shares[2] - output0 - output3 output5 = input_shares[3] - output0 - output3 output = [output0, output1, output2, output3, output4, output5] for i in range(len(output)): sock.TCPclient(self.party_addr[i][0], self.party_addr[i][1], ['output' + str(self.i), int(str(output[i]))]) if not self.qin1.empty(): cons = float(self.qin1.get()) * scale while not self.qin1.empty(): self.qin1.get() if not self.qin2.empty(): pump = float(self.qin2.get()) while not self.qin2.empty(): self.qin2.get() out = int(str(self.reconstruct_secret('output'))) / 100. sock.UDPclient(self.server_addr[self.i][0], self.server_addr[self.i][1], [pump, cons, out]) print('Control output party {}, round {}: {}'.format( self.i, j, out)) self.q4.put([2, out]) # time.sleep(1) #self.recv = {} self.c = 0 self.comr = 0