Tout jusqu'à la fonction dépouillement exclue.
This commit is contained in:
parent
c58e985561
commit
6e0e362e7e
2 changed files with 79 additions and 12 deletions
|
|
@ -1,5 +1,16 @@
|
|||
from ElGamal import KeyGen, Encrypt_cc, Decrypt_cc, Encrypt_ce, Decrypt_ce, Add_cipher
|
||||
from sympy import randprime, primitive_root
|
||||
from sympy import primitive_root, randprime
|
||||
|
||||
from ElGamal import (
|
||||
Add_cipher,
|
||||
Decrypt_cc,
|
||||
Decrypt_ce,
|
||||
Encrypt_cc,
|
||||
Encrypt_ce,
|
||||
KeyGen,
|
||||
KeyGen_central,
|
||||
Decrypt_central_cc,
|
||||
Decrypt_central_ce,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# On prend le groupe de (randprime - 1)
|
||||
|
|
@ -25,3 +36,22 @@ if __name__ == "__main__":
|
|||
|
||||
ciphers = [(1, 1), (1, 2), (1, 3)]
|
||||
assert Add_cipher(ciphers) == 1 + 2 + 3
|
||||
|
||||
# Le chiffrement par clé publique est déchiffrable par la clé privée reconstituée.
|
||||
privkeys, pubkey = KeyGen_central(gen, ordre, 2)
|
||||
clear = 12
|
||||
print(f"Clés privées : {privkeys}")
|
||||
print(f"Clé publique : {pubkey}")
|
||||
crypt = Encrypt_cc(gen, ordre, pubkey, clear)
|
||||
assert clear == Decrypt_central_cc(gen, ordre, privkeys, crypt)
|
||||
|
||||
assert clear != Decrypt_cc(
|
||||
gen, ordre, privkeys[0], Encrypt_cc(gen, ordre, pubkey, clear)
|
||||
)
|
||||
assert clear != Decrypt_cc(
|
||||
gen, ordre, privkeys[1], Encrypt_cc(gen, ordre, pubkey, clear)
|
||||
)
|
||||
|
||||
crypt = Encrypt_ce(gen, ordre, pubkey, clear)
|
||||
assert clear == Decrypt_central_ce(gen, ordre, privkeys, crypt)
|
||||
assert clear != Decrypt_central_ce(gen, ordre, [privkeys[0]], crypt)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue