1 <script language="javascript">
2 //-------------------------------------------------------------------
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //-------------------------------------------------------------------
9 function rotate_left(n,s) {
10 var t4 = ( n<<s ) | (n>>>(32-s));
13 function lsb_hex(val) {
18 for( i=0; i<=6; i+=2 ) {
19 vh = (val>>>(i*4+4))&0x0f;
20 vl = (val>>>(i*4))&0x0f;
21 str += vh.toString(16) + vl.toString(16);
25 function cvt_hex(val) {
29 for( i=7; i>=0; i-- ) {
30 v = (val>>>(i*4))&0x0f;
31 str += v.toString(16);
35 function Utf8Encode(string) {
36 string = string.replace(/\r\n/g,"\n");
38 for (var n = 0; n < string.length; n++) {
39 var c = string.charCodeAt(n);
41 utftext += String.fromCharCode(c);
43 else if((c > 127) && (c < 2048)) {
44 utftext += String.fromCharCode((c >> 6) | 192);
45 utftext += String.fromCharCode((c & 63) | 128);
48 utftext += String.fromCharCode((c >> 12) | 224);
49 utftext += String.fromCharCode(((c >> 6) & 63) | 128);
50 utftext += String.fromCharCode((c & 63) | 128);
57 var W = new Array(80);
66 msg = Utf8Encode(msg);
67 var msg_len = msg.length;
68 var word_array = new Array();
69 for( i=0; i<msg_len-3; i+=4 ) {
70 j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
71 msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
74 switch( msg_len % 4 ) {
79 i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
83 i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
87 i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8 | 0x80;
92 while( (word_array.length % 16) != 14 ) word_array.push( 0 );
93 word_array.push( msg_len>>>29 );
94 word_array.push( (msg_len<<3)&0x0ffffffff );
95 for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
97 for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
98 for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
104 for( i= 0; i<=19; i++ ) {
105 temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
108 C = rotate_left(B,30);
112 for( i=20; i<=39; i++ ) {
113 temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
116 C = rotate_left(B,30);
120 for( i=40; i<=59; i++ ) {
121 temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
124 C = rotate_left(B,30);
128 for( i=60; i<=79; i++ ) {
129 temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
132 C = rotate_left(B,30);
136 H0 = (H0 + A) & 0x0ffffffff;
137 H1 = (H1 + B) & 0x0ffffffff;
138 H2 = (H2 + C) & 0x0ffffffff;
139 H3 = (H3 + D) & 0x0ffffffff;
140 H4 = (H4 + E) & 0x0ffffffff;
142 var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
143 return temp.toLowerCase();