MD5加密的javascript实现
时间:2007-10-22 来源:不详 作者:林子
var lNumberOfWords = (lNumberOfWords_temp2 1)*16;
var lWordArray=Array(lNumberOfWords-1);
var lBytePosition = 0;
var lByteCount = 0;
while ( lByteCount < lMessageLength ) {
lWordCount = (lByteCount-(lByteCount % 4))/4;
lBytePosition = (lByteCount % 4)*8;
lWordArray[lWordCount] = (lWordArray[lWordCount] | (sMessage.charCodeAt(lByteCount)<<lBytePosition));
lByteCount ;
}
lWordCount = (lByteCount-(lByteCount % 4))/4;
lBytePosition = (lByteCount % 4)*8;
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
lWordArray[lNumberOfWords-2] = lMessageLength<<3;
lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
return lWordArray;
}
function WordToHex(lValue) {
var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
for (lCount = 0;lCount<=3;lCount ) {
lByte = (lValue>>>(lCount*8)) & 255;
WordToHexValue_temp = "0" lByte.toString(16);
WordToHexValue = WordToHexValue WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2); 本文来自织梦
}
return WordToHexValue;
}
var x=Array();
var k,AA,BB,CC,DD,a,b,c,d
var S11=7, S12=12, S13=17, S14=22;
var S21=5, S22=9 , S23=14, S24=20;
var S31=4, S32=11, S33=16, S34=23;
var S41=6, S42=10, S43=15, S44=21;
// Steps 1 and 2. Append padding bits and length and convert to words
x = ConvertToWordArray(sMessage);
// Step 3. Initialise
a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
// Step 4. Process the message in 16-word blocks
for (k=0;k<x.length;k =16) {
AA=a; BB=b; CC=c; DD=d;
a=FF(a,b,c,d,x[k 0], S11,0xD76AA478);
d=FF(d,a,b,c,x[k 1], S12,0xE8C7B756);
c=FF(c,d,a,b,x[k 2], S13,0x242070DB);
b=FF(b,c,d,a,x[k 3], S14,0xC1BDCEEE);
a=FF(a,b,c,d,x[k 4], S11,0xF57C0FAF);
d=FF(d,a,b,c,x[k 5], S12,0x4787C62A);
c=FF(c,d,a,b,x[k 6], S13,0xA8304613);
b=FF(b,c,d,a,x[k 7], S14,0xFD469501);
a=FF(a,b,c,d,x[k 8], S11,0x698098D8);
d=FF(d,a,b,c,x[k 9], S12,0x8B44F7AF);
c=FF(c,d,a,b,x[k 10],S13,0xFFFF5BB1);
b=FF(b,c,d,a,x[k 11],S14,0x895CD7BE);

文章评论
共有位Admini5网友发表了评论 查看完整内容