0

I am modifying a python script. There is a function that decode a string, but it gives me the error that the data passed to decrypt isn't a multiple of 8. I tried to add it the bytes it needs, but after i don't know how to remove them before return the object.

This is the function:

def plain(value, key):

    length = 8 - (len(value) % 8)
    value += chr(length)*length
    obj= Crypto.Cipher.Blowfish.new(
        key, Crypto.Cipher.Blowfish.MODE_ECB).decrypt(
            value.decode('string_escape'))
    return obj

I can't change the mode of decrypt because the date it's cripted by another script of which I haven't the sources.

How can I return the correct obj without the extra bytes that I added before the decript?

Thanks a lot :)

Vitto
  • 361
  • 3
  • 17

1 Answers1

0

You should not add padding at decryption time, it is added at encryption time to make the plaintext a multiple of the block length.

If your ciphertext value is not a multiple of the block length, either it was not encrypted with the same algorithm or parameters, or it doesn't contain what you think it does.

My guess would be that it is an hexadecimal string or a base64 encoded string while the decrypt method accepts a byte string.

Yolanda Ruiz
  • 686
  • 4
  • 7