-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc15.py
37 lines (26 loc) · 849 Bytes
/
c15.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
32
33
34
35
36
37
from pals import utils
a = b"ICE ICE BABY\x04\x04\x04\x04"
b = b"ICE ICE BABY\x05\x05\x05\x05"
c = b"ICE ICE BABY\x01\x02\x03\x04"
tests = [a, b, c]
for s in tests:
try:
utils.unpad(s)
print('good: {}'.format(s))
except:
print('bad: {}'.format(s))
'''
PKCS#7 padding validation
Write a function that takes a plaintext, determines if it
has valid PKCS#7 padding, and strips the padding off.
The string:
"ICE ICE BABY\x04\x04\x04\x04"
... has valid padding, and produces the result "ICE ICE BABY".
The string:
"ICE ICE BABY\x05\x05\x05\x05"
... does not have valid padding, nor does:
"ICE ICE BABY\x01\x02\x03\x04"
If you are writing in a language with exceptions, like Python
or Ruby, make your function throw an exception on bad padding.
Crypto nerds know where we're going with this. Bear with us.
'''