Skip to content

Commit 31bc585

Browse files
committed
Add comments in example.py
1 parent 2e1d64d commit 31bc585

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

example.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
import requests
77

8-
8+
# This function has to be implemented and will be passed to the PaddingOracle constructor.
9+
# It gets a hex encoded cipher text and has to return True if it can be decrypted successfully,
10+
# False otherwise.
11+
#
12+
# Here is an example implementation that I used for P.W.N. CTF 2018.
913
def oracle(cipher_hex):
1014
headers = {'Cookie': 'vals={}'.format(cipher_hex)}
1115
r = requests.get('http://converter.uni.hctf.fun/convert', headers=headers)
@@ -17,9 +21,11 @@ def oracle(cipher_hex):
1721
return False
1822

1923

24+
# Instantiate the helper with the oracle implementation
2025
o = PaddingOracle(oracle, max_retries=-1)
2126

22-
# Decrypt the plain text
27+
# Decrypt the plain text.
28+
# To make the guesswork faster, use an alphabet optimized for JSON data.
2329
cipher = 'b5290bd594ba08fa58b1d5c7a19f876c338191a51eeeac94c2b434bdb8adbfb8596f996d6eddca93c059e3dc35f7bef36b57a5611250ec4528c11e1573799d2178c54c034b9ea8fda8ae9a4a41c67763'
2430
plain, padding = o.decrypt(cipher, optimized_alphabet=json_alphabet())
2531
print('Plaintext: {}'.format(plain))

0 commit comments

Comments
 (0)