initial la moitié du TP est fait mais commit

This commit is contained in:
boyreau 2026-11-09 18:30:30 +01:00
commit c58e985561
4 changed files with 145 additions and 0 deletions

27
test_ElGamal.py Normal file
View file

@ -0,0 +1,27 @@
from ElGamal import KeyGen, Encrypt_cc, Decrypt_cc, Encrypt_ce, Decrypt_ce, Add_cipher
from sympy import randprime, primitive_root
if __name__ == "__main__":
# On prend le groupe de (randprime - 1)
ordre = randprime(2, 1 << 10)
gen = primitive_root(ordre)
m = 22
pk, sk = KeyGen(gen, ordre)
print(f"Private key: {pk}, public key: {sk}")
cipher = Encrypt_cc(gen, ordre, pk, m)
# print(f"Cipher of {m}: {cipher}")
clear = Decrypt_cc(gen, ordre, sk, cipher)
print(f"Cleartext message : {clear}")
assert clear == m
cipher = 0
clear = 0
cipher = Encrypt_ce(gen, ordre, pk, m)
print(f"Cipher_ce: {cipher}")
clear = Decrypt_ce(gen, ordre, sk, cipher)
print(f"Cleartext_ce: {clear}")
assert clear == m
ciphers = [(1, 1), (1, 2), (1, 3)]
assert Add_cipher(ciphers) == 1 + 2 + 3