Given a cipher and and key given in the code, Im supposed to find the plaintext, I don't think I'm doing it quite right because my result isn't an actual word its just 8 random letters and its supposed to be a word.
public class FindthePlainText
public static void printByteArray(byte  array)
for(int i = 0; i < array.length-1; i++)
I can see several things that are definitely wrong with your code ( for ecxample the line System.out.print(pt) does not do what you think it does ) but you are asking us to deduce your homework requirement from your probably flawed precis of the requirement and code that does not work. Even though I understand the JCE I for one cannot from what you have posted deduce the original homework requirement so cannot point out where you are going wrong.
If you post the text of you homework and not just your interpretation of it then maybe somebody here will be able to point out where you are going wrong.
Joined: Feb 10, 2013
Okay here is the original assignment:
8 characters of ciphertext: 2C, E6, DD, A4, 98, CA, BA, B9
Note: This is again exactly one block size.
Key bytes: FE, DC, BA, 98, 76, 54, 32, 10
What is the decoded plaintext? Specify it as a character string (using ASCII).
Note: If everything worked fine, the plaintext should be really plain text, i.e., perfectly
2. Finding the Key
Plaintext in ASCII: "Plaintxt "
The corresponding ciphertext: 4A, C4, 55, 3D, B3, 37, CA, B3
The first four bytes of the Key: 01, 23, 45, 67
What is the complete key used in this encryption?
The first task has two errors. One I have already pointed out (you need to understand what the toString() method of an array actually does) and the other is a result of your carelessness in typing.
Your solution to the second task is totally wrong since it should not involve wrapped keys. You have been given the first 4 bytes of a DES key and seem to be required to iterate through all possible values for the remaining 4 bytes of the key until you get a ciphertext match. Note - a DES key uses the least significant bit of each byte as an odd parity bit but the JCE does not actually care what value it is so you only have to worry about the first 7 bits if each of the 4 remaining bytes of the key.
I wish the admin people would stop messing around with the site! This is the third time I have had to type this response!
Joined: Feb 10, 2013
Okay I caught my mistake in the last keybyte entry and switched it to B9 and changed my print statement to look like this, but I don't think that's right becuase its giving me 18 numbers now when I run it. Was I previously printing out the arrays location in memory or something like that?
cipher = Cipher.getInstance("DES/ECB/NoPadding");
pt = cipher.doFinal(ct);
for(int i = 0; i < pt.length-1; i++)