Keep checking the FAQ regularly, as I will update it until the deadline. You can also ask specific questions on Piazza.


The DES programming portion of the assignment is cancelled. Just implement the OTP, plus ECB/CBC/CTR mode using AES. (See Piazza for more details.) However, you should still answer question (a) even for DES (just calculate the correct answer yourself). Also answer questions (c) and (d) for DES. (Even though you will not be able to run the statistical test for DES yourself, describe and explain what you would expect to see.)


This assignment may be done in teams of two students. (Though if you prefer to work alone, you may.) If you are looking for a partner, please post on Piazza. You may only partner with a student in the same section as you.

C vs. Java

I recommend C because that is a better choice when dealing with bits and bytes, as you will be doing for this homework. Of course, it is possible to complete the assignment in Java also.

Sample AES Code

You can download code for AES (written in C) here. An example of how to use it is also available. AES supports different key lengths, but for this homework you should be using 128-bit keys (the default).

Project Structure

Please structure your submission in the following way. Create a directory called hw1. Then create a subdirectory named either C or Java (depending on the language you used) containing the following:

Submission Instructions

You have the choice of working on grace (an account has been set up for you), or working on your own and emailing your code to the TA. (Email is preferred.) Directions for each case follow.
  1. Grace: Create an archive of your work by running gtar czvf hw1.tar.gz hw1 from the directory containing hw1. Then submit the archive using the submit script:
            submit 2012 spring cmsc 414 XXX 1 hw1.tar.gz ,
    where XXX is either 0101 or 0201 depending on your section. For usage instructions of the submit script run:
    After submitting, you are advised to email the TA assigned to your section to check whether they can see your submission.
  2. Email: Create a hw1.tar.gz archive and email it to the TA. Make sure to email the TA assigned to your section. The subject line should be "CMSC414 HW1 Submission" exactly as written.

General Questions

1. Will the homework be tested automatically?
The programming part of the homework will be tested automatically.

Question 1

1. What error should OTPenc.java return if the plaintext and key lengths do not match?
Print (quotes for clarity) "Plaintext and key lengths do not match.\n" in OTPctext.txt. Do not throw an exception.
2. What error should OTPdec.java return if the ciphertext and key lengths do not match?
Print (quotes for clarity) "Ciphertext and key lengths do not match.\n" in OTPdecrypt.txt. Do not throw an exception.
3. Is n the length of key/plaintext/ciphertext in bytes or in bits?
n is the length in bits.
4. Can you provide some sample input/output data?

        javac OTPgen.java
        java OTPgen 256

should result in OTPkey.txt looking like this.
Running next:

        javac OTPenc.java
        java OTPenc

with OTPmsg.txt in the current directory like this and OTPkey.txt as generated above, should generate output OTPctext.txt like this. Finally, running:

        javac OTPdec.java
        java OTPdec

with OTPctext.txt and OTPkey.txt in the current directory generated as above should produce OTPdecrypt.txt in the current dirctory that looks like this.
Note that all output should be readable, so hex values should be printed as ASCII characters. (I.e., the hex value 'A' should be printed as the ASCII character 'A'.)

6. How do I tell java to view characters as bit-strings?
You can obtain the 8-bit ASCII code of a char by casting the char to a byte. For example:

        char ch = 'a';
        byte b = (byte)ch;

7. Should we skip newlines in the plaintext file?
You should encrypt every character/byte in the file OTPmsg.txt whether it is a whitespace or not.

Question 2

1. The encryption schemes for CBC and CTR modes require an Initialization Vector (IV). How should we produce and/or store the IV?
You are supposed to figure this out for yourself.
2. What error message should we output to ctext.txt if the length of the message in msg.txt is not a multiple of the block length of the cipher being used?
Please output "Message needs to be padded.\n" to ctext.txt.
3. With how many bits is a character in msg.txt represented?
8 bits, its ASCII code.
4. How long should the AES keys be?
AES supports different key lengths, but for this homework you should just use 128-bit keys.
5. I have seen CTR mode defined slightly differently elsewhere. Which definition should we follow?
You should implement CTR mode exactly as described in class.
6. Can you provide some sample input/output data?
Below are sample ciphertexts, all encryptions of this plaintext using AES with this key. (These examples are provided to illustrate the formatting, and for testing. Note that I did not choose a random key, nor did I choose random IVs. You should generate your keys/IVs at random.)