I am taking a cryptography class and our first homework is to implement a 32-bit block cipher. I implemented a simple block-cipher that uses CBC. Currently, my implementation reads both the 32-bit IV and the 32-bit key from a key file.

However, I read that the initialization vector is generated randomly, and can be public as well. If I changed my algorithm to generate a random IV, where would I store this IV (or communicate it to the user)? Would I simply output the value of the IV to the user after I finish encrypting the message? Or could I store the initialization vector as part of the message itself (perhaps at the beginning).

Then my decryption algorithm can simply read the first 32-bits of the encrypted message, which will be the initialization vector. Is this the right way to do it?

  • $\begingroup$ "to implement a 32-bit block cipher" for which a specification was given, or one chosen by you? $\hspace{.6 in}$ "a simple block-cipher that uses CBC" is possible, although it seems far more likely that you mean "CBC mode with a simple block cipher", especially since you then jump straight into talking about IVs. $\hspace{.6 in}$ $\endgroup$
    – user991
    Commented Jan 28, 2015 at 21:39
  • $\begingroup$ Yes, the implementation is open to us. The only requirement is that it is a block-cipher and it is 32-bit. Also, I did mean "CBC mode". Sorry, I'm quite new at this and I don't have my terminology right. $\endgroup$ Commented Jan 28, 2015 at 21:42
  • $\begingroup$ From the short description you gave of the assignment, it sounds like you don't need to implement a mode of operation. $\:$ For modes of operation (including CBC), you would store the initialization vector as the beginning of the ciphertext, so that the decryption algorithm can do what you describe. $\;\;\;\;$ $\endgroup$
    – user991
    Commented Jan 28, 2015 at 22:03
  • $\begingroup$ He left it up to us whether we wanted to implement a mode of operation or not. It's very open ended. But I think you answered my question - adding it to the beginning of the ciphertext makes sense. Thank you! If you put that as an answer, I can accept it. $\endgroup$ Commented Jan 28, 2015 at 22:13
  • $\begingroup$ Standard practice is using a random per message IV and sending it alongside the message, typically as a prefix. So in principle you got the IV handling right. $\endgroup$ Commented Jan 28, 2015 at 22:22

1 Answer 1


For CBC encryption, you would store the initialization vector as the beginning of
the ciphertext, regardless of whether you read in an IV or generated it yourself.
The CBC decryption algorithm would do what you described at the end of your post.
Your implementation should also offer access to the block cipher itself, without any mode of operation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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