Ejemplo n.º 1
0
 def reconstruct_secret(self, a, m=1):
     res = [[], []]
     for i in range(self.n):
         temp = self.get_broadcast(a + str(i))
         for k in range(m):
             res[k].append(temp[k])
     res1 = []
     for i in range(m):
         res1.append(ss.rec(self.F, res[i]))
     return res1, res
Ejemplo n.º 2
0
    def run(self):

        xinit = [0]
        for i in range(self.iterations):
            if i == 0:
                c1, c2 = [0, 0]
            else:
                [c1, c2], res = self.reconstruct_secret('c' + str(self.name),
                                                        m=2)
            c1 = float(str(c1))
            c2 = float(str(c2))
            if c1 > 1000000:
                c1 = -float(str(ss.rec(self.F, -1 * np.array(res[0]))))
            if c2 > 1000000:
                c2 = -float(str(ss.rec(self.F, -1 * np.array(res[1]))))

#            print('{}: {}'.format(self.name, [float(str(c1))/200.,float(str(c2))/100.]))
            obj1 = lambda x: c1 / 200 * x**2 + c2 / 10000 * x

            obj = lambda x, f=obj1, l=self.obj: l(x) + f(x)

            res = minimize(obj, x0=xinit)  #, bounds=bnds)#, constraints=cons)
            self.x = res['x'][0]

            #print('Result from agent {}: {}'.format(self.name, self.x))
            #            if self.name == '0':
            #                self.server.A1.append([float(str(c1))/200.,float(str(c2))/10000.])
            #            if self.name == '1':
            #                self.server.A2.append([float(str(c1))/200.,float(str(c2))/10000.])
            #            if self.name == '2':
            #                self.server.A3.append([float(str(c1))/200.,float(str(c2))/10000.])

            if self.name == '0':
                self.server.A11.append(self.x)
            if self.name == '1':
                self.server.A22.append(self.x)
            if self.name == '2':
                self.server.A33.append(self.x)
            self.x = int(100 * self.x)
            self.distribute_shares('x' + str(i))
Ejemplo n.º 3
0
 def reconstruct_secret(self, name):
     return ss.rec(self.F, self.get_shares(name))
Ejemplo n.º 4
0
 def reconstruct_secret(self, a):
     res = []
     for i in range(self.n):
         res.append(self.get_broadcast(a + str(i)))
     return ss.rec(self.F, res)
Ejemplo n.º 5
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]]))

          
Ejemplo n.º 6
0
 def reconstruct_secret(F, c):
      return ss.rec(F, c)