I wonder if anyone here can help me. I have an algorithm to decrypt a password from a string and i am struggling to decrypt it. The algorithm itself shows an example and i tried the example but i cant get the results that were shown in the example to match with the result in my sample code.
Here is the algorithm.
1.First get the bytes of the original password, assuming a "Latin-1" encoding. For the password "Baltimore1," these bytes are: 66 97 108 116 105 109 111 114 101 49 44 (i.e. the value of "B" is 66, "a" is 97, etc). 2.Then get the MD5 hash of these bytes. MD5 is a standard, public algorithm. Once again, for the password "Baltimore1," these bytes work out as: 223 238 161 24 62 121 39 143 115 167 51 163 245 231 226 94 3.Finally, create the new password by forming a string whose Latin-1 encoding is the bytes from the previous step. For the "Baltimore1," password, if this is string is written to the screen, it looks like: ���_>y'?s�3����^(i.e. the 62 above is a ">", the 121 is a "y", etc).
To try the above, i tried to get the string shown in step 3 using the "Baltimore1," password. Here is the code that i wrote.
And here is the output of the above program.
As you can see, the output of line 1 is correct. The bytes are exactly as described in the example. I was expecting the output on line 4 to be 223 238 161 24 62 121 39 143 115 167 51 163 245 231 226 94 as shown in the example. Does anyone know what i am doing wrong?
Arrays don't override the toString() method, so the value you are returning from the MD5 method is actually the value of the array reference. To convert the values in an array to a String, Try the Arrays.toString(byte) method.
Thanks guys for your help. I followed some of your advice and changed the code as shown below as an example.
It looks like im almost there but not quite yet.
And here is the output from the above program
The bytes shown in line 3 are corect. The bytes shown in line 4 are partially correct in that the positive numbers are correct. Im not sure why the others have come out as negative numbers. Whats interesting is that when i add 256 to the negative numbers the answer becomes correct. Why does this happen? Have i used a variable that is the wrong size?