def getRandomInp(): key = paillier.keygen() privk = key.private_key pubk = key.public_key a = [ random.randint(-20000, 20000), random.randint(-200000, 20000), random.randint(-20000, 20000) ] # a = [1915,1383] # for i in range(15): # x = random.randint(-31,-1) # a.append(x) # a = np.array(a) ans = np.argmax(np.array(a)) # print(a) inp = [] for num in a: inp.append(paillier.encrypt(mpz(num), pubk)) inp = np.array(inp) return inp, pubk, privk, ans, a
from paillierlib import paillier as pal from gmpy2 import mpz m1 = mpz(10) m2 = mpz(1) m3 = mpz(0) m4 = mpz(2000) m5 = mpz(4000) m6 = mpz(999) key_pair = pal.keygen() c1 = pal.encrypt(m1, key_pair.public_key) c2 = pal.encrypt(m2, key_pair.public_key) c3 = pal.encrypt(m3, key_pair.public_key) c4 = pal.encrypt(m4, key_pair.public_key) c5 = pal.encrypt(m5, key_pair.public_key) c6 = pal.encrypt(m6, key_pair.public_key) def test_additive(): assert pal.decrypt(c1 + c2, key_pair.private_key) == 11 assert pal.decrypt(c1 + c2 + c1, key_pair.private_key) == 21 assert pal.decrypt(c1 + c2 + c1 + c2, key_pair.private_key) == 22 assert pal.decrypt(c6 + c2, key_pair.private_key) == 1000 assert pal.decrypt(c5 + c6 + c5, key_pair.private_key) == 8999 assert pal.decrypt(c3 + c3 + c3 + c3 + c3, key_pair.private_key) == 0 def test_sub(): assert pal.decrypt(c2 - c3, key_pair.private_key) == 1 assert pal.decrypt(c2 - c3 - c3 - c3, key_pair.private_key) == 1
import random from gmpy2 import mpz from tqdm import tqdm from veu11 import compare from paillierlib import paillier key_pair = paillier.keygen(1024) l = 20 for i in tqdm(range(5)): a = random.randint(0, pow(2, l) - 1) b = random.randint(0, pow(2, l) - 1) encrypted_a = paillier.encrypt(mpz(a), key_pair.public_key) encrypted_b = paillier.encrypt(mpz(b), key_pair.public_key) for j in range(20): _, out = compare(encrypted_a, encrypted_b, l, key_pair.public_key, key_pair.private_key) if a < b and out == 0: print("Test Failed") elif a > b and out == 1: print("Test Failed")
import numpy as np from paillierlib import paillier from gmpy2 import mpz, mpfr import random import copy from tqdm import tqdm from POIS_deepcrypt.Naiive_Bayes.ArgMax import handler_A from hyperplane import dot, compute_dot, encrypt_weights inp_vec = np.random.randint(low=0, high=10000, size=10).tolist() weights = np.random.randint(low=0, high=10000, size=(5, 10)) key_pair = paillier.keygen() encrypted_weights = encrypt_weights(weights, key_pair.public_key) encrypted_vec = compute_dot(inp_vec, encrypted_weights, key_pair.public_key) index = handler_A(encrypted_vec, 30, key_pair.public_key, key_pair.private_key) inp1_vec = np.asarray(inp_vec).reshape(1, 10) index1 = np.argmax(np.dot(inp1_vec, weights.T)) if index1 == index: print("Success") else: print(index, index1)
from paillierlib import paillier import numpy as np from gmpy2 import mpz import POIS_deepcrypt.goldwasser_micali as gm k = paillier.keygen() a = np.array([k]) np.save("./PAILLIER_KEY", a) g = gm.generate_key(1024) b = np.array([g]) np.save("./GM_KEY", b)