views:

94

answers:

2

I have a project where I want to compute an MD5 sum in JavaScript but I want to then break it up into chunks (as it happens I want 3 bits at a time). Are there any implementation I can use that make this easy to do? (BTW I already found this MD5 implementation that returns a string.)

Option I've thought of:

  • Hack that implementation to emit octal.
  • Consume a hex string 3 places at a time and re-slice it.

Anyone know of something simpler?

+1  A: 

Maybe convert it to an array of integers and extract the desired values by bitwise logical operators and bit-shifts?..

scaryzet
How well defined is bit twiddling in JS? Would I be better off using `n%8` and `n/=8`?
BCS
+1  A: 

I think your two solutions are probably the easiest you're going to get. In particular, since that implementation uses an array-of-ints representation internally, it'd probably be pretty easy to make a companion function to the existing b64 and hex encoding functions which outputs your desired format.

Mark Bessey