Richard Tookey wrote:
I'm very uncomfortable with this. It is difficult to see how a Java course could jump in with a homework requirement such as this so I assume it builds on lectures and previous homework. Your task does not really rely on understanding the JCE; the JCE is just clutter and the homework requires that you be able to iterate through all the 2^56 possible key values and then use them in the code given.
Note - a DES key is just 56 bits packaged in 8 bytes with the least significant bit of each byte being a parity bit. The JCE ignores this parity bit so you just have to go though the 128 values of each byte that ignore the least significant bit. This can be done very simply using recursion but could equally well be done by counting though the first 2^56 values of a long and converting the first 56 bits of the long to 8 bytes (7 bits at a time) using the shift operators. The actual approach you take will depend on what you have done in the course so far.
Note 1 - the code you published is flawed. It assumes that the key can always be represented by a String and that it can be converted to bytes using the platform default character encoding! This makes it non-portable since for a given key String the actual bytes of the key will depend on the platform default character encoding!
The following plaintext:
Seize the Day!
was encrypted with DES the algorithm implemented at:
http://www.avajava.com/tutorials/lessons/how-do-i-encrypt-and-decrypt-files-using-des.html
Three files (original.txt, encrypted.txt, and CipherExample.java) are included with this assignment. Note that the key in the code was changed.
Write code that given the plaintext and ciphertext above will try and exhaustive search for the key.
You create an empty SortableArrayList called nameList, then you print some stuff that's not connected to nameList, then you sort nameList even though it is empty, then you print some other stuff not connected to nameList. I expect that accomplishes very little.
I also notice that you print listItem twice without changing it between the two printings. That doesn't seem useful either.