Additional questions are answered here
Submission instructions
Create a directory called hw1 containing the following:
- A file README with the names and UIDs
of the partners who did the homework together. If you worked alone, provide
just your name and UID. If you worked in a pair, provide both students' names
and UIDs but submit the archive through the account of only one of the partners.
Sample README:
        Name: John Smith
        UID: XXXXXXXXX
        Name: Eva Green
        UID: XXXXXXXXX
- A file hw1.txt
containing solutions to the non-programming questions.
- Two subdirectories q1 and q2 . In directory q1 provide OTPgen.java,
OTPenc.java, and OTPdec.java. In directory q2
provide Keygen.java, encrypt.java, and decrypt.java.
Please package OTPgen.java, OTPenc.java, and
OTPdec.java in the hw1.q1 package and Keygen.java,
encrypt.java, and decrypt.java in the hw1.q2 package.
Create an archive by running the following command from the directory containing
hw1:
        gtar czvf hw1.tar.gz hw1
Then submit the archive using the submit script:
        submit 2009 fall cmsc 414 0101 1 hw1.tar.gz
For usage instructions of the submit script run:
        submit
General Questions
- 1. Will the homework be tested automatically?
- The programming part of the homework will be tested automatically.
Question 1
- 1. How is OTPgen.java getting its argument?
- On the command line.
- 2. 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.
- 3. 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.
- 4. Is n the length of key/plaintext/ciphertext in bytes
or in bits?
- n is the length in bits.
- 5. Can you provide some sample input/output data?
- Running:
        javac OTPgen.java
        java OTPgen 264
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. Do all error outputs really need to be to a file?
- You should check for the errors mentioned in this FAQ and should print the
corresponding messages to the corresponding files.
- 8. The way we coded up the reading in of the OTPmsg.txt file
removes newlines. Do you want these included?
- You should encrypt every character/byte in the file OTPmsg.txt
no matter whether it is a whitespace or not.
Question 2
- 1. After I read the DES/AES key from key.txt, how do I pass it
to the init() method of the Cipher class in order to initialize the
Cipher object?
- If you read the key into an array of bytes (byte[]), let's
call it key, create an object of class javax.crypto.spec.SecretKeySpec.
This class implements the SecretKey interface which is the type of the
argument Cipher's init() expects. Don't forget to consult
the Java API documentation and the JCA reference guide:
        http://java.sun.com/javase/6/docs/api/
        http://java.sun.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html
- 2. 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.
- 3. 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.
- 4. With how many bits is a character in msg.txt represented?
- 8 bits, its ASCII code.
- 5. The question does not specify what Decrypt.java should do
with the recovered plaintext?
- Please output the recovered message in decrypt.txt