So i am not sure if I’m doing this correctly. I am going by the pseudo code here: http://en.wikipedia.org/wiki/MD5
It says:
//Pre-processing:
append "1" bit to message
append "0" bits until message length in bits ≡ 448 (mod 512)
append length to message
In java, would i be able to convert the message to a byte array. Then get the number of bits by getting the string length * 8. Then do something like 448 - ((#bits+1) mod 512) to get the number of 0 bits to append to.
Then copy that byte array to another array, but pad the first bytes with 0s and then a 1.
Example:
String is 746 bits
I would then do 448 - ((746+1) mod 512) = 213
So i would need to pad the string with 213 “0” bits and then 1 “1” bit.
So then my array would be something like
byteArr[0] = 0x00
byteArr[1] = 0x00
...
byteArr[27] = 000001(Rest of message bits)
byteArr[n] = Rest of the bytes from message
How can i find out where the 1 goes though? Basically how can i find out if it’s going to create a short if i append the 1 bit.
Is there an easier way or some other way to do this?
As someone else caught, “append” means added to the end. So really what you want to have is a byte of 0x80 after the message followed by a bunch of 0 bytes until the number of bytes total is 8 less than a multiple of 64.