# Arbitrary length to multiple of block size

I would like to apply CTR mode on a arbitrary length which isn't multiple of block size. Is this possible without applying padding.

In case we apply padding - how does the decryption algorithm know this padding!?

• at least let me know why the down vote! new here!! Sep 21, 2017 at 5:06

In CTR mode, Enc is done as

CT = Enc(k,PT) = Enc(k,ctr) xor PT

The decryption is similar to encryption except you XOR Cipertext(CT) instead of Plaintext(PT).

PT = Dec(k,CT) = Enc(k,ctr) xor CT

So there is no need for plaintext to be multiple of block length and no need of padding because the PT or CT never become the input of the block cipher. Its the counter which is encrypted to generate a random stream and then Xored with plaintext or ciphertext. You can use the required length of generated bit-stream and discard the remaining.

More Details and picture Credit of CTR MODE

• Welcome :) u have to process n=((plaintextLength / blockLength )+ 1) blocks using n ctrs, but u will discard the surplus bits of last block. Sep 21, 2017 at 14:07