TKK_E32232028/.venv/lib/python3.10/site-packages/tests/test_damgard.py

35 lines
807 B
Python

import pytest
from lightphe.commons.logger import Logger
logger = Logger(module="tests/test_damgard.py")
def test_api():
from lightphe import LightPHE
cs = LightPHE(algorithm_name="Damgard-Jurik", key_size=50)
m1 = 17
m2 = 21
c1 = cs.encrypt(plaintext=m1)
c2 = cs.encrypt(plaintext=m2)
# homomorphic addition
assert cs.decrypt(c1 + c2) == m1 + m2
# homomorphic scalar multiplication
assert cs.decrypt(c1 * m2) == m1 * m2
assert cs.decrypt(c2 * m1) == m1 * m2
assert cs.decrypt(m2 * c1) == m1 * m2
assert cs.decrypt(m1 * c2) == m1 * m2
# unsupported homomorphic operations
with pytest.raises(ValueError):
_ = c1 * c2
with pytest.raises(ValueError):
_ = c1 ^ c2
logger.info("✅ Damgard-Jurik api test succeeded")