-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path46.py
27 lines (19 loc) · 855 Bytes
/
46.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import base64
from .. import rsa
def gen_parity_oracle():
"""Returns (parity_oracle_fn, ciphertext, pub_key)."""
secret = base64.b64decode("VGhhdCdzIHdoeSBJIGZvdW5kIHlvdSBkb24ndCBwbGF5IGF"
"yb3VuZCB3aXRoIHRoZSBGdW5reSBDb2xkIE1lZGluYQ==")
r = rsa.Rsa(e=3, bits=1024)
ciphertext = r.encrypt_bytes(secret)
def parity_oracle(c):
p = r.decrypt_bytes(c)
return p[-1] % 2 == 0
return parity_oracle, ciphertext, r.public_key()
parity_oracle_fn, ciphertext, (e, n) = gen_parity_oracle()
plaintext = rsa.attack_parity_oracle(parity_oracle_fn, ciphertext, e, n,
hollywood=True)
plaintext = plaintext.decode("ascii")
print(f"Recovered: '{plaintext}'")
assert plaintext == \
"That's why I found you don't play around with the Funky Cold Medina"