-1

I am implementing a primitive block cipher. However, the implementation is such that the size of the ciphertext may differ from the size of plaintext. I need to know how I can calculate the size of the ciphertext that is formed after encoding. strlen(char *) will not work since the ciphertext may contain multiple '\n' characters. Is there any work-around this problem?

sidharth sharma
  • 3,025
  • 6
  • 23
  • 20
  • 1
    strlen has no problem with embedded '\n'. Do you mean embedded '\0' characters? – Klas Lindbäck Feb 01 '12 at 17:22
  • 1
    I don't understand - if you are implementing the cipher, how can you not know how big the output block is? If you mean 'how can I parse out the blocks on decoding', you will have to implement some protocol to wrap the blocks. – Martin James Feb 01 '12 at 17:24

1 Answers1

2

Your encoding function should return the size, it's the one and only entity that knows it. Implementing a separate function to "find out the size" would mean reimplementing half of the algorithm.

So if in your encoding function you have something like this:

while (...)
    buf[i++] = stuff;

You should return i.

cnicutar
  • 178,505
  • 25
  • 365
  • 392