Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/elgamal_encryption/nonce_reuse.py
2589 views
1
def attack(p, m, c1, c2, c1_, c2_):
2
"""
3
Recovers a secret plaintext encrypted using the same nonce as a previous, known plaintext.
4
:param p: the prime used in the ElGamal scheme
5
:param m: the known plaintext
6
:param c1: the ciphertext of the known plaintext
7
:param c2: the ciphertext of the known plaintext
8
:param c1_: the ciphertext of the secret plaintext
9
:param c2_: the ciphertext of the secret plaintext
10
:return: the secret plaintext
11
"""
12
s = c2 * pow(m, -1, p) % p
13
m_ = c2_ * pow(s, -1, p) % p
14
return int(m_)
15
16