DISCLAIMER: This is a proof-of-concept implementation. It does not represent a remotely product ready implementation or follow proper conventions for security, convenience, or scalability. It is part of a broader proof-of-concept demonstrating the vision of the OpenMined project, its major moving parts, and how they might work together.
In [10]:
from syft.he.paillier import KeyPair, PaillierTensor
from syft import TensorBase
import numpy as np
In [11]:
pubkey,prikey = KeyPair().generate()
In [12]:
x = PaillierTensor(pubkey, np.array([1, 2, 3, 4, 5.]))
In [15]:
x.decrypt(prikey)
Out[15]:
In [20]:
(x+x[0]).decrypt(prikey)
Out[20]:
In [21]:
(x*5).decrypt(prikey)
Out[21]:
In [22]:
(x+x/5).decrypt(prikey)
Out[22]:
In [23]:
pubkey,prikey = KeyPair().generate()
In [24]:
x = PaillierTensor(pubkey, np.array([1, 2, 3, 4, 5.]))
In [25]:
pubkey_str = pubkey.serialize()
prikey_str = prikey.serialize()
In [26]:
pubkey2,prikey2 = KeyPair().deserialize(pubkey_str,prikey_str)
In [27]:
prikey2.decrypt(x)
Out[27]:
In [28]:
y = PaillierTensor(pubkey,(np.ones(5))/2)
In [29]:
prikey.decrypt(y)
Out[29]:
In [30]:
import pickle
In [31]:
y_str = pickle.dumps(y)
In [32]:
y2 = pickle.loads(y_str)
In [34]:
prikey.decrypt(y2)
Out[34]:
In [ ]: