예제 #1
0
 def Obliviously_Send(self, M0,M1,num_of_OT, lam):
     conn = self.conn
     for i in xrange(num_of_OT):
         print i
         r=random.randrange(self.q)
         c=random.randrange(self.q)
         conn.send(str(c))
         pk0 = conn.recv(200) #you should receive pk0 from the receiver via the sender_receiver channel
         pk0r=modifiedPower(int(pk0),r,self.q)
         gr=modifiedPower(self.g,r,self.q)
         r0=(hashlib.sha512(str(pk0r)+str(0)).digest())
         r00=str(r0)* int(math.ceil(num_of_OT/len(r0))+1)
         cr=modifiedPower(c,r,self.q)
         gcd=inv=-1
         while gcd != 1 and inv <= 0 :
             gcd,inv,k = euclid(pk0r,self.q)
         pk1r=cr*inv%self.q
         r1=(hashlib.sha512(str(pk1r)+str(1)).digest())
         r10=str(r1) * int(math.ceil(num_of_OT/len(r1))+1)
         E0=bin(int(M0[i])^ord(r00[i]))[2:].zfill(lam)
         E1=bin(int(M1[i])^ord(r10[i]))[2:].zfill(lam)
         conn.send(str(gr))
         conn.send(str(E0))
         conn.send(str(E1))
     return True
예제 #2
0
 def obliviouslyReceive(self, X,number_of_OT, lam):
     client_socket = self.s
     final = []
     k=random.randrange(1,self.q+1);
     for i in xrange(number_of_OT):
         print i
         c=int(client_socket.recv(200))
         pk=list()
         #print pk
         pk.insert(X[i],modifiedPower(self.g,k,self.q))
         gcd=inv=-1
         while gcd != 1 and inv <= 0 :
             gcd,inv,ui = euclid(modifiedPower(self.g,k,self.q),self.q)
         pk.insert(1-X[i],(c*inv)%self.q)
         client_socket.send(str(pk[0]))
         gr=client_socket.recv(200)
         M0=client_socket.recv(lam)
         M1=client_socket.recv(lam)
         E=[M0,M1]
         grk = modifiedPower(int(gr),k,self.q)
         r_guess0=(hashlib.sha512(str(grk)+str(X[i])).digest())
         f=str(r_guess0)* int(math.ceil(number_of_OT/len(r_guess0))+1)
         T=int(E[X[i]],2)^ord(f[i])
         final.append(T)
     return final