Pycrypto
James Stroud
jstroud at ucla.edu
Fri Jun 16 16:56:44 EDT 2006
Laszlo Nagy wrote:
>
>> Not in this implementation:
>> py> from Crypto.Cipher import AES
>> py> crypt = AES.new('abcdefghijklmnop', AES.MODE_CBC)
>> py> c = crypt.encrypt('1')
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>> ValueError: Input strings must be a multiple of 16 in length
>>
>
> This is strange. In theory, any ECB mode cipher can be used to create a
> CBC mode cipher.
> AFAIK, CBC creates one encrypted block, and uses the one byte from the
> plain text to xor it
> with the last encrypted byte. Finally it shifts the encrypted block.
> This way each input byte will
> have a corresponding output byte, and there is no size limit for the
> plain text.
>
> Frankly, I could write the CBC mode cipher using the (already existing)
> ECB cipher. Why we have this limitation?
>
> Laszlo
>
>
CBC mode is cipher block chaining, so it still works as a block cipher,
which means that it must be that len(text) % block_size == 0. In other
words, CBC does not shift by one byte but by block_size bytes. See:
http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
More information about the Python-list
mailing list