Skip to content

Commit

Permalink
challenge 15 set 2
Browse files Browse the repository at this point in the history
  • Loading branch information
appills committed Feb 18, 2024
1 parent 6d33366 commit 64633c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/padding.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ def strip_pkcs7_pad(block, block_size=16):
if last_byte > 0 and last_byte < block_size:
return block[0:(-1*last_byte)]
return block

def throw_bad_padding(block, block_size=16):
block_len = len(block)
if block_len % block_size == 0:
# check last byte
last_byte = block[-1]
pad_bytes = block[(-1*last_byte):]
for pad_byte in pad_bytes:
if pad_byte != last_byte:
raise Exception("Bad padding")

13 changes: 11 additions & 2 deletions tests/test_set2.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,18 @@ def test_set2_challenge14(self):
plaintext = b''.join([i.to_bytes() for i in plaintext_bytes])
self.assertEqual(expected, plaintext) # cool af

return
def test_set2_challenge15(self):
return
cases = [
b'ICE ICE BABY\x04\x04\x04\x04',
b'ICE ICE BABY\x05\x05\x05\x05',
b'ICE ICE BABY\x01\x02\x03\x04'
]
for c in cases:
try:
padding.throw_bad_padding(c)
except Exception as e:
self.assertRaises(Exception, e)

def test_set2_challenge16(self):
return

Expand Down

0 comments on commit 64633c6

Please sign in to comment.