def bench_ipe(n, group_name, iter = 10, simulated = False, M = 1): setup_a = time.time() (pp, sk) = ipe.setup(n, group_name, simulated) setup_b = time.time() L = [] for index in range(iter): x = [random.randint(0, M) for i in range(n)] y = [random.randint(0, M) for i in range(n)] keygen_a = time.time() skx = ipe.keygen(sk, x) keygen_b = time.time() encrypt_a = time.time() cty = ipe.encrypt(sk, y) encrypt_b = time.time() ctsize = get_ct_size(cty) decrypt_a = time.time() prod = ipe.decrypt(pp, skx, cty, M*M*n) decrypt_b = time.time() L.append((keygen_b - keygen_a, encrypt_b - encrypt_a, decrypt_b - decrypt_a, ctsize)) print("raw runtimes for each iteration: ", L) return (setup_b - setup_a, list_tuple_mean(L))
def bench_ipe(n, group_name, iter=10, simulated=False, M=1): setup_a = time.time() (pp, sk) = ipe.setup(n, group_name, simulated) setup_b = time.time() L = [] for index in range(iter): x = [random.randint(0, M) for i in range(n)] y = [random.randint(0, M) for i in range(n)] keygen_a = time.time() skx = ipe.keygen(sk, x) keygen_b = time.time() encrypt_a = time.time() cty = ipe.encrypt(sk, y) encrypt_b = time.time() ctsize = get_ct_size(cty) decrypt_a = time.time() prod = ipe.decrypt(pp, skx, cty, M * M * n) decrypt_b = time.time() L.append((keygen_b - keygen_a, encrypt_b - encrypt_a, decrypt_b - decrypt_a, ctsize)) print("raw runtimes for each iteration: ", L) return (setup_b - setup_a, list_tuple_mean(L))
def ipe_decry_m(xvec,yvec,dev): (pp, sk) = ipe.setup(len(xvec)) skx = ipe.keygen(sk, xvec) cty = ipe.encrypt(sk, yvec) prod = ipe.decrypt(pp, skx, cty, M*M*n) m=prod/(len(xvec)*dev*dev) return m
def ipe_hamming(x, y): (pp, sk) = ipe.setup(n) skx = ipe.keygen(sk, x) print("the skx is:", skx) cty = ipe.encrypt(sk, y) print("the cty is:", cty) prod = ipe.decrypt(pp, skx, cty, M * M * n) print("<X',Y'> :", prod) return prod
def encryptL(sk, x): """ Performs the left-encrypt algorithm, where sk is the secret key and x is an integer in the range [0,n-1]. """ (n, _, sk_ipe) = sk assert x in range(n), "Input is outside of range" u = [0] * n u[x] = 1 skx = ipe.keygen(sk_ipe, u) return skx
def test_ipe(): """ Runs a test on IPE for toy parameters. """ n = 10 M = 20 x = [random.randint(0, M) for i in range(n)] y = [random.randint(0, M) for i in range(n)] checkprod = sum(map(lambda i: x[i] * y[i], range(n))) (pp, sk) = ipe.setup(n) skx = ipe.keygen(sk, x) cty = ipe.encrypt(sk, y) prod = ipe.decrypt(pp, skx, cty, M * M * n) assert prod == checkprod, "Failed test_ipe"
def test_ipe(): """ Runs a test on IPE for toy parameters. """ n = 10 M = 20 x = [random.randint(0, M) for i in range(n)] y = [random.randint(0, M) for i in range(n)] checkprod = sum(map(lambda i: x[i] * y[i], range(n))) (pp, sk) = ipe.setup(n) skx = ipe.keygen(sk, x) cty = ipe.encrypt(sk, y) prod = ipe.decrypt(pp, skx, cty, M*M*n) assert prod == checkprod, "Failed test_ipe"
def test_ipe(): """ Runs a test on IPE for toy parameters. """ n = 10 M = 10 x = [random.randint(-M, M) for i in range(n)] print(x) y = [random.randint(-M, M) for i in range(n)] # checkprod = sum(map(lambda i: x[i] * y[i], range(n))) print(y) (pp, sk) = ipe.setup(n) skx = ipe.keygen(sk, x) cty = ipe.encrypt(sk, y) prod = ipe.decrypt(pp, skx, cty, M * M * n) print(prod)
def ipe_hamming(x,y): (pp, sk) = ipe.setup(n) keya=datetime.datetime.now() skx = ipe.keygen(sk, x) keyb=datetime.datetime.now() f.write(str(keyb-keya)+"---") #time 3 ena=datetime.datetime.now() cty = ipe.encrypt(sk, y) enb=datetime.datetime.now() f.write(str(enb-ena)+"---") dea=datetime.datetime.now() prod = ipe.decrypt(pp, skx, cty, M*M*n) deb=datetime.datetime.now() f.write(str(deb-dea)+"---") return prod
def ipe_decry_m(xvec, yvec, dev): (pp, sk) = ipe.setup(len(xvec)) kea = datetime.datetime.now() skx = ipe.keygen(sk, xvec) keb = datetime.datetime.now() f.write(str(keb - kea) + "---") # time ena = datetime.datetime.now() cty = ipe.encrypt(sk, yvec) enb = datetime.datetime.now() f.write(str(enb - ena) + "---") # time dea = datetime.datetime.now() prod = ipe.decrypt(pp, skx, cty, M * M * n) deb = datetime.datetime.now() f.write(str(deb - dea) + "---") # time m = prod / (len(xvec) * dev * dev) return m
def encrypt_token(self, coeffs): return ipe.keygen(self.sk, coeffs)
for i in range(inorout): des = [] select = int(input("please input the data your want 1 or 2 :")) d = load(select) f = pca(d) lowdata = display(select) for i in lowdata.tolist(): for j in i: des.append(j) print("x vectory is ", des) if select == 1: xarr = [] x = xvectory(des) for i in x: xarr.append(int(i)) skx = ipe.keygen(sk, xarr) ll = 0 tt = [] for i in xarr: ll += 1 tt.append(i) if ll / 10 == 0: print(tt) tt = [] print("x' vectory is ", xarr) if select == 2: yarr = [] y = yvectory(des) for i in y: yarr.append(int(i)) cty = ipe.encrypt(sk, yarr)