Exemplo n.º 1
0
    def encrypt(self, x, same_type=False):
        """Encrypts x. X can be either an encrypted int or a numpy
        vector/matrix/tensor."""
        if (type(x) == int or type(x) == float or type(x) == np.float64):
            if (same_type):
                return NotImplemented
            return Float(self, x)
        elif (type(x) == TensorBase):
            if (x.encrypted or same_type):
                return NotImplemented
            return BVTensor(self, x.data)
        elif (type(x) == np.ndarray):
            sh = x.shape
            x_ = x.reshape(-1)
            out = list()
            for v in x_:
                out.append(Float(self, v))
            if (same_type):
                return np.array(out).reshape(sh)
            else:
                return BVTensor(self, np.array(out).reshape(sh))
        else:
            print("format not recognized:" + str(type(x)))
            return NotImplemented

        return self.pk.encrypt(x)
Exemplo n.º 2
0
    def test_add(self):
        a = BVTensor(self.keys.pk(), np.asarray([40,2]), True, self.keys.sk())

        # integers only, for now!
        b = a + 2
        p = self.keys.sk().decrypt(b)
        print(p)
Exemplo n.º 3
0
 def test_mul_by_scalarinv(self):
     a = BVTensor(self.keys.pk, [21], False, self.keys.sk)
     b = a * 2
Exemplo n.º 4
0
 def test_add(self):
     a = BVTensor(self.keys.pk, [40,2], False, self.keys.sk)
     b = a + 2.0
Exemplo n.º 5
0
 def test_mul_by_scalarinv(self):
     a = BVTensor(self.keys.pk(), np.asarray([21]), True, self.keys.sk)
     b = a * 2
Exemplo n.º 6
0
 def test_add(self):
     a = BVTensor(self.keys.pk(), np.asarray([40, 2]), True, self.keys.sk)
     b = a + 2.0
Exemplo n.º 7
0
    def test_mul_by_scalar(self):
        a = BVTensor(self.keys.pk(), np.asarray([21]), True, self.keys.sk())

        # Integers only, for now!
        b = a * 2