Custom code for MD5 in js
function myMD5(string){


MD5 itself acts on bits or - for most runtimes - bytes. All string manipulation should take place outside any MD5 function.

/*unsigning also works cuts to 32bit words*/


That's not clear to me. Two verbs in a row...

string = unescape(encodeURIComponent(string));


Oh dear, that throws the principle of least surprise in the blender. Do not suddenly change the string without warning the user.

The you first copy the complete message to bytes, and then to words. This uses a lot of unnecessary memory. There is a reason why most implementations (well, outside of those of JavaScript) use multiple update method and a final digest method. It is to handle larger messages, or messages that are actually split over multiple locations.

for(var i = 1; i &lt;= 64; i++)
    K.push(Math.floor(0x100000000 * Math.abs(Math.sin(i))));


This makes the code smaller, of course, but do you really want to perform that calculation for each MD5 invocation?

var A, B, C, D;


When using variable names that are specific to a specification, then please provide a link to the specification. Otherwise other devs are going to wonder about the special variable names (such as shif).

if(rnd &lt; 16){


Branching is relatively slow on modern processors. This is why you see the unrolled loops that you've coiled up again. To get speed, you want to perform operations chunks by buffering a chunk at a time. Then you want to have the code run as fast as possible.

Fortunately you are using else if which makes it ever so slightly more performant. Over a few runs, the branching should become predictable and a good runtime should make it run faster.

You are returning the result as bytes, which is how it should be. Don't forget to test your code against the official test vectors, and add tests for your own edge cases or your MD5 may still result in a wrong value.

Your code looks fine if you just want to get a feel of what MD5 - a relatively simple crypto hash - looks like. It's good practice. But now you may want to proceed and see what it takes to make it efficient - and unroll your own code yourself.