Example #1
0
def decrypt_matrix(private_key: PaillierPrivateKey, A):
    if len(A.shape) == 1:
        A = np.expand_dims(A, axis=0)

    decrypt_A = []
    for i in range(len(A)):
        row = []
        for j in range(len(A[i])):
            if len(A.shape) == 3:
                row.append([
                    private_key.decrypt(A[i, j, k])
                    for k in range(len(A[i][j]))
                ])
            else:
                row.append(private_key.decrypt(A[i, j]))

        decrypt_A.append(row)
    return np.array(decrypt_A, dtype=np.float64)
Example #2
0
def decrypt_matrix(private_key: PaillierPrivateKey, A):
    """
    decrypt matrix with dim 1, 2 or 3
    :param private_key:
    :param A:
    :return:
    """
    if len(A.shape) == 1:
        A = np.expand_dims(A, axis=0)

    decrypt_A = []
    for i in range(len(A)):
        row = []
        for j in range(len(A[i])):
            if len(A.shape) == 3:
                row.append([private_key.decrypt(A[i, j, k]) for k in range(len(A[i][j]))])
            else:
                row.append(private_key.decrypt(A[i, j]))
        decrypt_A.append(row)

    result = np.array(decrypt_A, dtype=np.float64)
    if len(A.shape) == 1:
        result = np.squeeze(result, axis=0)
    return result
Example #3
0
def decrypt_array(private_key: PaillierPrivateKey, X):
    decrypt_x = []
    for i in range(X.shape[0]):
        elem = private_key.decrypt(X[i])
        decrypt_x.append(elem)
    return np.array(decrypt_x, dtype=np.float64)
Example #4
0
def decrypt_scalar(private_key: PaillierPrivateKey, x):
    return private_key.decrypt(x)
def encrypt_array(private_key: PaillierPrivateKey, X):
    decrpt_X = Parallel(n_jobs=N_JOBS)(delayed(private_key.decrypt())(num)
                                       for num in X)
    return np.array(decrpt_X)