예제 #1
0
def test_decrypted_encrypted_sub():

    pub, pri = sy.keygen()

    x_tensor = torch.Tensor([1, 2, 3])
    x = x_tensor.encrypt(pub)

    y_tensor = torch.Tensor([2, 2, 2])
    y = y_tensor.encrypt(pub)

    z = (x_tensor - y).decrypt(pri)

    assert ((x_tensor - y_tensor) == z).all()
예제 #2
0
def test_encrypt_and_decrypt():
    """
    Test the basic paillier encrypt/decrypt functionality
    """

    pub, pri = sy.keygen()

    x_tensor = torch.Tensor([1, 2, 3])
    x = x_tensor.encrypt(pub)

    y = x.decrypt(pri)

    assert (x_tensor == y).all()
예제 #3
0
def test_decrypted_encrypted_add():
    """
    Test the addition of a decrypted and encrypted value
    """

    pub, pri = sy.keygen()

    x_tensor = torch.Tensor([1, 2, 3])
    x = x_tensor.encrypt(pub)

    y = (x_tensor + x).decrypt(pri)

    assert ((x_tensor + x_tensor) == y).all()
예제 #4
0
def test_encrypted_decrypted_matmul():

    pub, pri = sy.keygen()

    x_tensor = torch.tensor([1, 2, 3])
    x = x_tensor.encrypt(pub)

    y_tensor = torch.tensor([2, 2, 2])
    y = y_tensor.encrypt(pub)

    z = (x.mm(y_tensor)).decrypt(pri)

    assert (z == 12).all()
예제 #5
0
def test_decrypted_encrypted_matmul():

    pub, pri = sy.keygen()

    x_tensor = torch.Tensor([[1, 2, 3]])
    x = x_tensor.encrypt(pub)

    y_tensor = torch.Tensor([[2], [2], [2]])
    y = y_tensor.encrypt(pub)

    z = (x_tensor.mm(y)).decrypt(pri)

    assert ((x_tensor.mm(y_tensor)) == z).all()
예제 #6
0
def test_decrypted_encrypted_sub():

    pub, pri = sy.keygen()

    x_tensor = torch.Tensor([1, 2, 3])
    x = x_tensor.encrypt(protocol="paillier", public_key=pub)

    y_tensor = torch.Tensor([2, 2, 2])
    y = y_tensor.encrypt(protocol="paillier", public_key=pub)

    z = (x_tensor - y).decrypt(protocol="paillier", private_key=pri)

    assert ((x_tensor - y_tensor) == z).all()
예제 #7
0
def test_encrypted_decrypted_add():
    """
    Test addition of an encryptd and decrypted value
    """

    pub, pri = sy.keygen()

    x_tensor = torch.Tensor([1, 2, 3])
    x = x_tensor.encrypt(protocol="paillier", public_key=pub)

    y = (x + x_tensor).decrypt(protocol="paillier", private_key=pri)

    assert ((x_tensor + x_tensor) == y).all()
예제 #8
0
def test_decrypted_encrypted_matmul():

    pub, pri = sy.keygen()

    x_tensor = torch.Tensor([[1, 2, 3]])
    x = x_tensor.encrypt(protocol="paillier", public_key=pub)

    y_tensor = torch.Tensor([[2], [2], [2]])
    y = y_tensor.encrypt(protocol="paillier", public_key=pub)

    z = (x_tensor.mm(y)).decrypt(protocol="paillier", private_key=pri)

    assert ((x_tensor.mm(y_tensor)) == z).all()
예제 #9
0
def test_encrypted_decrypted_matmul():

    pub, pri = sy.keygen()

    x_tensor = torch.tensor([1, 2, 3])
    x = x_tensor.encrypt(protocol="paillier", public_key=pub)

    y_tensor = torch.tensor([2, 2, 2])
    y = y_tensor.encrypt(protocol="paillier", public_key=pub)

    z = (x.mm(y_tensor)).decrypt(protocol="paillier", private_key=pri)

    assert (z == 12).all()
예제 #10
0
from syft.frameworks.torch.tensors.interpreters.paillier import PaillierTensor
from phe.paillier import EncryptedNumber, PaillierPublicKey
from flask import Flask, request, jsonify
import json
import psycopg2
import torch
import syft as sy
import numpy as np
import tenseal as ts
conn = psycopg2.connect("dbname=basic-provider user=postgres password=postgres")
hook = sy.TorchHook(torch)
pub, pri = sy.keygen()

if __name__ == '__main__':
    cur = conn.cursor()
    command = "SELECT numero_ruc, duracion, business_size, lat, lon "
    command += "FROM RUCs r INNER JOIN businesscategory b on CAST(r.actividad_economica as INT )=b.id_actividad "
    command += "WHERE b.business_category = 'RESTAURANTE'"
    cur.execute(command)
    restaurants = cur.fetchall()

    index = 2

    cur.close()
    conn.close()
    array = np.array(restaurants)
    new_array = array[:,index]
    new_array = [[e] for e in new_array]
    array = np.delete(array, index, 1)
    array = array.tolist()