Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (dehelloo):

I want do an AES CBC decryption in Python without padding but I keep getting an error.

OpenStudy (dehelloo):

from Crypto.Cipher import AES BS = 16 pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) unpad = lambda s : s[0:-ord(s[-1])] class AESCipher: def __init__( self, key ): self.key = key def encrypt( self, raw ): raw = pad(raw) iv = raw[:16] raw=raw[16:] #iv = Random.new().read( AES.block_size ) cipher = AES.new( self.key, AES.MODE_CBC, iv ) return ( iv + cipher.encrypt( raw ) ).encode("hex") def decrypt( self, enc ): iv = enc[:16] enc= enc[16:] cipher = AES.new(self.key, AES.MODE_CBC, iv ) return unpad(cipher.decrypt( enc)) mode = AES.MODE_CBC key = "blahahahblah ciphertext = blahblahblah key=key[:32] decryptor = AESCipher(key) decryptor.__init__(key) plaintext = decryptor.decrypt(ciphertext) print plaintext

OpenStudy (dehelloo):

Would I have to decode tbe hex value before decryption?

OpenStudy (dehelloo):

126 Bit

OpenStudy (chantysquirrel1129**):

.....

OpenStudy (dehelloo):

above and beyond my question to unforeseen extents thanks so much mate phuarkin hell

OpenStudy (dehelloo):

thanks so much

OpenStudy (chantysquirrel1129**):

YOU'RE WELCOME DUDE.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!