Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/elgamal_encryption/unsafe_generator.py
2589 views
1
from sage.all import legendre_symbol
2
3
4
def attack(p, h, c1, c2):
5
"""
6
Returns the Legendre symbol of the message encrypted using an unsafe generator.
7
:param p: the prime used in the ElGamal scheme
8
:param h: the public key
9
:param c1: the ciphertext
10
:param c2: the ciphertext
11
:return: the Legendre symbol
12
"""
13
return int(legendre_symbol(c2, p) // max(legendre_symbol(h, p), legendre_symbol(c1, p)))
14
15