Update README.md

phe snippet
This commit is contained in:
Sefik Ilkin Serengil 2025-03-08 20:20:58 +00:00 committed by GitHub
parent 72dc780abc
commit 76676ac51c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -381,13 +381,12 @@ Even though vector embeddings are not reversible to original images, they still
```python
from lightphe import LightPHE
# define a plain vectors for source and target
alpha = DeepFace.represent("img1.jpg")[0]["embedding"] # user tower
beta = DeepFace.represent("target.jpg")[0]["embedding"] # item tower
# build an additively homomorphic cryptosystem (e.g. Paillier) on-prem
cs = LightPHE(algorithm_name = "Paillier", precision = 19)
# define a plain vector for source
alpha = DeepFace.represent("img1.jpg")[0]["embedding"] # user tower
# export keys
cs.export_keys("secret.txt"); cs.export_keys("public.txt", public=True)
@ -400,6 +399,9 @@ del cs, alpha
# restore the cryptosystem in cloud with only public key
cloud_cs = LightPHE(algorithm_name = "Paillier", precision = 19, key_file = "public.txt")
# define a plain vector for target
beta = DeepFace.represent("target.jpg")[0]["embedding"] # item tower
# dot product of encrypted and plain embedding pair
encrypted_cosine_similarity = encrypted_alpha @ beta