def encrypt_(self, public_key): """This method will encrypt each value in the tensor using Paillier homomorphic encryption. Args: *public_key a public key created using syft.frameworks.torch.he.paillier.keygen() """ inputs = self.child.flatten().tolist() new_child = sy.pool().map(public_key.encrypt, inputs) data = np.array(new_child).reshape(self.child.shape) self.child = data self.pubkey = public_key
def decrypt(self, private_key): """This method will decrypt each value in the tensor, returning a normal torch tensor. =Args: *private_key a private key created using syft.frameworks.torch.he.paillier.keygen() """ if not isinstance(self.child, np.ndarray): return th.tensor(private_key.decrypt(self.child)) inputs = self.child.flatten().tolist() new_child = sy.pool().map(private_key.decrypt, inputs) return th.tensor(new_child).view(*self.child.shape)