cryptopals

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 9fa8aaf36b97dd89bc739755278581048f2f1ed7
parent 9782852d4d776f5896414b4cefbd789ac37384eb
Author: mpizzzle <michael.770211@gmail.com>
Date:   Thu, 26 Oct 2017 20:16:30 +0100

set 2 challenge 15 complete

Diffstat:
Aset2/pkcs7_padding_validation.py | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/set2/pkcs7_padding_validation.py b/set2/pkcs7_padding_validation.py @@ -0,0 +1,18 @@ +from Crypto.Cipher import AES + +def pkcs7_padding(msg): + pad_len = AES.block_size - (len(msg) % AES.block_size) + return msg + ''.join([chr(pad_len) for x in range(pad_len)]) + +def pkcs7_padding_stripper(msg): + for char in msg[:len(msg) - ord(msg[len(msg) - 1]) : -1]: + if char != msg[len(msg) - 1]: + raise Exception("invalid pkcs7 padding") + + return msg[:len(msg) - ord(msg[len(msg) - 1])] + +plaintext = "YELLOW SUBMARINE" + +pad = pkcs7_padding(plaintext) +print pad.encode("hex") +print pkcs7_padding_stripper(pad).encode("hex")