Skip to content

Instantly share code, notes, and snippets.

View youben11's full-sized avatar
🏠
Working from home

Ayoub Benaissa youben11

🏠
Working from home
View GitHub Profile
SENTENCE_LENGTH_LIMIT = 5
inferer = Inferer(model)
homomorphic_inferer = hnp.compile_fhe(
inferer.infer,
{
"x": hnp.encrypted_ndarray(bounds=(-1, 1), shape=(SENTENCE_LENGTH_LIMIT, 300))
},
config=hnp.config.CompilationConfig(
context = homomorphic_inferer.create_context()
keys = context.keygen()
def evaluate(sentence):
try:
embedded = encode(sentence)
except KeyError as error:
print("! the word", error, "is unknown")
return
if embedded.shape[0] > SENTENCE_LENGTH_LIMIT:
print(f"! the sentence should not contain more than {SENTENCE_LENGTH_LIMIT} tokens")
return
padded = np.zeros((SENTENCE_LENGTH_LIMIT, 300))
evaluate("Encryption is awesome")
+ the sentence was positive (original: 99.99%, simulated: 99.99%, actual: 99.99%, difference: 0.00%, took: 33.813 seconds)
@youben11
youben11 / bsides22_aes.py
Last active January 5, 2022 17:47
Bsides 2022 Crypto Workshop AES
import os
from Crypto.Cipher import AES
# Can be 16, 24, or 32 bytes
KEY = b"A"*16
############
# ECB mode #
############
aes_ecb = AES.new(KEY, mode=AES.MODE_ECB)
@youben11
youben11 / rlwe_he_scheme.py
Last active April 22, 2024 09:07
Implementation of an homomorphic encryption scheme with numpy based on the ring learning with error problem
"""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