Skip to content

Commit

Permalink
Update paillier.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mortendahl committed Sep 2, 2019
1 parent 5e4e14f commit a35d655
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions examples/paillier.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ def __init__(self, n, nn, g):
class DecryptionKey:
def __init__(self):
# TODO what do we need?
pass

def keygen(modulus_bitlen):
# TODO
p = tf_big.constant(SOME PRIME)
q = tf_big.constant(SOME PRIME)
def dummy_keygen():
# TODO use fixed large primes
p = tf_big.constant([17])
q = tf_big.constant([19])
n = p * q

g = n + 1
Expand All @@ -29,7 +30,8 @@ def keygen(modulus_bitlen):
return ek, dk

def encrypt(ek, x):
r = tf_big.random.uniform(ek.n, shape=x.shape)
# r = tf_big.random.uniform(ek.n, shape=x.shape)
r = tf_big.convert_to_tensor(tf.constant([[123, 124], [125, 126]])) # TODO
assert r.shape == x.shape, "Shapes are not matching: {}, {}".format(r.shape, x.shape)

gx = tf_big.pow(ek.g, x, ek.nn)
Expand All @@ -39,6 +41,7 @@ def encrypt(ek, x):

def decrypt(dk, c):
# TODO what do we need?
pass

def add(ek, c1, c2):
c = c1 * c2 % ek.nn
Expand All @@ -48,7 +51,7 @@ def mul(ek, c1, x2):
c = tf_big.pow(c1, x2, ek.nn)
return c

ek, dk = keygen(2048)
ek, dk = dummy_keygen()

# TODO(Morten) relace with lin reg computation?

Expand All @@ -65,6 +68,6 @@ def mul(ek, c1, x2):
y = decrypt(dk, c4)

with tf.Session() as sess:
actual = sess.run(tf_big.convert_from_tensor(y))
actual = sess.run(y)
expected = (x1 + x2) * 3
np.testing.assert_array_equal(actual, expected)

0 comments on commit a35d655

Please sign in to comment.