New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

js-md5

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-md5 - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

2

bower.json
{
"name": "js-md5",
"version": "0.1.3",
"version": "0.2.0",
"main": ["build/md5.min.js"],

@@ -5,0 +5,0 @@ "ignore": [

@@ -1,10 +0,10 @@

(function(m,v){var t="0123456789abcdef".split(""),u=function(h,l){var e,k=1732584193,n=4023233417,p=2562383102,q=271733878,b,d,a,c,g;if(!l&&/[^\x00-\x7F]/.test(h)){e=[];for(d=b=0;d<h.length;d++)a=h.charCodeAt(d),128>a?e[b++]=a:(2048>a?e[b++]=192|a>>6:(55296>a||57344<=a?e[b++]=224|a>>12:(a=65536+((a&1023)<<10|h.charCodeAt(++d)&1023),e[b++]=240|a>>18,e[b++]=128|a>>12&63),e[b++]=128|a>>6&63),e[b++]=128|a&63);b=e.length;d=(b+8>>6)+1<<4;a=[];for(c=0;c<d;++c)a[c]=0;for(c=0;c<b;++c)a[c>>2]|=e[c]<<((c&3)<<
3);a[c>>2]|=128<<((c&3)<<3);a[d-2]=b<<3;e=a}else{e=h.length;b=(e+8>>6)+1<<4;d=[];for(a=0;a<b;++a)d[a]=0;for(a=0;a<e;++a)d[a>>2]|=h.charCodeAt(a)<<((a&3)<<3);d[a>>2]|=128<<((a&3)<<3);d[b-2]=e<<3;e=d}for(var f=0,m=e.length;f<m;f+=16)0===f?(b=e[f+0]-680876937,b=(b<<7|b>>>25)-271733879<<0,c=e[f+1]-117830708+(2004318071&b^-1732584194),c=(c<<12|c>>>20)+b<<0,a=e[f+2]-1126478375+((b^-271733879)&c^-271733879),a=(a<<17|a>>>15)+c<<0,d=e[f+3]-1316259209+((c^b)&a^b)):(b=k,d=n,a=p,c=q,b+=(c^d&(a^c))+e[f+0]-680876936,
b=(b<<7|b>>>25)+d<<0,c+=(a^b&(d^a))+e[f+1]-389564586,c=(c<<12|c>>>20)+b<<0,a+=(d^c&(b^d))+e[f+2]+606105819,a=(a<<17|a>>>15)+c<<0,d+=(b^a&(c^b))+e[f+3]-1044525330),d=(d<<22|d>>>10)+a<<0,b+=(c^d&(a^c))+e[f+4]-176418897,b=(b<<7|b>>>25)+d<<0,c+=(a^b&(d^a))+e[f+5]+1200080426,c=(c<<12|c>>>20)+b<<0,a+=(d^c&(b^d))+e[f+6]-1473231341,a=(a<<17|a>>>15)+c<<0,d+=(b^a&(c^b))+e[f+7]-45705983,d=(d<<22|d>>>10)+a<<0,b+=(c^d&(a^c))+e[f+8]+1770035416,b=(b<<7|b>>>25)+d<<0,c+=(a^b&(d^a))+e[f+9]-1958414417,c=(c<<12|c>>>
20)+b<<0,a+=(d^c&(b^d))+e[f+10]-42063,a=(a<<17|a>>>15)+c<<0,d+=(b^a&(c^b))+e[f+11]-1990404162,d=(d<<22|d>>>10)+a<<0,b+=(c^d&(a^c))+e[f+12]+1804603682,b=(b<<7|b>>>25)+d<<0,c+=(a^b&(d^a))+e[f+13]-40341101,c=(c<<12|c>>>20)+b<<0,a+=(d^c&(b^d))+e[f+14]-1502002290,a=(a<<17|a>>>15)+c<<0,d+=(b^a&(c^b))+e[f+15]+1236535329,d=(d<<22|d>>>10)+a<<0,b+=(a^c&(d^a))+e[f+1]-165796510,b=(b<<5|b>>>27)+d<<0,c+=(d^a&(b^d))+e[f+6]-1069501632,c=(c<<9|c>>>23)+b<<0,a+=(b^d&(c^b))+e[f+11]+643717713,a=(a<<14|a>>>18)+c<<0,d+=
(c^b&(a^c))+e[f+0]-373897302,d=(d<<20|d>>>12)+a<<0,b+=(a^c&(d^a))+e[f+5]-701558691,b=(b<<5|b>>>27)+d<<0,c+=(d^a&(b^d))+e[f+10]+38016083,c=(c<<9|c>>>23)+b<<0,a+=(b^d&(c^b))+e[f+15]-660478335,a=(a<<14|a>>>18)+c<<0,d+=(c^b&(a^c))+e[f+4]-405537848,d=(d<<20|d>>>12)+a<<0,b+=(a^c&(d^a))+e[f+9]+568446438,b=(b<<5|b>>>27)+d<<0,c+=(d^a&(b^d))+e[f+14]-1019803690,c=(c<<9|c>>>23)+b<<0,a+=(b^d&(c^b))+e[f+3]-187363961,a=(a<<14|a>>>18)+c<<0,d+=(c^b&(a^c))+e[f+8]+1163531501,d=(d<<20|d>>>12)+a<<0,b+=(a^c&(d^a))+e[f+
13]-1444681467,b=(b<<5|b>>>27)+d<<0,c+=(d^a&(b^d))+e[f+2]-51403784,c=(c<<9|c>>>23)+b<<0,a+=(b^d&(c^b))+e[f+7]+1735328473,a=(a<<14|a>>>18)+c<<0,d+=(c^b&(a^c))+e[f+12]-1926607734,d=(d<<20|d>>>12)+a<<0,g=d^a,b+=(g^c)+e[f+5]-378558,b=(b<<4|b>>>28)+d<<0,g=d^a,c+=(g^b)+e[f+8]-2022574463,c=(c<<11|c>>>21)+b<<0,g=c^b,a+=(g^d)+e[f+11]+1839030562,a=(a<<16|a>>>16)+c<<0,g=c^b,d+=(g^a)+e[f+14]-35309556,d=(d<<23|d>>>9)+a<<0,g=d^a,b+=(g^c)+e[f+1]-1530992060,b=(b<<4|b>>>28)+d<<0,g=d^a,c+=(g^b)+e[f+4]+1272893353,c=
(c<<11|c>>>21)+b<<0,g=c^b,a+=(g^d)+e[f+7]-155497632,a=(a<<16|a>>>16)+c<<0,g=c^b,d+=(g^a)+e[f+10]-1094730640,d=(d<<23|d>>>9)+a<<0,g=d^a,b+=(g^c)+e[f+13]+681279174,b=(b<<4|b>>>28)+d<<0,g=d^a,c+=(g^b)+e[f+0]-358537222,c=(c<<11|c>>>21)+b<<0,g=c^b,a+=(g^d)+e[f+3]-722521979,a=(a<<16|a>>>16)+c<<0,g=c^b,d+=(g^a)+e[f+6]+76029189,d=(d<<23|d>>>9)+a<<0,g=d^a,b+=(g^c)+e[f+9]-640364487,b=(b<<4|b>>>28)+d<<0,g=d^a,c+=(g^b)+e[f+12]-421815835,c=(c<<11|c>>>21)+b<<0,g=c^b,a+=(g^d)+e[f+15]+530742520,a=(a<<16|a>>>16)+
c<<0,g=c^b,d+=(g^a)+e[f+2]-995338651,d=(d<<23|d>>>9)+a<<0,b+=(a^(d|~c))+e[f+0]-198630844,b=(b<<6|b>>>26)+d<<0,c+=(d^(b|~a))+e[f+7]+1126891415,c=(c<<10|c>>>22)+b<<0,a+=(b^(c|~d))+e[f+14]-1416354905,a=(a<<15|a>>>17)+c<<0,d+=(c^(a|~b))+e[f+5]-57434055,d=(d<<21|d>>>11)+a<<0,b+=(a^(d|~c))+e[f+12]+1700485571,b=(b<<6|b>>>26)+d<<0,c+=(d^(b|~a))+e[f+3]-1894986606,c=(c<<10|c>>>22)+b<<0,a+=(b^(c|~d))+e[f+10]-1051523,a=(a<<15|a>>>17)+c<<0,d+=(c^(a|~b))+e[f+1]-2054922799,d=(d<<21|d>>>11)+a<<0,b+=(a^(d|~c))+e[f+
8]+1873313359,b=(b<<6|b>>>26)+d<<0,c+=(d^(b|~a))+e[f+15]-30611744,c=(c<<10|c>>>22)+b<<0,a+=(b^(c|~d))+e[f+6]-1560198380,a=(a<<15|a>>>17)+c<<0,d+=(c^(a|~b))+e[f+13]+1309151649,d=(d<<21|d>>>11)+a<<0,b+=(a^(d|~c))+e[f+4]-145523070,b=(b<<6|b>>>26)+d<<0,c+=(d^(b|~a))+e[f+11]-1120210379,c=(c<<10|c>>>22)+b<<0,a+=(b^(c|~d))+e[f+2]+718787259,a=(a<<15|a>>>17)+c<<0,d+=(c^(a|~b))+e[f+9]-343485551,d=(d<<21|d>>>11)+a<<0,k=k+b<<0,n=n+d<<0,p=p+a<<0,q=q+c<<0;return r(k)+r(n)+r(p)+r(q)},r=function(h){for(var l="",
e=0;4>e;e++)var k=e<<3,l=l+(t[h>>k+4&15]+t[h>>k&15]);return l};"undefined"!=typeof module?module.exports=u:m&&(m.md5=u)})(this);
(function(g,w){var x="undefined"!=typeof module;x&&(g=global);var y=!g.JS_MD5_TEST&&"undefined"!=typeof ArrayBuffer,z="0123456789abcdef".split(""),e=[],k;if(y){var h=new ArrayBuffer(68);k=new Uint8Array(h);e=new Uint32Array(h)}var A=[128,32768,8388608,-2147483648],m=[0,8,16,24],h=function(p){var n,q,r,g,b,a,d,c,f,l=0,h=0,v=0,t=p.length;e[16]=0;do{e[0]=e[16];e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0;if(y)for(a=h;l<t&&64>a;++l)b=p.charCodeAt(l),128>b?k[a++]=
b:(2048>b?k[a++]=192|b>>6:(55296>b||57344<=b?k[a++]=224|b>>12:(b=65536+((b&1023)<<10|p.charCodeAt(++l)&1023),k[a++]=240|b>>18,k[a++]=128|b>>12&63),k[a++]=128|b>>6&63),k[a++]=128|b&63);else for(a=h;l<t&&64>a;++l)b=p.charCodeAt(l),128>b?e[a>>2]|=b<<m[a++&3]:(2048>b?e[a>>2]|=(192|b>>6)<<m[a++&3]:(55296>b||57344<=b?e[a>>2]|=(224|b>>12)<<m[a++&3]:(b=65536+((b&1023)<<10|p.charCodeAt(++l)&1023),e[a>>2]|=(240|b>>18)<<m[a++&3],e[a>>2]|=(128|b>>12&63)<<m[a++&3]),e[a>>2]|=(128|b>>6&63)<<m[a++&3]),e[a>>2]|=(128|
b&63)<<m[a++&3]);v+=a-h;h=a-64;l==t&&(e[a>>2]|=A[a&3],e[14]=v<<3);n===w?(b=e[0]-680876937,b=(b<<7|b>>>25)-271733879<<0,c=e[1]-117830708+(2004318071&b^-1732584194),c=(c<<12|c>>>20)+b<<0,d=e[2]-1126478375+((b^-271733879)&c^-271733879),d=(d<<17|d>>>15)+c<<0,a=e[3]-1316259209+((c^b)&d^b)):(b=n,a=q,d=r,c=g,b+=(c^a&(d^c))+e[0]-680876936,b=(b<<7|b>>>25)+a<<0,c+=(d^b&(a^d))+e[1]-389564586,c=(c<<12|c>>>20)+b<<0,d+=(a^c&(b^a))+e[2]+606105819,d=(d<<17|d>>>15)+c<<0,a+=(b^d&(c^b))+e[3]-1044525330);a=(a<<22|a>>>
10)+d<<0;b+=(c^a&(d^c))+e[4]-176418897;b=(b<<7|b>>>25)+a<<0;c+=(d^b&(a^d))+e[5]+1200080426;c=(c<<12|c>>>20)+b<<0;d+=(a^c&(b^a))+e[6]-1473231341;d=(d<<17|d>>>15)+c<<0;a+=(b^d&(c^b))+e[7]-45705983;a=(a<<22|a>>>10)+d<<0;b+=(c^a&(d^c))+e[8]+1770035416;b=(b<<7|b>>>25)+a<<0;c+=(d^b&(a^d))+e[9]-1958414417;c=(c<<12|c>>>20)+b<<0;d+=(a^c&(b^a))+e[10]-42063;d=(d<<17|d>>>15)+c<<0;a+=(b^d&(c^b))+e[11]-1990404162;a=(a<<22|a>>>10)+d<<0;b+=(c^a&(d^c))+e[12]+1804603682;b=(b<<7|b>>>25)+a<<0;c+=(d^b&(a^d))+e[13]-40341101;
c=(c<<12|c>>>20)+b<<0;d+=(a^c&(b^a))+e[14]-1502002290;d=(d<<17|d>>>15)+c<<0;a+=(b^d&(c^b))+e[15]+1236535329;a=(a<<22|a>>>10)+d<<0;b+=(d^c&(a^d))+e[1]-165796510;b=(b<<5|b>>>27)+a<<0;c+=(a^d&(b^a))+e[6]-1069501632;c=(c<<9|c>>>23)+b<<0;d+=(b^a&(c^b))+e[11]+643717713;d=(d<<14|d>>>18)+c<<0;a+=(c^b&(d^c))+e[0]-373897302;a=(a<<20|a>>>12)+d<<0;b+=(d^c&(a^d))+e[5]-701558691;b=(b<<5|b>>>27)+a<<0;c+=(a^d&(b^a))+e[10]+38016083;c=(c<<9|c>>>23)+b<<0;d+=(b^a&(c^b))+e[15]-660478335;d=(d<<14|d>>>18)+c<<0;a+=(c^b&
(d^c))+e[4]-405537848;a=(a<<20|a>>>12)+d<<0;b+=(d^c&(a^d))+e[9]+568446438;b=(b<<5|b>>>27)+a<<0;c+=(a^d&(b^a))+e[14]-1019803690;c=(c<<9|c>>>23)+b<<0;d+=(b^a&(c^b))+e[3]-187363961;d=(d<<14|d>>>18)+c<<0;a+=(c^b&(d^c))+e[8]+1163531501;a=(a<<20|a>>>12)+d<<0;b+=(d^c&(a^d))+e[13]-1444681467;b=(b<<5|b>>>27)+a<<0;c+=(a^d&(b^a))+e[2]-51403784;c=(c<<9|c>>>23)+b<<0;d+=(b^a&(c^b))+e[7]+1735328473;d=(d<<14|d>>>18)+c<<0;a+=(c^b&(d^c))+e[12]-1926607734;a=(a<<20|a>>>12)+d<<0;f=a^d;b+=(f^c)+e[5]-378558;b=(b<<4|b>>>
28)+a<<0;f=a^d;c+=(f^b)+e[8]-2022574463;c=(c<<11|c>>>21)+b<<0;f=c^b;d+=(f^a)+e[11]+1839030562;d=(d<<16|d>>>16)+c<<0;f=c^b;a+=(f^d)+e[14]-35309556;a=(a<<23|a>>>9)+d<<0;f=a^d;b+=(f^c)+e[1]-1530992060;b=(b<<4|b>>>28)+a<<0;f=a^d;c+=(f^b)+e[4]+1272893353;c=(c<<11|c>>>21)+b<<0;f=c^b;d+=(f^a)+e[7]-155497632;d=(d<<16|d>>>16)+c<<0;f=c^b;a+=(f^d)+e[10]-1094730640;a=(a<<23|a>>>9)+d<<0;f=a^d;b+=(f^c)+e[13]+681279174;b=(b<<4|b>>>28)+a<<0;f=a^d;c+=(f^b)+e[0]-358537222;c=(c<<11|c>>>21)+b<<0;f=c^b;d+=(f^a)+e[3]-
722521979;d=(d<<16|d>>>16)+c<<0;f=c^b;a+=(f^d)+e[6]+76029189;a=(a<<23|a>>>9)+d<<0;f=a^d;b+=(f^c)+e[9]-640364487;b=(b<<4|b>>>28)+a<<0;f=a^d;c+=(f^b)+e[12]-421815835;c=(c<<11|c>>>21)+b<<0;f=c^b;d+=(f^a)+e[15]+530742520;d=(d<<16|d>>>16)+c<<0;f=c^b;a+=(f^d)+e[2]-995338651;a=(a<<23|a>>>9)+d<<0;b+=(d^(a|~c))+e[0]-198630844;b=(b<<6|b>>>26)+a<<0;c+=(a^(b|~d))+e[7]+1126891415;c=(c<<10|c>>>22)+b<<0;d+=(b^(c|~a))+e[14]-1416354905;d=(d<<15|d>>>17)+c<<0;a+=(c^(d|~b))+e[5]-57434055;a=(a<<21|a>>>11)+d<<0;b+=(d^
(a|~c))+e[12]+1700485571;b=(b<<6|b>>>26)+a<<0;c+=(a^(b|~d))+e[3]-1894986606;c=(c<<10|c>>>22)+b<<0;d+=(b^(c|~a))+e[10]-1051523;d=(d<<15|d>>>17)+c<<0;a+=(c^(d|~b))+e[1]-2054922799;a=(a<<21|a>>>11)+d<<0;b+=(d^(a|~c))+e[8]+1873313359;b=(b<<6|b>>>26)+a<<0;c+=(a^(b|~d))+e[15]-30611744;c=(c<<10|c>>>22)+b<<0;d+=(b^(c|~a))+e[6]-1560198380;d=(d<<15|d>>>17)+c<<0;a+=(c^(d|~b))+e[13]+1309151649;a=(a<<21|a>>>11)+d<<0;b+=(d^(a|~c))+e[4]-145523070;b=(b<<6|b>>>26)+a<<0;c+=(a^(b|~d))+e[11]-1120210379;c=(c<<10|c>>>
22)+b<<0;d+=(b^(c|~a))+e[2]+718787259;d=(d<<15|d>>>17)+c<<0;a+=(c^(d|~b))+e[9]-343485551;a=(a<<21|a>>>11)+d<<0;n===w?(n=b+1732584193<<0,q=a-271733879<<0,r=d-1732584194<<0,g=c+271733878<<0):(n=n+b<<0,q=q+a<<0,r=r+d<<0,g=g+c<<0)}while(l<t);return u(n)+u(q)+u(r)+u(g)},u=function(e){for(var g="",h=0;4>h;h++)var k=h<<3,g=g+(z[e>>k+4&15]+z[e>>k&15]);return g};!g.JS_MD5_TEST&&x?module.exports=h:g&&(g.md5=h)})(this);

@@ -0,1 +1,11 @@

# v0.2.0 / 2015-01-12
* Remove ascii parameter.
* Improve performance.
# v0.1.4 / 2015-01-11
* Improve performance.
* Add test case.
# v0.1.3 / 2015-01-05

@@ -2,0 +12,0 @@

{
"name": "js-md5",
"version": "0.1.3",
"version": "0.2.0",
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",

@@ -5,0 +5,0 @@ "main": "src/md5.js",

@@ -14,6 +14,6 @@ # js-md5

## Install
## Installation
You can also install js-md5 by using Bower.
bower install js-md5
bower install md5

@@ -34,16 +34,2 @@ For node.js, you can use this command to install:

### Methods
#### md5(str, asciiOnly)
Hash string to md5, set asciiOnly to true for better performace if you ensure input is ascii.
##### *str: `String`*
String to hash.
##### *asciiOnly: `Boolean` (default: `false`)*
Specify the string encoding is ASCII.
## Example

@@ -73,4 +59,3 @@ Code

## Benchmark
[ASCII](http://jsperf.com/md5-ascii/4)
[UTF8](http://jsperf.com/md5-utf8/3)
[MD5 Shootout](http://jsperf.com/md5-shootout/79)

@@ -77,0 +62,0 @@ ## Extensions

/*
* js-md5 v0.1.3
* js-md5 v0.2.0
* https://github.com/emn178/js-md5

@@ -13,23 +13,88 @@ *

var NODE_JS = typeof(module) != 'undefined';
if(NODE_JS) {
root = global;
}
var ARRAY_BUFFER = !root.JS_MD5_TEST && typeof(ArrayBuffer) != 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var md5 = function(message, asciiOnly) {
var blocks, h0 = 0x67452301, h1 = 0xEFCDAB89, h2 = 0x98BADCFE, h3 = 0x10325476,
a, b, c, d, bc, da;
if(!asciiOnly && /[^\x00-\x7F]/.test(message)) {
blocks = getBlocksFromUtf8(message);
} else {
blocks = getBlocksFromAscii(message);
}
for(var i = 0, length = blocks.length;i < length;i += 16) {
if(i === 0) {
a = blocks[i + 0] - 680876937;
a = ((a << 7 | a >>> 25) - 271733879) << 0;
d = blocks[i + 1] - 117830708 + ((2004318071 & a) ^ -1732584194);
d = ((d << 12 | d >>> 20) + a) << 0;
c = blocks[i + 2] - 1126478375 + (((a ^ -271733879) & d) ^ -271733879);
c = ((c << 17 | c >>> 15) + d) << 0;
b = blocks[i + 3] - 1316259209 + (((d ^ a) & c) ^ a);
b = ((b << 22 | b >>> 10) + c) << 0;
var blocks = [], buffer8;
if(ARRAY_BUFFER) {
var buffer = new ArrayBuffer(68);
buffer8 = new Uint8Array(buffer);
blocks = new Uint32Array(buffer);
}
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
var md5 = function(message) {
var h0, h1, h2, h3, a, b, c, d, bc, da, code,
index = 0, i, start = 0, bytes = 0, length = message.length;
blocks[16] = 0;
do {
blocks[0] = blocks[16];
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
if(ARRAY_BUFFER) {
for (i = start;index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
buffer8[i++] = code;
} else if (code < 0x800) {
buffer8[i++] = 0xc0 | (code >> 6);
buffer8[i++] = 0x80 | (code & 0x3f);
} else if (code < 0xd800 || code >= 0xe000) {
buffer8[i++] = 0xe0 | (code >> 12);
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
buffer8[i++] = 0x80 | (code & 0x3f);
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
buffer8[i++] = 0xf0 | (code >> 18);
buffer8[i++] = 0x80 | ((code >> 12) & 0x3f);
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
buffer8[i++] = 0x80 | (code & 0x3f);
}
}
} else {
for (i = start;index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
blocks[i >> 2] |= code << SHIFT[i++ & 3];
} else if (code < 0x800) {
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else if (code < 0xd800 || code >= 0xe000) {
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
}
}
bytes += i - start;
start = i - 64;
if(index == length) {
blocks[i >> 2] |= EXTRA[i & 3];
blocks[14] = bytes << 3;
}
if(h0 === undefined) {
a = blocks[0] - 680876937;
a = (a << 7 | a >>> 25) - 271733879 << 0;
d = blocks[1] - 117830708 + ((2004318071 & a) ^ -1732584194);
d = (d << 12 | d >>> 20) + a << 0;
c = blocks[2] - 1126478375 + (((a ^ -271733879) & d) ^ -271733879);
c = (c << 17 | c >>> 15) + d << 0;
b = blocks[3] - 1316259209 + (((d ^ a) & c) ^ a);
b = (b << 22 | b >>> 10) + c << 0;
} else {
a = h0;

@@ -39,154 +104,161 @@ b = h1;

d = h3;
a += (d ^ (b & (c ^ d))) + blocks[i + 0] - 680876936;
a = ((a << 7 | a >>> 25) + b) << 0;
d += (c ^ (a & (b ^ c))) + blocks[i + 1] - 389564586;
d = ((d << 12 | d >>> 20) + a) << 0;
c += (b ^ (d & (a ^ b))) + blocks[i + 2] + 606105819;
c = ((c << 17 | c >>> 15) + d) << 0;
b += (a ^ (c & (d ^ a))) + blocks[i + 3] - 1044525330;
b = ((b << 22 | b >>> 10) + c) << 0;
a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936;
a = (a << 7 | a >>> 25) + b << 0;
d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586;
d = (d << 12 | d >>> 20) + a << 0;
c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819;
c = (c << 17 | c >>> 15) + d << 0;
b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330;
b = (b << 22 | b >>> 10) + c << 0;
}
a += (d ^ (b & (c ^ d))) + blocks[i + 4] - 176418897;
a = ((a << 7 | a >>> 25) + b) << 0;
d += (c ^ (a & (b ^ c))) + blocks[i + 5] + 1200080426;
d = ((d << 12 | d >>> 20) + a) << 0;
c += (b ^ (d & (a ^ b))) + blocks[i + 6] - 1473231341;
c = ((c << 17 | c >>> 15) + d) << 0;
b += (a ^ (c & (d ^ a))) + blocks[i + 7] - 45705983;
b = ((b << 22 | b >>> 10) + c) << 0;
a += (d ^ (b & (c ^ d))) + blocks[i + 8] + 1770035416;
a = ((a << 7 | a >>> 25) + b) << 0;
d += (c ^ (a & (b ^ c))) + blocks[i + 9] - 1958414417;
d = ((d << 12 | d >>> 20) + a) << 0;
c += (b ^ (d & (a ^ b))) + blocks[i + 10] - 42063;
c = ((c << 17 | c >>> 15) + d) << 0;
b += (a ^ (c & (d ^ a))) + blocks[i + 11] - 1990404162;
b = ((b << 22 | b >>> 10) + c) << 0;
a += (d ^ (b & (c ^ d))) + blocks[i + 12] + 1804603682;
a = ((a << 7 | a >>> 25) + b) << 0;
d += (c ^ (a & (b ^ c))) + blocks[i + 13] - 40341101;
d = ((d << 12 | d >>> 20) + a) << 0;
c += (b ^ (d & (a ^ b))) + blocks[i + 14] - 1502002290;
c = ((c << 17 | c >>> 15) + d) << 0;
b += (a ^ (c & (d ^ a))) + blocks[i + 15] + 1236535329;
b = ((b << 22 | b >>> 10) + c) << 0;
a += (c ^ (d & (b ^ c))) + blocks[i + 1] - 165796510;
a = ((a << 5 | a >>> 27) + b) << 0;
d += (b ^ (c & (a ^ b))) + blocks[i + 6] - 1069501632;
d = ((d << 9 | d >>> 23) + a) << 0;
c += (a ^ (b & (d ^ a))) + blocks[i + 11] + 643717713;
c = ((c << 14 | c >>> 18) + d) << 0;
b += (d ^ (a & (c ^ d))) + blocks[i + 0] - 373897302;
b = ((b << 20 | b >>> 12) + c) << 0;
a += (c ^ (d & (b ^ c))) + blocks[i + 5] - 701558691;
a = ((a << 5 | a >>> 27) + b) << 0;
d += (b ^ (c & (a ^ b))) + blocks[i + 10] + 38016083;
d = ((d << 9 | d >>> 23) + a) << 0;
c += (a ^ (b & (d ^ a))) + blocks[i + 15] - 660478335;
c = ((c << 14 | c >>> 18) + d) << 0;
b += (d ^ (a & (c ^ d))) + blocks[i + 4] - 405537848;
b = ((b << 20 | b >>> 12) + c) << 0;
a += (c ^ (d & (b ^ c))) + blocks[i + 9] + 568446438;
a = ((a << 5 | a >>> 27) + b) << 0;
d += (b ^ (c & (a ^ b))) + blocks[i + 14] - 1019803690;
d = ((d << 9 | d >>> 23) + a) << 0;
c += (a ^ (b & (d ^ a))) + blocks[i + 3] - 187363961;
c = ((c << 14 | c >>> 18) + d) << 0;
b += (d ^ (a & (c ^ d))) + blocks[i + 8] + 1163531501;
b = ((b << 20 | b >>> 12) + c) << 0;
a += (c ^ (d & (b ^ c))) + blocks[i + 13] - 1444681467;
a = ((a << 5 | a >>> 27) + b) << 0;
d += (b ^ (c & (a ^ b))) + blocks[i + 2] - 51403784;
d = ((d << 9 | d >>> 23) + a) << 0;
c += (a ^ (b & (d ^ a))) + blocks[i + 7] + 1735328473;
c = ((c << 14 | c >>> 18) + d) << 0;
b += (d ^ (a & (c ^ d))) + blocks[i + 12] - 1926607734;
b = ((b << 20 | b >>> 12) + c) << 0;
a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897;
a = (a << 7 | a >>> 25) + b << 0;
d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426;
d = (d << 12 | d >>> 20) + a << 0;
c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341;
c = (c << 17 | c >>> 15) + d << 0;
b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983;
b = (b << 22 | b >>> 10) + c << 0;
a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416;
a = (a << 7 | a >>> 25) + b << 0;
d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417;
d = (d << 12 | d >>> 20) + a << 0;
c += (b ^ (d & (a ^ b))) + blocks[10] - 42063;
c = (c << 17 | c >>> 15) + d << 0;
b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162;
b = (b << 22 | b >>> 10) + c << 0;
a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682;
a = (a << 7 | a >>> 25) + b << 0;
d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101;
d = (d << 12 | d >>> 20) + a << 0;
c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290;
c = (c << 17 | c >>> 15) + d << 0;
b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329;
b = (b << 22 | b >>> 10) + c << 0;
a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510;
a = (a << 5 | a >>> 27) + b << 0;
d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632;
d = (d << 9 | d >>> 23) + a << 0;
c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713;
c = (c << 14 | c >>> 18) + d << 0;
b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302;
b = (b << 20 | b >>> 12) + c << 0;
a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691;
a = (a << 5 | a >>> 27) + b << 0;
d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083;
d = (d << 9 | d >>> 23) + a << 0;
c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335;
c = (c << 14 | c >>> 18) + d << 0;
b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848;
b = (b << 20 | b >>> 12) + c << 0;
a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438;
a = (a << 5 | a >>> 27) + b << 0;
d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690;
d = (d << 9 | d >>> 23) + a << 0;
c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961;
c = (c << 14 | c >>> 18) + d << 0;
b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501;
b = (b << 20 | b >>> 12) + c << 0;
a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467;
a = (a << 5 | a >>> 27) + b << 0;
d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784;
d = (d << 9 | d >>> 23) + a << 0;
c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473;
c = (c << 14 | c >>> 18) + d << 0;
b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734;
b = (b << 20 | b >>> 12) + c << 0;
bc = b ^ c;
a += (bc ^ d) + blocks[i + 5] - 378558;
a = ((a << 4 | a >>> 28) + b) << 0;
a += (bc ^ d) + blocks[5] - 378558;
a = (a << 4 | a >>> 28) + b << 0;
bc = b ^ c;
d += (bc ^ a) + blocks[i + 8] - 2022574463;
d = ((d << 11 | d >>> 21) + a) << 0;
d += (bc ^ a) + blocks[8] - 2022574463;
d = (d << 11 | d >>> 21) + a << 0;
da = d ^ a;
c += (da ^ b) + blocks[i + 11] + 1839030562;
c = ((c << 16 | c >>> 16) + d) << 0;
c += (da ^ b) + blocks[11] + 1839030562;
c = (c << 16 | c >>> 16) + d << 0;
da = d ^ a;
b += (da ^ c) + blocks[i + 14] - 35309556;
b = ((b << 23 | b >>> 9) + c) << 0;
b += (da ^ c) + blocks[14] - 35309556;
b = (b << 23 | b >>> 9) + c << 0;
bc = b ^ c;
a += (bc ^ d) + blocks[i + 1] - 1530992060;
a = ((a << 4 | a >>> 28) + b) << 0;
a += (bc ^ d) + blocks[1] - 1530992060;
a = (a << 4 | a >>> 28) + b << 0;
bc = b ^ c;
d += (bc ^ a) + blocks[i + 4] + 1272893353;
d = ((d << 11 | d >>> 21) + a) << 0;
d += (bc ^ a) + blocks[4] + 1272893353;
d = (d << 11 | d >>> 21) + a << 0;
da = d ^ a;
c += (da ^ b) + blocks[i + 7] - 155497632;
c = ((c << 16 | c >>> 16) + d) << 0;
c += (da ^ b) + blocks[7] - 155497632;
c = (c << 16 | c >>> 16) + d << 0;
da = d ^ a;
b += (da ^ c) + blocks[i + 10] - 1094730640;
b = ((b << 23 | b >>> 9) + c) << 0;
b += (da ^ c) + blocks[10] - 1094730640;
b = (b << 23 | b >>> 9) + c << 0;
bc = b ^ c;
a += (bc ^ d) + blocks[i + 13] + 681279174;
a = ((a << 4 | a >>> 28) + b) << 0;
a += (bc ^ d) + blocks[13] + 681279174;
a = (a << 4 | a >>> 28) + b << 0;
bc = b ^ c;
d += (bc ^ a) + blocks[i + 0] - 358537222;
d = ((d << 11 | d >>> 21) + a) << 0;
d += (bc ^ a) + blocks[0] - 358537222;
d = (d << 11 | d >>> 21) + a << 0;
da = d ^ a;
c += (da ^ b) + blocks[i + 3] - 722521979;
c = ((c << 16 | c >>> 16) + d) << 0;
c += (da ^ b) + blocks[3] - 722521979;
c = (c << 16 | c >>> 16) + d << 0;
da = d ^ a;
b += (da ^ c) + blocks[i + 6] + 76029189;
b = ((b << 23 | b >>> 9) + c) << 0;
b += (da ^ c) + blocks[6] + 76029189;
b = (b << 23 | b >>> 9) + c << 0;
bc = b ^ c;
a += (bc ^ d) + blocks[i + 9] - 640364487;
a = ((a << 4 | a >>> 28) + b) << 0;
a += (bc ^ d) + blocks[9] - 640364487;
a = (a << 4 | a >>> 28) + b << 0;
bc = b ^ c;
d += (bc ^ a) + blocks[i + 12] - 421815835;
d = ((d << 11 | d >>> 21) + a) << 0;
d += (bc ^ a) + blocks[12] - 421815835;
d = (d << 11 | d >>> 21) + a << 0;
da = d ^ a;
c += (da ^ b) + blocks[i + 15] + 530742520;
c = ((c << 16 | c >>> 16) + d) << 0;
c += (da ^ b) + blocks[15] + 530742520;
c = (c << 16 | c >>> 16) + d << 0;
da = d ^ a;
b += (da ^ c) + blocks[i + 2] - 995338651;
b = ((b << 23 | b >>> 9) + c) << 0;
a += (c ^ (b | ~d)) + blocks[i + 0] - 198630844;
a = ((a << 6 | a >>> 26) + b) << 0;
d += (b ^ (a | ~c)) + blocks[i + 7] + 1126891415;
d = ((d << 10 | d >>> 22) + a) << 0;
c += (a ^ (d | ~b)) + blocks[i + 14] - 1416354905;
c = ((c << 15 | c >>> 17) + d) << 0;
b += (d ^ (c | ~a)) + blocks[i + 5] - 57434055;
b = ((b << 21 | b >>> 11) + c) << 0;
a += (c ^ (b | ~d)) + blocks[i + 12] + 1700485571;
a = ((a << 6 | a >>> 26) + b) << 0;
d += (b ^ (a | ~c)) + blocks[i + 3] - 1894986606;
d = ((d << 10 | d >>> 22) + a) << 0;
c += (a ^ (d | ~b)) + blocks[i + 10] - 1051523;
c = ((c << 15 | c >>> 17) + d) << 0;
b += (d ^ (c | ~a)) + blocks[i + 1] - 2054922799;
b = ((b << 21 | b >>> 11) + c) << 0;
a += (c ^ (b | ~d)) + blocks[i + 8] + 1873313359;
a = ((a << 6 | a >>> 26) + b) << 0;
d += (b ^ (a | ~c)) + blocks[i + 15] - 30611744;
d = ((d << 10 | d >>> 22) + a) << 0;
c += (a ^ (d | ~b)) + blocks[i + 6] - 1560198380;
c = ((c << 15 | c >>> 17) + d) << 0;
b += (d ^ (c | ~a)) + blocks[i + 13] + 1309151649;
b = ((b << 21 | b >>> 11) + c) << 0;
a += (c ^ (b | ~d)) + blocks[i + 4] - 145523070;
a = ((a << 6 | a >>> 26) + b) << 0;
d += (b ^ (a | ~c)) + blocks[i + 11] - 1120210379;
d = ((d << 10 | d >>> 22) + a) << 0;
c += (a ^ (d | ~b)) + blocks[i + 2] + 718787259;
c = ((c << 15 | c >>> 17) + d) << 0;
b += (d ^ (c | ~a)) + blocks[i + 9] - 343485551;
b = ((b << 21 | b >>> 11) + c) << 0;
b += (da ^ c) + blocks[2] - 995338651;
b = (b << 23 | b >>> 9) + c << 0;
a += (c ^ (b | ~d)) + blocks[0] - 198630844;
a = (a << 6 | a >>> 26) + b << 0;
d += (b ^ (a | ~c)) + blocks[7] + 1126891415;
d = (d << 10 | d >>> 22) + a << 0;
c += (a ^ (d | ~b)) + blocks[14] - 1416354905;
c = (c << 15 | c >>> 17) + d << 0;
b += (d ^ (c | ~a)) + blocks[5] - 57434055;
b = (b << 21 | b >>> 11) + c << 0;
a += (c ^ (b | ~d)) + blocks[12] + 1700485571;
a = (a << 6 | a >>> 26) + b << 0;
d += (b ^ (a | ~c)) + blocks[3] - 1894986606;
d = (d << 10 | d >>> 22) + a << 0;
c += (a ^ (d | ~b)) + blocks[10] - 1051523;
c = (c << 15 | c >>> 17) + d << 0;
b += (d ^ (c | ~a)) + blocks[1] - 2054922799;
b = (b << 21 | b >>> 11) + c << 0;
a += (c ^ (b | ~d)) + blocks[8] + 1873313359;
a = (a << 6 | a >>> 26) + b << 0;
d += (b ^ (a | ~c)) + blocks[15] - 30611744;
d = (d << 10 | d >>> 22) + a << 0;
c += (a ^ (d | ~b)) + blocks[6] - 1560198380;
c = (c << 15 | c >>> 17) + d << 0;
b += (d ^ (c | ~a)) + blocks[13] + 1309151649;
b = (b << 21 | b >>> 11) + c << 0;
a += (c ^ (b | ~d)) + blocks[4] - 145523070;
a = (a << 6 | a >>> 26) + b << 0;
d += (b ^ (a | ~c)) + blocks[11] - 1120210379;
d = (d << 10 | d >>> 22) + a << 0;
c += (a ^ (d | ~b)) + blocks[2] + 718787259;
c = (c << 15 | c >>> 17) + d << 0;
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
b = (b << 21 | b >>> 11) + c << 0;
h0 = (h0 + a) << 0;
h1 = (h1 + b) << 0;
h2 = (h2 + c) << 0;
h3 = (h3 + d) << 0;
}
if(h0 === undefined) {
h0 = a + 1732584193 << 0;
h1 = b - 271733879<< 0;
h2 = c - 1732584194 << 0;
h3 = d + 271733878 << 0;
} else {
h0 = h0 + a << 0;
h1 = h1 + b << 0;
h2 = h2 + c << 0;
h3 = h3 + d << 0;
}
} while(index < length);

@@ -205,61 +277,3 @@ return toHexString(h0) + toHexString(h1) + toHexString(h2) + toHexString(h3);

var getBytesFromUtf8 = function(str) {
var bytes = [], index = 0;
for (var i = 0;i < str.length; i++) {
var c = str.charCodeAt(i);
if (c < 0x80) {
bytes[index++] = c;
} else if (c < 0x800) {
bytes[index++] = 0xc0 | (c >> 6);
bytes[index++] = 0x80 | (c & 0x3f);
} else if (c < 0xd800 || c >= 0xe000) {
bytes[index++] = 0xe0 | (c >> 12);
bytes[index++] = 0x80 | ((c >> 6) & 0x3f);
bytes[index++] = 0x80 | (c & 0x3f);
} else {
c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
bytes[index++] = 0xf0 | (c >> 18);
bytes[index++] = 0x80 | ((c >> 12) & 0x3f);
bytes[index++] = 0x80 | ((c >> 6) & 0x3f);
bytes[index++] = 0x80 | (c & 0x3f);
}
}
return bytes;
};
var getBlocksFromAscii = function(message) {
// a block is 32 bits(4 bytes), a chunk is 512 bits(64 bytes)
var length = message.length;
var chunkCount = ((length + 8) >> 6) + 1;
var blockCount = chunkCount << 4; // chunkCount * 16
var blocks = [], i;
for(i = 0;i < blockCount;++i) {
blocks[i] = 0;
}
for(i = 0;i < length;++i) {
blocks[i >> 2] |= message.charCodeAt(i) << ((i & 3) << 3);
}
blocks[i >> 2] |= 0x80 << ((i & 3) << 3);
blocks[blockCount - 2] = length << 3; // length * 8
return blocks;
};
var getBlocksFromUtf8 = function(message) {
var bytes = getBytesFromUtf8(message);
var length = bytes.length;
var chunkCount = ((length + 8) >> 6) + 1;
var blockCount = chunkCount << 4; // chunkCount * 16
var blocks = [], i;
for(i = 0;i < blockCount;++i) {
blocks[i] = 0;
}
for(i = 0;i < length;++i) {
blocks[i >> 2] |= bytes[i] << ((i & 3) << 3);
}
blocks[i >> 2] |= 0x80 << ((i & 3) << 3);
blocks[blockCount - 2] = length << 3; // length * 8
return blocks;
};
if(typeof(module) != 'undefined') {
if(!root.JS_MD5_TEST && NODE_JS) {
module.exports = md5;

@@ -266,0 +280,0 @@ } else if(root) {

@@ -1,184 +0,202 @@

var HEX_CHARS = "0123456789abcdef".split('');
var HEX_TABLE = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15,
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15
};
var crypto = require('crypto');
var md5 = require('../src/md5.js');
// var str = '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789';
var str = '訊息摘要演算法第五版';
var R = [7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21];
console.time('s');
for(var i = 0;i < 100000;++i) {
crypto.createHash('md5').update(str).digest('hex');
}
console.timeEnd('s');
var K = [0XD76AA478, 0XE8C7B756, 0X242070DB, 0XC1BDCEEE,
0XF57C0FAF, 0X4787C62A, 0XA8304613, 0XFD469501,
0X698098D8, 0X8B44F7AF, 0XFFFF5BB1, 0X895CD7BE,
0X6B901122, 0XFD987193, 0XA679438E, 0X49B40821,
0XF61E2562, 0XC040B340, 0X265E5A51, 0XE9B6C7AA,
0XD62F105D, 0X02441453, 0XD8A1E681, 0XE7D3FBC8,
0X21E1CDE6, 0XC33707D6, 0XF4D50D87, 0X455A14ED,
0XA9E3E905, 0XFCEFA3F8, 0X676F02D9, 0X8D2A4C8A,
0XFFFA3942, 0X8771F681, 0X6D9D6122, 0XFDE5380C,
0XA4BEEA44, 0X4BDECFA9, 0XF6BB4B60, 0XBEBFBC70,
0X289B7EC6, 0XEAA127FA, 0XD4EF3085, 0X04881D05,
0XD9D4D039, 0XE6DB99E5, 0X1FA27CF8, 0XC4AC5665,
0XF4292244, 0X432AFF97, 0XAB9423A7, 0XFC93A039,
0X655B59C3, 0X8F0CCC92, 0XFFEFF47D, 0X85845DD1,
0X6FA87E4F, 0XFE2CE6E0, 0XA3014314, 0X4E0811A1,
0XF7537E82, 0XBD3AF235, 0X2AD7D2BB, 0XEB86D391];
console.time('s');
for(var i = 0;i < 100000;++i) {
md5(str);
}
console.timeEnd('s');
var str = '';
// var HEX_CHARS = "0123456789abcdef".split('');
// var HEX_TABLE = {
// '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
// 'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15,
// 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15
// };
// var R = [7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
// 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
// 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
// 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21];
for(var j = 0;j < 64;++j)
{
if(j < 16)
{
// f = (b & c) | ((~b) & d);
switch(j % 4)
{
case 0:
// str += 'f = d ^ (b & (c ^ d));\n';
f = '(d ^ (b & (c ^ d)))';
// f = '(((c ^ d) & b) ^ d)';
break;
case 1:
// str += 'f = c ^ (a & (b ^ c));\n';
f = '(c ^ (a & (b ^ c)))';
// f = '(((b ^ c) & a) ^ c)';
break;
case 2:
// str += 'f = b ^ (d & (a ^ b));\n';
f = '(b ^ (d & (a ^ b)))';
// f = '(((a ^ b) & d) ^ b)';
break;
case 3:
// str += 'f = a ^ (c & (d ^ a));\n';
f = '(a ^ (c & (d ^ a)))';
// f = '(((d ^ a) & c) ^ a)';
break;
}
g = j;
// str += 'g = ' + g + ';\n';
}
else if(j < 32)
{
// f = (d & b) | ((~d) & c);
switch(j % 4)
{
case 0:
// str += 'f = c ^ (d & (b ^ c));\n';
f = '(c ^ (d & (b ^ c)))';
// f = '(((b ^ c) & d) ^ c)';
break;
case 1:
// str += 'f = b ^ (c & (a ^ b));\n';
f = '(b ^ (c & (a ^ b)))';
// f = '(((a ^ b) & c) ^ b)';
break;
case 2:
// str += 'f = a ^ (b & (d ^ a));\n';
f = '(a ^ (b & (d ^ a)))';
// f = '(((d ^ a) & b) ^ a)';
break;
case 3:
// str += 'f = d ^ (a & (c ^ d));\n';
f = '(d ^ (a & (c ^ d)))';
// f = '(((c ^ d) & a) ^ d)';
break;
}
g = (5 * j + 1) % 16;
// str += 'g = ' + g + ';\n';
}
else if(j < 48)
{
switch(j % 4)
{
case 0:
str += 'bc = b ^ c;\n';
// str += 'f = b ^ c ^ d;\n';
f = '(bc ^ d)';
break;
case 1:
str += 'bc = b ^ c;\n';
// str += 'f = b ^ c ^ a;\n';
f = '(bc ^ a)';
break;
case 2:
str += 'da = d ^ a;\n';
// str += 'f = d ^ a ^ b;\n';
f = '(da ^ b)';
break;
case 3:
str += 'da = d ^ a;\n';
// str += 'f = d ^ a ^ c;\n';
f = '(da ^ c)';
break;
}
g = (3 * j + 5) % 16;
// str += 'g = ' + g + ';\n';
}
else
{
switch(j % 4)
{
case 0:
// str += 'f = c ^ (b | (~d));\n';
f = '(c ^ (b | ~d))';
break;
case 1:
// str += 'f = b ^ (a | (~c));\n';
f = '(b ^ (a | ~c))';
break;
case 2:
// str += 'f = a ^ (d | (~b));\n';
f = '(a ^ (d | ~b))';
break;
case 3:
// str += 'f = d ^ (c | (~a));\n';
f = '(d ^ (c | ~a))';
break;
}
g = (7 * j) % 16;
// str += 'g = ' + g + ';\n';
}
// var K = [0XD76AA478, 0XE8C7B756, 0X242070DB, 0XC1BDCEEE,
// 0XF57C0FAF, 0X4787C62A, 0XA8304613, 0XFD469501,
// 0X698098D8, 0X8B44F7AF, 0XFFFF5BB1, 0X895CD7BE,
// 0X6B901122, 0XFD987193, 0XA679438E, 0X49B40821,
// 0XF61E2562, 0XC040B340, 0X265E5A51, 0XE9B6C7AA,
// 0XD62F105D, 0X02441453, 0XD8A1E681, 0XE7D3FBC8,
// 0X21E1CDE6, 0XC33707D6, 0XF4D50D87, 0X455A14ED,
// 0XA9E3E905, 0XFCEFA3F8, 0X676F02D9, 0X8D2A4C8A,
// 0XFFFA3942, 0X8771F681, 0X6D9D6122, 0XFDE5380C,
// 0XA4BEEA44, 0X4BDECFA9, 0XF6BB4B60, 0XBEBFBC70,
// 0X289B7EC6, 0XEAA127FA, 0XD4EF3085, 0X04881D05,
// 0XD9D4D039, 0XE6DB99E5, 0X1FA27CF8, 0XC4AC5665,
// 0XF4292244, 0X432AFF97, 0XAB9423A7, 0XFC93A039,
// 0X655B59C3, 0X8F0CCC92, 0XFFEFF47D, 0X85845DD1,
// 0X6FA87E4F, 0XFE2CE6E0, 0XA3014314, 0X4E0811A1,
// 0XF7537E82, 0XBD3AF235, 0X2AD7D2BB, 0XEB86D391];
// str += 'tmp = d, d = c, c = b;\n';
// var str = '';
k = K[j];
if(k > 2147483647)
k = k - 0xFFFFFFFF - 1;
r = R[j];
// leftrotate
// for(var j = 0;j < 64;++j)
// {
// if(j < 16)
// {
// // f = (b & c) | ((~b) & d);
// switch(j % 4)
// {
// case 0:
// // str += 'f = d ^ (b & (c ^ d));\n';
// f = '(d ^ (b & (c ^ d)))';
// // f = '(((c ^ d) & b) ^ d)';
// break;
// case 1:
// // str += 'f = c ^ (a & (b ^ c));\n';
// f = '(c ^ (a & (b ^ c)))';
// // f = '(((b ^ c) & a) ^ c)';
// break;
// case 2:
// // str += 'f = b ^ (d & (a ^ b));\n';
// f = '(b ^ (d & (a ^ b)))';
// // f = '(((a ^ b) & d) ^ b)';
// break;
// case 3:
// // str += 'f = a ^ (c & (d ^ a));\n';
// f = '(a ^ (c & (d ^ a)))';
// // f = '(((d ^ a) & c) ^ a)';
// break;
// }
// g = j;
// // str += 'g = ' + g + ';\n';
// }
// else if(j < 32)
// {
// // f = (d & b) | ((~d) & c);
// switch(j % 4)
// {
// case 0:
// // str += 'f = c ^ (d & (b ^ c));\n';
// f = '(c ^ (d & (b ^ c)))';
// // f = '(((b ^ c) & d) ^ c)';
// break;
// case 1:
// // str += 'f = b ^ (c & (a ^ b));\n';
// f = '(b ^ (c & (a ^ b)))';
// // f = '(((a ^ b) & c) ^ b)';
// break;
// case 2:
// // str += 'f = a ^ (b & (d ^ a));\n';
// f = '(a ^ (b & (d ^ a)))';
// // f = '(((d ^ a) & b) ^ a)';
// break;
// case 3:
// // str += 'f = d ^ (a & (c ^ d));\n';
// f = '(d ^ (a & (c ^ d)))';
// // f = '(((c ^ d) & a) ^ d)';
// break;
// }
// g = (5 * j + 1) % 16;
// // str += 'g = ' + g + ';\n';
// }
// else if(j < 48)
// {
// switch(j % 4)
// {
// case 0:
// str += 'bc = b ^ c;\n';
// // str += 'f = b ^ c ^ d;\n';
// f = '(bc ^ d)';
// break;
// case 1:
// str += 'bc = b ^ c;\n';
// // str += 'f = b ^ c ^ a;\n';
// f = '(bc ^ a)';
// break;
// case 2:
// str += 'da = d ^ a;\n';
// // str += 'f = d ^ a ^ b;\n';
// f = '(da ^ b)';
// break;
// case 3:
// str += 'da = d ^ a;\n';
// // str += 'f = d ^ a ^ c;\n';
// f = '(da ^ c)';
// break;
// }
// g = (3 * j + 5) % 16;
// // str += 'g = ' + g + ';\n';
// }
// else
// {
// switch(j % 4)
// {
// case 0:
// // str += 'f = c ^ (b | (~d));\n';
// f = '(c ^ (b | ~d))';
// break;
// case 1:
// // str += 'f = b ^ (a | (~c));\n';
// f = '(b ^ (a | ~c))';
// break;
// case 2:
// // str += 'f = a ^ (d | (~b));\n';
// f = '(a ^ (d | ~b))';
// break;
// case 3:
// // str += 'f = d ^ (c | (~a));\n';
// f = '(d ^ (c | ~a))';
// break;
// }
// g = (7 * j) % 16;
// // str += 'g = ' + g + ';\n';
// }
// // str += 'tmp = d, d = c, c = b;\n';
// k = K[j];
// if(k > 2147483647)
// k = k - 0xFFFFFFFF - 1;
// r = R[j];
// // leftrotate
var aa, bb;
switch(j % 4)
{
case 0:
aa = 'a';
bb = 'b';
break;
case 1:
aa = 'd';
bb = 'a';
break;
case 2:
aa = 'c';
bb = 'd';
break;
case 3:
aa = 'b';
bb = 'c';
break;
}
str += aa + ' += ' +f+' + blocks[i + ' + g + '] + ' + k + ';\n';
// y = R[j];
// str += 'y = ' + r + ';\n';
// str += 'b += (x << y) | (x >>> (32 - y));\n';
str += aa + ' = ((' + aa+ ' << ' + r + ' | ' + aa+ ' >>> ' + (32 - r) + ') + ' + bb + ') << 0;\n';
// str += 'a = tmp;\n';
}
// var aa, bb;
// switch(j % 4)
// {
// case 0:
// aa = 'a';
// bb = 'b';
// break;
// case 1:
// aa = 'd';
// bb = 'a';
// break;
// case 2:
// aa = 'c';
// bb = 'd';
// break;
// case 3:
// aa = 'b';
// bb = 'c';
// break;
// }
// str += aa + ' += ' +f+' + blocks[i + ' + g + '] + ' + k + ';\n';
// // y = R[j];
// // str += 'y = ' + r + ';\n';
// // str += 'b += (x << y) | (x >>> (32 - y));\n';
// str += aa + ' = ((' + aa+ ' << ' + r + ' | ' + aa+ ' >>> ' + (32 - r) + ') + ' + bb + ') << 0;\n';
// // str += 'a = tmp;\n';
// }
console.log(str);
// console.log(str);
md5 = require('../src/md5.js');
expect = require('expect.js');
testName = 'default';
require('./test.js');
delete require.cache[require.resolve('../src/md5.js')]
delete require.cache[require.resolve('./test.js')]
md5 = null
JS_MD5_TEST = true;
testName = 'without ArrayBuffer';
base64 = require('../src/md5.js');
require('./test.js');

@@ -1,30 +0,37 @@

describe('ascii', function() {
describe('less than 64 bytes', function() {
it('should be successful', function() {
expect(md5('')).to.be('d41d8cd98f00b204e9800998ecf8427e');
expect(md5('The quick brown fox jumps over the lazy dog')).to.be('9e107d9d372bb6826bd81d3542a419d6');
expect(md5('The quick brown fox jumps over the lazy dog.')).to.be('e4d909c290d0fb1ca068ffaddf22cbd0');
var module = md5;
describe(testName, function() {
describe('ascii', function() {
describe('less than 64 bytes', function() {
it('should be successful', function() {
expect(module('')).to.be('d41d8cd98f00b204e9800998ecf8427e');
expect(module('The quick brown fox jumps over the lazy dog')).to.be('9e107d9d372bb6826bd81d3542a419d6');
expect(module('The quick brown fox jumps over the lazy dog.')).to.be('e4d909c290d0fb1ca068ffaddf22cbd0');
expect(module('01234567801234567801234567801234567801234567801234567801234567801234567')).to.be('658d914ae42c4938874b2e786ccda479');
expect(module('012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('a083a3710d685793f1f17988bfe3c175');
});
});
});
describe('more than 64 bytes', function() {
it('should be successful', function() {
expect(md5('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('f63872ef7bc97a8a8eadba6f0881de53');
describe('more than 64 bytes', function() {
it('should be successful', function() {
expect(module('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('f63872ef7bc97a8a8eadba6f0881de53');
});
});
});
});
describe('UTF8', function() {
describe('less than 64 bytes', function() {
it('should be successful', function() {
expect(md5('中文')).to.be('a7bac2239fcdcb3a067903d8077c4a07');
expect(md5('aécio')).to.be('ec3edbf3b05a449fc206a0138c739c3b');
describe('UTF8', function() {
describe('less than 64 bytes', function() {
it('should be successful', function() {
expect(module('中文')).to.be('a7bac2239fcdcb3a067903d8077c4a07');
expect(module('aécio')).to.be('ec3edbf3b05a449fc206a0138c739c3b');
expect(module('𠜎')).to.be('b90869aaf121210f6c563973fa855650');
});
});
});
describe('more than 64 bytes', function() {
it('should be successful', function() {
expect(md5('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('ad36c9ab669a0ba9ce46d3ce9134de34');
describe('more than 64 bytes', function() {
it('should be successful', function() {
expect(module('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('ad36c9ab669a0ba9ce46d3ce9134de34');
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc