This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(f"Simulation result: {h.simulate(x)}") | |
print(f"Plain NumPy result: {func(x)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = np.random.uniform(-1, 1, 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h = hnp.compile_fhe( | |
func, | |
{ | |
'x': hnp.encrypted_ndarray(bounds=(-1, 1), shape=(5,)), | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
weights = np.array([0.1, 0.2, 0.3, 0.4, 0.5]) | |
bias = np.array([0.1]) | |
def sigmoid(x): | |
return 1 / (1 + np.exp(-x)) | |
def func(x): | |
return sigmoid(np.dot(x, weights) + bias) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hnumpy as hnp | |
import numpy as np |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A basic homomorphic encryption scheme inspired from BFV https://eprint.iacr.org/2012/144.pdf | |
You can read my blog post explaining the implementation details here: https://www.ayoub-benaissa.com/blog/build-he-scheme-from-scratch-python/ | |
Disclaimer: This implementation doesn’t neither claim to be secure nor does it follow software engineering best practices, | |
it is designed as simple as possible for the reader to understand the concepts behind homomorphic encryption schemes. | |
""" | |
import numpy as np | |
from numpy.polynomial import polynomial as poly |
NewerOlder