0
$\begingroup$

A message has 2003 characters, encrypted using a block cipher of 64 bits. What is the size of the padding and the number of blocks?

I tried this, but I'm sure it's not the right thing:

  • 2003 mod 64 = 19, this is the number of bits that needs padding.
  • 2003 / 64 = 31, this is the number of complete blocks, this + 1 = 32 is the total number of blocks.
$\endgroup$
  • 2
    $\begingroup$ @poncho Presumably a character is supposed to have 8 bits. So you need to either compute 2003 * 8 % 64 (in bits) or 2003 % 8 (in bytes). $\endgroup$ – CodesInChaos Nov 30 '16 at 18:10
  • $\begingroup$ @CodesInChaos: sorry about that; somehow, I read that as '2003 bits'... $\endgroup$ – poncho Nov 30 '16 at 18:29
2
$\begingroup$

As written, this exercise is ambiguous, since we don't know how many bits make one character, or even if this number is constant or not. (For e.g. Unicode text using the UTF-8 encoding, it's not — one character can take up between 1 to 4 bytes, or 8 to 32 bits.)

However, if we assume that one character = one byte = 8 bits, then the message has 2003 × 8 = 16024 bits. This amounts to 250 (= 16000 / 64) full 64-bit cipher blocks, and 24 bits (= 3 bytes) left over, for a total of 251 blocks (= 251 × 64 = 16064 bits) after padding.

(A perhaps simpler way to calculate this is to note that 64 bits = 8 bytes, and that 2000 is a multiple of 8. Thus, the message has 2000 / 8 = 250 full blocks and 3 extra bytes, giving a total of 2008 bytes after 5 padding bytes have been appended to round the length up to the next multiple of 8 bytes.)

$\endgroup$
  • 1
    $\begingroup$ Assuming ECB mode of operation, or CBC mode of operation without ciphertext stealing. $\endgroup$ – Maarten Bodewes Nov 30 '16 at 22:24
  • $\begingroup$ ...or, more generally, any mode of operation that requires padding the message to a whole number of cipher blocks. $\endgroup$ – Ilmari Karonen Nov 30 '16 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.