-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
24 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
def attack(p, m1, c1, d1, c2, d2): | ||
def attack(p, m, c1, c2, c1_, c2_): | ||
""" | ||
Recovers a secret plaintext encrypted using the same nonce as a previous, known plaintext. | ||
:param p: the prime used in the ElGamal scheme | ||
:param m1: the known plaintext | ||
:param m: the known plaintext | ||
:param c1: the ciphertext of the known plaintext | ||
:param d1: the ciphertext of the known plaintext | ||
:param c2: the ciphertext of the secret plaintext | ||
:param d2: the ciphertext of the secret plaintext | ||
:param c2: the ciphertext of the known plaintext | ||
:param c1_: the ciphertext of the secret plaintext | ||
:param c2_: the ciphertext of the secret plaintext | ||
:return: the secret plaintext | ||
""" | ||
return int(pow(d1, -1, p) * d2 * m1 % p) | ||
s = c2 * pow(m, -1, p) % p | ||
m_ = c2_ * pow(s, -1, p) % p | ||
return int(m_) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters