1

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?

BCS
  • 75,627
  • 68
  • 187
  • 294
  • Take a look at this answers http://stackoverflow.com/questions/1655769/fastest-md5-implementation-in-javascript there are many MD5 implementations listed. – powtac May 11 '10 at 17:27

2 Answers2

1

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

scaryzet
  • 923
  • 4
  • 9
  • How well defined is bit twiddling in JS? Would I be better off using `n%8` and `n/=8`? – BCS May 11 '10 at 18:39
1

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
  • 19,598
  • 4
  • 47
  • 69