-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge48.py
31 lines (25 loc) · 1.01 KB
/
challenge48.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
28
29
30
31
from common.attacks.pkcs1_5 import PKCS1_5PaddingOracleAttack,\
PKCS1_5PaddingOracle
from common.challenge import MatasanoChallenge
from common.ciphers.pubkey.rsa import RSA
from common.tools.misc import ByteSize
from common.tools.padders import PKCS1_5Padder
class Set6Challenge48(MatasanoChallenge):
STRING = 'Pochoclin!'
RSA_BITS = 768
def expected_value(self):
return self.STRING
def _decrypt(self, ciphertext, oracle):
# See comment on Set6Challenge7.
try:
plaintext = PKCS1_5PaddingOracleAttack(oracle).decrypt(ciphertext)
except Exception:
plaintext = None
return plaintext
def value(self):
rsa = RSA(bits=self.RSA_BITS)
oracle = PKCS1_5PaddingOracle(rsa)
byte_size = ByteSize(rsa.n).value()
padded_string = PKCS1_5Padder(self.STRING).value(size=byte_size)
ciphertext = rsa.encrypt(padded_string)
return self._decrypt(ciphertext, oracle)