35 lines
813 B
Python
35 lines
813 B
Python
import pytest
|
|
from lightphe.commons.logger import Logger
|
|
|
|
logger = Logger(module="tests/test_okamoto.py")
|
|
|
|
|
|
def test_api():
|
|
from lightphe import LightPHE
|
|
|
|
cs = LightPHE(algorithm_name="Okamoto-Uchiyama", 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("✅ Okamoto-Uchiyama api test succeeded")
|