找回密码
 点一下
楼主: KickedByOthers

[Flash游戏]看看谁的名字更厉害!

  [复制链接]
发表于 2007-1-1 01:34:07 | 显示全部楼层
引用第119楼well6zyl9102007-01-01 01:32发表的:


英文和数字都对
就是中文没搞定

你素怎么验证的...
回复

使用道具 举报

发表于 2007-1-1 01:45:04 | 显示全部楼层
http://bbs15.xilu.com/cgi-bin/bb ... amp;message=1141986
MD5作战flash版,v 1.03扩大版

左下角有个MD5计算器
输入“AZ01”,得到:603ed9d601da7567eea42634b4497c3e
输入“中国”,得到:477fe630fe413595b6d3f42d92dcb044


  1.             System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();
  2.             Encoding conv = Encoding.GetEncoding(0);
  3.             byte[] byArrS = conv.GetBytes( txtSrc.Text);
  4.             byte[] byArrD = md5.ComputeHash(byArrS);
  5.             txtOut.Text = ToHexString(byArrD);
复制代码
输入“AZ01”,得到:603ED9D601DA7567EEA42634B4497C3E
输入“中国”,得到:CF0832DEDF7457BBCBFA00BBD87B300A



  1.             System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();
  2.             Encoding conv = Encoding.UTF8;
  3.             byte[] byArrS = conv.GetBytes( txtSrc.Text);
  4.             byte[] byArrD = md5.ComputeHash(byArrS);
  5.             txtOut.Text = ToHexString(byArrD);
复制代码
输入“AZ01”,得到:603ED9D601DA7567EEA42634B4497C3E
输入“中国”,得到:C13DCEABCB143ACD6C9298265D618A9F


以此类推,试验了很多编码都不行
回复

使用道具 举报

发表于 2007-1-1 01:53:38 | 显示全部楼层
用什么编码滴问题可以先不考虑...
不过偶记得flash素使用gb2312...
而且楼上滴那个链接中ID滴数值也素不同的
反正知道用滴素官方MD5算法即可...

如果素偶肯定换常数...
回复

使用道具 举报

发表于 2007-1-1 01:58:12 | 显示全部楼层
该Flash用的是这个MD5类


http://www.yady.net/blog/article.asp?id=192
  1. class MD5 {
  2. /**
  3. * Variables
  4. * hexcase : hex output format. 0 - lowercase; 1 - uppercase
  5. * b64pad : base-64 pad character. "=" for strict RFC compliance
  6. * chrsz : bits per input character. 8 - ASCII; 16 - Unicode
  7. */
  8. public static var hexcase:Number = 0;
  9. public static var b64pad:String = "";
  10. public static var chrsz:Number = 8;
  11. /**
  12. * Public methods
  13. */
  14. public static function test():String { return md5_vm_test(); };
  15. public static function calculate(s:String):String { return hex_md5(s); };
  16. public static function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
  17. public static function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
  18. public static function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
  19. /**
  20. * Private methods
  21. */
  22. private static function hex_md5(s) { return binl2hex(core_md5(str2binl(s), s.length*chrsz)); }
  23. private static function b64_md5(s) { return binl2b64(core_md5(str2binl(s), s.length*chrsz)); }
  24. private static function str_md5(s) { return binl2str(core_md5(str2binl(s), s.length*chrsz)); }
  25. private static function md5_vm_test() { return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; }
  26. private static function core_md5(x, len) {
  27. x[len >> 5] |= 0x80 << ((len)%32); x[(((len+64) >>> 9) << 4)+14] = len;
  28. var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878;
  29. for (var i = 0; i<x.length; i += 16) {
  30. var olda = a; var oldb = b; var oldc = c; var oldd = d;
  31. a = md5_ff(a, b, c, d, x[i+0], 7, -680876936);
  32. d = md5_ff(d, a, b, c, x[i+1], 12, -389564586);
  33. c = md5_ff(c, d, a, b, x[i+2], 17, 606105819);
  34. b = md5_ff(b, c, d, a, x[i+3], 22, -1044525330);
  35. a = md5_ff(a, b, c, d, x[i+4], 7, -176418897);
  36. d = md5_ff(d, a, b, c, x[i+5], 12, 1200080426);
  37. c = md5_ff(c, d, a, b, x[i+6], 17, -1473231341);
  38. b = md5_ff(b, c, d, a, x[i+7], 22, -45705983);
  39. a = md5_ff(a, b, c, d, x[i+8], 7, 1770035416);
  40. d = md5_ff(d, a, b, c, x[i+9], 12, -1958414417);
  41. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  42. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  43. a = md5_ff(a, b, c, d, x[i+12], 7, 1804603682);
  44. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  45. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  46. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  47. a = md5_gg(a, b, c, d, x[i+1], 5, -165796510);
  48. d = md5_gg(d, a, b, c, x[i+6], 9, -1069501632);
  49. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  50. b = md5_gg(b, c, d, a, x[i+0], 20, -373897302);
  51. a = md5_gg(a, b, c, d, x[i+5], 5, -701558691);
  52. d = md5_gg(d, a, b, c, x[i+10], 9, 38016083);
  53. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  54. b = md5_gg(b, c, d, a, x[i+4], 20, -405537848);
  55. a = md5_gg(a, b, c, d, x[i+9], 5, 568446438);
  56. d = md5_gg(d, a, b, c, x[i+14], 9, -1019803690);
  57. c = md5_gg(c, d, a, b, x[i+3], 14, -187363961);
  58. b = md5_gg(b, c, d, a, x[i+8], 20, 1163531501);
  59. a = md5_gg(a, b, c, d, x[i+13], 5, -1444681467);
  60. d = md5_gg(d, a, b, c, x[i+2], 9, -51403784);
  61. c = md5_gg(c, d, a, b, x[i+7], 14, 1735328473);
  62. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  63. a = md5_hh(a, b, c, d, x[i+5], 4, -378558);
  64. d = md5_hh(d, a, b, c, x[i+8], 11, -2022574463);
  65. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  66. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  67. a = md5_hh(a, b, c, d, x[i+1], 4, -1530992060);
  68. d = md5_hh(d, a, b, c, x[i+4], 11, 1272893353);
  69. c = md5_hh(c, d, a, b, x[i+7], 16, -155497632);
  70. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  71. a = md5_hh(a, b, c, d, x[i+13], 4, 681279174);
  72. d = md5_hh(d, a, b, c, x[i+0], 11, -358537222);
  73. c = md5_hh(c, d, a, b, x[i+3], 16, -722521979);
  74. b = md5_hh(b, c, d, a, x[i+6], 23, 76029189);
  75. a = md5_hh(a, b, c, d, x[i+9], 4, -640364487);
  76. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  77. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  78. b = md5_hh(b, c, d, a, x[i+2], 23, -995338651);
  79. a = md5_ii(a, b, c, d, x[i+0], 6, -198630844);
  80. d = md5_ii(d, a, b, c, x[i+7], 10, 1126891415);
  81. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  82. b = md5_ii(b, c, d, a, x[i+5], 21, -57434055);
  83. a = md5_ii(a, b, c, d, x[i+12], 6, 1700485571);
  84. d = md5_ii(d, a, b, c, x[i+3], 10, -1894986606);
  85. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  86. b = md5_ii(b, c, d, a, x[i+1], 21, -2054922799);
  87. a = md5_ii(a, b, c, d, x[i+8], 6, 1873313359);
  88. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  89. c = md5_ii(c, d, a, b, x[i+6], 15, -1560198380);
  90. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  91. a = md5_ii(a, b, c, d, x[i+4], 6, -145523070);
  92. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  93. c = md5_ii(c, d, a, b, x[i+2], 15, 718787259);
  94. b = md5_ii(b, c, d, a, x[i+9], 21, -343485551);
  95. a = safe_add(a, olda); b = safe_add(b, oldb);
  96. c = safe_add(c, oldc); d = safe_add(d, oldd);
  97. } return new Array(a, b, c, d);
  98. }
  99. private static function md5_cmn(q, a, b, x, s, t) { return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b); }
  100. private static function md5_ff(a, b, c, d, x, s, t) { return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); }
  101. private static function md5_gg(a, b, c, d, x, s, t) { return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); }
  102. private static function md5_hh(a, b, c, d, x, s, t) { return md5_cmn(b ^ c ^ d, a, b, x, s, t); }
  103. private static function md5_ii(a, b, c, d, x, s, t) { return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); }
  104. private static function core_hmac_md5(key, data) {
  105. var bkey = str2binl(key);
  106. if (bkey.length>16) bkey = core_md5(bkey, key.length*chrsz);
  107. var ipad = new Array(16), opad = new Array(16);
  108. for (var i = 0; i<16; i++) {
  109. ipad = bkey ^ 0x36363636; opad = bkey ^ 0x5C5C5C5C;
  110. }
  111. var hash = core_md5(ipad.concat(str2binl(data)), 512+data.length*chrsz);
  112. return core_md5(opad.concat(hash), 512+128);
  113. }
  114. private static function safe_add(x, y) {
  115. var lsw = (x & 0xFFFF)+(y & 0xFFFF); var msw = (x >> 16)+(y >> 16)+(lsw >> 16);
  116. return (msw << 16) | (lsw & 0xFFFF);
  117. }
  118. private static function bit_rol(num, cnt) { return (num << cnt) | (num >>> (32-cnt)); }
  119. private static function str2binl(str) {
  120. var bin = new Array(); var mask = (1 << chrsz)-1;
  121. for (var i = 0; i<str.length*chrsz; i += chrsz) bin[i >> 5] |= (str.charCodeAt(i/chrsz) & mask) << (i%32);
  122. return bin;
  123. }
  124. private static function binl2str(bin) {
  125. var str = ""; var mask = (1 << chrsz)-1;
  126. for (var i = 0; i<bin.length*32; i += chrsz) str += String.fromCharCode((bin[i >> 5] >>> (i%32)) & mask);
  127. return str;
  128. }
  129. private static function binl2hex(binarray) {
  130. var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var str = "";
  131. for (var i = 0; i<binarray.length*4; i++) {
  132. str += hex_tab.charAt((binarray[i >> 2] >> ((i%4)*8+4)) & 0xF)+hex_tab.charAt((binarray[i >> 2] >> ((i%4)*8)) & 0xF);
  133. } return str;
  134. }
  135. private static function binl2b64(binarray) {
  136. var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var str = "";
  137. for (var i = 0; i<binarray.length*4; i += 3) {
  138. var triplet = (((binarray[i >> 2] >> 8*(i%4)) & 0xFF) << 16) | (((binarray[i+1 >> 2] >> 8*((i+1)%4)) & 0xFF) << 8) | ((binarray[i+2 >> 2] >> 8*((i+2)%4)) & 0xFF);
  139. for (var j = 0; j<4; j++) {
  140. if (i*8+j*6>binarray.length*32) str += b64pad;
  141. else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
  142. }
  143. } return str;
  144. }
  145. }
  146. ===========================
  147. 实现如下:
  148. import MD5;
  149. var tt:String="JimLee";
  150. trace(MD5.calculate(tt));
复制代码
回复

使用道具 举报

发表于 2007-1-1 02:01:51 | 显示全部楼层
md5滴算法偶研究过也写过...
这些常数化成灰偶也认得...

910大人你弄错料...
那个可以计算md5滴版本和cgfan滴版本使用滴编码不同
证据就素不含中文的id在两个版本中数值相同而中文id不同
回复

使用道具 举报

发表于 2007-1-1 02:14:28 | 显示全部楼层

cgfan为什么要改中文的呢
直接用Unicode不好吗


反编译天书:MD5
  1. #initclip
  2.     // branch @3275
  3.     if (!?["?"]) {
  4.         ?["?"] = new ? ();
  5.     }
  6.     if (!?["?"]["?"]) {
  7.         ?["?"]["?"] = new ? ();
  8.     }
  9.     if (!?["?"]["?"]["?"]) {
  10.         var _local1 = function (b64pad, chrsz) {
  11.             if (b64pad != undefined) {
  12.                 this["?"] = b64pad;
  13.             }
  14.             if (((chrsz != undefined) && (chrsz == 8)) || (chrsz == 16)) {
  15.                 this["?"] = chrsz;
  16.             }
  17.         };
  18.         ?["?"]["?"] = _local1;
  19.         var _local2 = _local1["?"];
  20.         _local2["?"] = function (s) {
  21.             return (this.?(s));
  22.         };
  23.         _local2["?"] = function (s) {
  24.             return (this.?(this.?(this.?(s), s["?"] * this["?"])));
  25.         };
  26.         _local2["?"] = function (s) {
  27.             return (this.?(this.?(this.?(s), s["?"] * this["?"])));
  28.         };
  29.         _local2["?"] = function (s) {
  30.             return (this.?(this.?(this.?(s), s["?"] * this["?"])));
  31.         };
  32.         _local2["?"] = function (key, data) {
  33.             return (this.?(this.?(key, data)));
  34.         };
  35.         _local2["?"] = function (key, data) {
  36.             return (this.?(this.?(key, data)));
  37.         };
  38.         _local2["?"] = function (key, data) {
  39.             return (this.?(this.?(key, data)));
  40.         };
  41.         _local2["?"] = function (q, a, b, x, s, t) {
  42.             return (this.?(this.?(this.?(this.?(a, q), this.?(x, t)), s), b));
  43.         };
  44.         _local2["?"] = function (a, b, c, d, x, s, t) {
  45.             return (this.?((b & c) | ((~b) & d), a, b, x, s, t));
  46.         };
  47.         _local2["?"] = function (a, b, c, d, x, s, t) {
  48.             return (this.?((b & d) | (c & (~d)), a, b, x, s, t));
  49.         };
  50.         _local2["?"] = function (a, b, c, d, x, s, t) {
  51.             return (this.?((b ^ c) ^ d, a, b, x, s, t));
  52.         };
  53.         _local2["?"] = function (a, b, c, d, x, s, t) {
  54.             return (this.?(c ^ (b | (~d)), a, b, x, s, t));
  55.         };
  56.         _local2["?"] = function (x, len) {
  57.             x[len >> 5] = x[len >> 5] | (128 << (len % 32));
  58.             x[(((len + 64) >>> 9) << 4) + 14] = len;
  59.             var _local5 = 1732584193 /* 0x67452301 */;
  60.             var _local4 = -271733879;
  61.             var _local3 = -1732584194;
  62.             var _local2 = 271733878 /* 0x10325476 */;
  63.             var _local6 = 0;
  64.             while (_local6 < x["?"]) {
  65.                 var _local11 = _local5;
  66.                 var _local10 = _local4;
  67.                 var _local9 = _local3;
  68.                 var _local8 = _local2;
  69.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 0], 7, -680876936);
  70.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 1], 12, -389564586);
  71.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 2], 17, 606105819);
  72.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 3], 22, -1044525330);
  73.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 4], 7, -176418897);
  74.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 5], 12, 1200080426);
  75.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 6], 17, -1473231341);
  76.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 7], 22, -45705983);
  77.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 8], 7, 1770035416);
  78.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 9], 12, -1958414417);
  79.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 10], 17, -42063);
  80.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 11], 22, -1990404162);
  81.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 12], 7, 1804603682);
  82.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 13], 12, -40341101);
  83.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 14], 17, -1502002290);
  84.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 15], 22, 1236535329);
  85.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 1], 5, -165796510);
  86.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 6], 9, -1069501632);
  87.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 11], 14, 643717713);
  88.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 0], 20, -373897302);
  89.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 5], 5, -701558691);
  90.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 10], 9, 38016083);
  91.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 15], 14, -660478335);
  92.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 4], 20, -405537848);
  93.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 9], 5, 568446438);
  94.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 14], 9, -1019803690);
  95.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 3], 14, -187363961);
  96.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 8], 20, 1163531501);
  97.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 13], 5, -1444681467);
  98.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 2], 9, -51403784);
  99.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 7], 14, 1735328473);
  100.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 12], 20, -1926607734);
  101.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 5], 4, -378558);
  102.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 8], 11, -2022574463);
  103.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 11], 16, 1839030562);
  104.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 14], 23, -35309556);
  105.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 1], 4, -1530992060);
  106.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 4], 11, 1272893353);
  107.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 7], 16, -155497632);
  108.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 10], 23, -1094730640);
  109.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 13], 4, 681279174);
  110.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 0], 11, -358537222);
  111.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 3], 16, -722521979);
  112.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 6], 23, 76029189);
  113.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 9], 4, -640364487);
  114.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 12], 11, -421815835);
  115.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 15], 16, 530742520);
  116.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 2], 23, -995338651);
  117.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 0], 6, -198630844);
  118.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 7], 10, 1126891415);
  119.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 14], 15, -1416354905);
  120.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 5], 21, -57434055);
  121.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 12], 6, 1700485571);
  122.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 3], 10, -1894986606);
  123.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 10], 15, -1051523);
  124.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 1], 21, -2054922799);
  125.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 8], 6, 1873313359);
  126.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 15], 10, -30611744);
  127.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 6], 15, -1560198380);
  128.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 13], 21, 1309151649);
  129.                 _local5 = this.?(_local5, _local4, _local3, _local2, x[_local6 + 4], 6, -145523070);
  130.                 _local2 = this.?(_local2, _local5, _local4, _local3, x[_local6 + 11], 10, -1120210379);
  131.                 _local3 = this.?(_local3, _local2, _local5, _local4, x[_local6 + 2], 15, 718787259);
  132.                 _local4 = this.?(_local4, _local3, _local2, _local5, x[_local6 + 9], 21, -343485551);
  133.                 _local5 = this.?(_local5, _local11);
  134.                 _local4 = this.?(_local4, _local10);
  135.                 _local3 = this.?(_local3, _local9);
  136.                 _local2 = this.?(_local2, _local8);
  137.                 _local6 = _local6 + 16;
  138.             }
  139.             return (?(_local5, _local4, _local3, _local2));
  140.         };
  141.         _local2["?"] = function (key, data) {
  142.             var _local3 = new ? (this.?(key));
  143.             if (_local3["?"] > 16) {
  144.                 _local3 = this.?(_local3, key["?"] * this["?"]);
  145.             }
  146.             var _local4 = new ? (16);
  147.             var _local5 = new ? (16);
  148.             var _local2 = 0;
  149.             while (_local2 < 16) {
  150.                 _local4[_local2] = _local3[_local2] ^ 909522486;
  151.                 _local5[_local2] = _local3[_local2] ^ 1549556828;
  152.                 _local2++;
  153.             }
  154.             var _local6 = new ? (this.?(_local4.?(this.?(data)), 512 + (data["?"] * this["?"])));
  155.             return (this.?(_local5.?(_local6), 640));
  156.         };
  157.         _local2["?"] = function (x, y) {
  158.             var _local1 = new ? ((x & 65535) + (y & 65535));
  159.             var _local2 = new ? (((x >> 16) + (y >> 16)) + (_local1 >> 16));
  160.             return ((_local2 << 16) | (_local1 & 65535));
  161.         };
  162.         _local2["?"] = function (num, cnt) {
  163.             return ((num << cnt) | (num >>> (32 - cnt)));
  164.         };
  165.         _local2["?"] = function (str) {
  166.             var _local6 = new ? ();
  167.             var _local1 = 0;
  168.             var _local2 = 0;
  169.             var _local3 = 0;
  170.             var _local5 = 0;
  171.             var _local4 = 0;
  172.             while (_local4 < str["?"]) {
  173.                 _local3 = str.?(_local4);
  174.                 if (_local3 < 256) {
  175.                     _local5 = 1;
  176.                 } else {
  177.                     _local5 = 2;
  178.                  }
  179.                 if ((_local5 + _local1) < 5) {
  180.                     _local2 = _local2 | (_local3 << (_local1 * 8));
  181.                     _local1 = _local1 + _local5;
  182.                     if (_local1 == 4) {
  183.                         _local6.?(_local2);
  184.                         _local1 = 0;
  185.                         _local2 = 0;
  186.                     }
  187.                 } else {
  188.                     _local2 = _local2 | ((_local3 & 255) << (_local1 * 8));
  189.                     _local6.?(_local2);
  190.                     _local2 = _local3 >> 8;
  191.                     _local1 = 1;
  192.                  }
  193.                 _local4 = _local4 + 1;
  194.             }
  195.             if (_local1 != 0) {
  196.                 _local6.?(_local2);
  197.             }
  198.             return (_local6);
  199.         };
  200.         _local2["?"] = function (bin) {
  201.             var _local4 = new ? ("?");
  202.             var _local5 = (1 << this["?"]) - 1;
  203.             var _local2 = 0;
  204.             while (_local2 < (bin["?"] * 32)) {
  205.                 _local4 = _local4 + ?.?((bin[_local2 >> 5] >>> (_local2 % 32)) & _local5);
  206.                 _local2 = _local2 + this["?"];
  207.             }
  208.             return (_local4);
  209.         };
  210.         _local2["?"] = function (binarray) {
  211.             var _local3 = "?";
  212.             var _local4 = new ? ("?");
  213.             var _local1 = 0;
  214.             while (_local1 < (binarray["?"] * 4)) {
  215.                 _local4 = _local4 + (_local3.?((binarray[_local1 >> 2] >> (((_local1 % 4) * 8) + 4)) & 15) + _local3.?((binarray[_local1 >> 2] >> ((_local1 % 4) * 8)) & 15));
  216.                 _local1++;
  217.             }
  218.             return (_local4);
  219.         };
  220.         _local2["?"] = function (binarray) {
  221.             var _local7 = "?";
  222.             var _local5 = new ? ("?");
  223.             var _local3 = 0;
  224.             while (_local3 < (binarray["?"] * 4)) {
  225.                 var _local6 = ((((binarray[_local3 >> 2] >> (8 * (_local3 % 4))) & 255) << 16) | (((binarray[(_local3 + 1) >> 2] >> (8 * ((_local3 + 1) % 4))) & 255) << 8)) | ((binarray[(_local3 + 2) >> 2] >> (8 * ((_local3 + 2) % 4))) & 255);
  226.                 var _local2 = 0;
  227.                 while (_local2 < 4) {
  228.                     if (((_local3 * 8) + (_local2 * 6)) > (binarray["?"] * 32)) {
  229.                         _local5 = _local5 + this["?"];
  230.                     } else {
  231.                         _local5 = _local5 + _local7.?((_local6 >> (6 * (3 - _local2))) & 63);
  232.                      }
  233.                     _local2++;
  234.                 }
  235.                 _local3 = _local3 + 3;
  236.             }
  237.             return (_local5);
  238.         };
  239.         _local2["?"] = function (s) {
  240.             var _local5 = this.?(this.?(s), s["?"] * this["?"]);
  241.             var _local4 = new ? ();
  242.             var _local3 = 0;
  243.             while (_local3 < 4) {
  244.                 var _local2 = 0;
  245.                 while (_local2 < 32) {
  246.                     _local4.?((_local5[_local3] >> _local2) & 1);
  247.                     _local2++;
  248.                 }
  249.                 _local3++;
  250.             }
  251.             return (_local4);
  252.         };
  253.         _local2["?"] = new ? ("?");
  254.         _local2["?"] = new ? (8);
  255.         (?(?["?"]["?"]["?"], null, 1));// not popped
  256.     }
  257.     //
  258.     if (false) {
  259.     }
  260.     if (true) {
  261.         // branch @3279
  262.     }
  263.     // branch @2
  264. #endinitclip
复制代码
回复

使用道具 举报

发表于 2007-1-1 02:19:12 | 显示全部楼层
关键素怎么从MD5值算属性值...
回复

使用道具 举报

 楼主| 发表于 2007-1-1 03:38:55 | 显示全部楼层
做到魔兽里去啊?
回复

使用道具 举报

发表于 2007-1-1 13:17:39 | 显示全部楼层
555,现在偶正在翻以前的一篇MD5算法的文章。
怎么看都看不懂。
白银大人和910大人解释一下?
回复

使用道具 举报

发表于 2007-1-1 13:23:03 | 显示全部楼层
官方RFC文档...

=================式神の分割线===================

Network Working Group                                          R. Rivest
Request for Comments: 1321           MIT Laboratory for Computer Science
                                             and RSA Data Security, Inc.
                                                              April 1992


                     The MD5 Message-Digest Algorithm

Status of this Memo

   This memo provides information for the Internet community.  It does
   not specify an Internet standard.  Distribution of this memo is
   unlimited.

Acknowlegements

   We would like to thank Don Coppersmith, Burt Kaliski, Ralph Merkle,
   David Chaum, and Noam Nisan for numerous helpful comments and
   suggestions.

Table of Contents

   1. Executive Summary                                                1
   2. Terminology and Notation                                         2
   3. MD5 Algorithm Description                                        3
   4. Summary                                                          6
   5. Differences Between MD4 and MD5                                  6
   References                                                          7
   APPENDIX A - Reference Implementation                               7
   Security Considerations                                            21
   Author's Address                                                   21

1. Executive Summary

   This document describes the MD5 message-digest algorithm. The
   algorithm takes as input a message of arbitrary length and produces
   as output a 128-bit "fingerprint" or "message digest" of the input.
   It is conjectured that it is computationally infeasible to produce
   two messages having the same message digest, or to produce any
   message having a given prespecified target message digest. The MD5
   algorithm is intended for digital signature applications, where a
   large file must be "compressed" in a secure manner before being
   encrypted with a private (secret) key under a public-key cryptosystem
   such as RSA.







Rivest                                                          [Page 1]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


   The MD5 algorithm is designed to be quite fast on 32-bit machines. In
   addition, the MD5 algorithm does not require any large substitution
   tables; the algorithm can be coded quite compactly.

   The MD5 algorithm is an extension of the MD4 message-digest algorithm
   1,2]. MD5 is slightly slower than MD4, but is more "conservative" in
   design. MD5 was designed because it was felt that MD4 was perhaps
   being adopted for use more quickly than justified by the existing
   critical review; because MD4 was designed to be exceptionally fast,
   it is "at the edge" in terms of risking successful cryptanalytic
   attack. MD5 backs off a bit, giving up a little in speed for a much
   greater likelihood of ultimate security. It incorporates some
   suggestions made by various reviewers, and contains additional
   optimizations. The MD5 algorithm is being placed in the public domain
   for review and possible adoption as a standard.

   For OSI-based applications, MD5's object identifier is

   md5 OBJECT IDENTIFIER ::=
     iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) 5}

   In the X.509 type AlgorithmIdentifier [3], the parameters for MD5
   should have type NULL.

2. Terminology and Notation

   In this document a "word" is a 32-bit quantity and a "byte" is an
   eight-bit quantity. A sequence of bits can be interpreted in a
   natural manner as a sequence of bytes, where each consecutive group
   of eight bits is interpreted as a byte with the high-order (most
   significant) bit of each byte listed first. Similarly, a sequence of
   bytes can be interpreted as a sequence of 32-bit words, where each
   consecutive group of four bytes is interpreted as a word with the
   low-order (least significant) byte given first.

   Let x_i denote "x sub i". If the subscript is an expression, we
   surround it in braces, as in x_{i+1}. Similarly, we use ^ for
   superscripts (exponentiation), so that x^i denotes x to the i-th
   power.

   Let the symbol "+" denote addition of words (i.e., modulo-2^32
   addition). Let X <<< s denote the 32-bit value obtained by circularly
   shifting (rotating) X left by s bit positions. Let not(X) denote the
   bit-wise complement of X, and let X v Y denote the bit-wise OR of X
   and Y. Let X xor Y denote the bit-wise XOR of X and Y, and let XY
   denote the bit-wise AND of X and Y.





Rivest                                                          [Page 2]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


3. MD5 Algorithm Description

   We begin by supposing that we have a b-bit message as input, and that
   we wish to find its message digest. Here b is an arbitrary
   nonnegative integer; b may be zero, it need not be a multiple of
   eight, and it may be arbitrarily large. We imagine the bits of the
   message written down as follows:

          m_0 m_1 ... m_{b-1}

   The following five steps are performed to compute the message digest
   of the message.

3.1 Step 1. Append Padding Bits

   The message is "padded" (extended) so that its length (in bits) is
   congruent to 448, modulo 512. That is, the message is extended so
   that it is just 64 bits shy of being a multiple of 512 bits long.
   Padding is always performed, even if the length of the message is
   already congruent to 448, modulo 512.

   Padding is performed as follows: a single "1" bit is appended to the
   message, and then "0" bits are appended so that the length in bits of
   the padded message becomes congruent to 448, modulo 512. In all, at
   least one bit and at most 512 bits are appended.

3.2 Step 2. Append Length

   A 64-bit representation of b (the length of the message before the
   padding bits were added) is appended to the result of the previous
   step. In the unlikely event that b is greater than 2^64, then only
   the low-order 64 bits of b are used. (These bits are appended as two
   32-bit words and appended low-order word first in accordance with the
   previous conventions.)

   At this point the resulting message (after padding with bits and with
   b) has a length that is an exact multiple of 512 bits. Equivalently,
   this message has a length that is an exact multiple of 16 (32-bit)
   words. Let M[0 ... N-1] denote the words of the resulting message,
   where N is a multiple of 16.

3.3 Step 3. Initialize MD Buffer

   A four-word buffer (A,B,C,D) is used to compute the message digest.
   Here each of A, B, C, D is a 32-bit register. These registers are
   initialized to the following values in hexadecimal, low-order bytes
   first):




Rivest                                                          [Page 3]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


          word A: 01 23 45 67
          word B: 89 ab cd ef
          word C: fe dc ba 98
          word D: 76 54 32 10

3.4 Step 4. Process Message in 16-Word Blocks

   We first define four auxiliary functions that each take as input
   three 32-bit words and produce as output one 32-bit word.

          F(X,Y,Z) = XY v not(X) Z
          G(X,Y,Z) = XZ v Y not(Z)
          H(X,Y,Z) = X xor Y xor Z
          I(X,Y,Z) = Y xor (X v not(Z))

   In each bit position F acts as a conditional: if X then Y else Z.
   The function F could have been defined using + instead of v since XY
   and not(X)Z will never have 1's in the same bit position.) It is
   interesting to note that if the bits of X, Y, and Z are independent
   and unbiased, the each bit of F(X,Y,Z) will be independent and
   unbiased.

   The functions G, H, and I are similar to the function F, in that they
   act in "bitwise parallel" to produce their output from the bits of X,
   Y, and Z, in such a manner that if the corresponding bits of X, Y,
   and Z are independent and unbiased, then each bit of G(X,Y,Z),
   H(X,Y,Z), and I(X,Y,Z) will be independent and unbiased. Note that
   the function H is the bit-wise "xor" or "parity" function of its
   inputs.

   This step uses a 64-element table T[1 ... 64] constructed from the
   sine function. Let T denote the i-th element of the table, which
   is equal to the integer part of 4294967296 times abs(sin(i)), where i
   is in radians. The elements of the table are given in the appendix.

   Do the following:

   /* Process each 16-word block. */
   For i = 0 to N/16-1 do

     /* Copy block i into X. */
     For j = 0 to 15 do
       Set X[j] to M[i*16+j].
     end /* of loop on j */

     /* Save A as AA, B as BB, C as CC, and D as DD. */
     AA = A
     BB = B



Rivest                                                          [Page 4]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


     CC = C
     DD = D

     /* Round 1. */
     /* Let [abcd k s i] denote the operation
          a = b + ((a + F(b,c,d) + X[k] + T) <<< s). */
     /* Do the following 16 operations. */
     [ABCD  0  7  1]  [DABC  1 12  2]  [CDAB  2 17  3]  [BCDA  3 22  4]
     [ABCD  4  7  5]  [DABC  5 12  6]  [CDAB  6 17  7]  [BCDA  7 22  8]
     [ABCD  8  7  9]  [DABC  9 12 10]  [CDAB 10 17 11]  [BCDA 11 22 12]
     [ABCD 12  7 13]  [DABC 13 12 14]  [CDAB 14 17 15]  [BCDA 15 22 16]

     /* Round 2. */
     /* Let [abcd k s i] denote the operation
          a = b + ((a + G(b,c,d) + X[k] + T) <<< s). */
     /* Do the following 16 operations. */
     [ABCD  1  5 17]  [DABC  6  9 18]  [CDAB 11 14 19]  [BCDA  0 20 20]
     [ABCD  5  5 21]  [DABC 10  9 22]  [CDAB 15 14 23]  [BCDA  4 20 24]
     [ABCD  9  5 25]  [DABC 14  9 26]  [CDAB  3 14 27]  [BCDA  8 20 28]
     [ABCD 13  5 29]  [DABC  2  9 30]  [CDAB  7 14 31]  [BCDA 12 20 32]

     /* Round 3. */
     /* Let [abcd k s t] denote the operation
          a = b + ((a + H(b,c,d) + X[k] + T) <<< s). */
     /* Do the following 16 operations. */
     [ABCD  5  4 33]  [DABC  8 11 34]  [CDAB 11 16 35]  [BCDA 14 23 36]
     [ABCD  1  4 37]  [DABC  4 11 38]  [CDAB  7 16 39]  [BCDA 10 23 40]
     [ABCD 13  4 41]  [DABC  0 11 42]  [CDAB  3 16 43]  [BCDA  6 23 44]
     [ABCD  9  4 45]  [DABC 12 11 46]  [CDAB 15 16 47]  [BCDA  2 23 48]

     /* Round 4. */
     /* Let [abcd k s t] denote the operation
          a = b + ((a + I(b,c,d) + X[k] + T) <<< s). */
     /* Do the following 16 operations. */
     [ABCD  0  6 49]  [DABC  7 10 50]  [CDAB 14 15 51]  [BCDA  5 21 52]
     [ABCD 12  6 53]  [DABC  3 10 54]  [CDAB 10 15 55]  [BCDA  1 21 56]
     [ABCD  8  6 57]  [DABC 15 10 58]  [CDAB  6 15 59]  [BCDA 13 21 60]
     [ABCD  4  6 61]  [DABC 11 10 62]  [CDAB  2 15 63]  [BCDA  9 21 64]

     /* Then perform the following additions. (That is increment each
        of the four registers by the value it had before this block
        was started.) */
     A = A + AA
     B = B + BB
     C = C + CC
     D = D + DD

   end /* of loop on i */



Rivest                                                          [Page 5]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


3.5 Step 5. Output

   The message digest produced as output is A, B, C, D. That is, we
   begin with the low-order byte of A, and end with the high-order byte
   of D.

   This completes the description of MD5. A reference implementation in
   C is given in the appendix.

4. Summary

   The MD5 message-digest algorithm is simple to implement, and provides
   a "fingerprint" or message digest of a message of arbitrary length.
   It is conjectured that the difficulty of coming up with two messages
   having the same message digest is on the order of 2^64 operations,
   and that the difficulty of coming up with any message having a given
   message digest is on the order of 2^128 operations. The MD5 algorithm
   has been carefully scrutinized for weaknesses. It is, however, a
   relatively new algorithm and further security analysis is of course
   justified, as is the case with any new proposal of this sort.

5. Differences Between MD4 and MD5

     The following are the differences between MD4 and MD5:

       1.   A fourth round has been added.

       2.   Each step now has a unique additive constant.

       3.   The function g in round 2 was changed from (XY v XZ v YZ) to
       (XZ v Y not(Z)) to make g less symmetric.

       4.   Each step now adds in the result of the previous step.  This
       promotes a faster "avalanche effect".

       5.   The order in which input words are accessed in rounds 2 and
       3 is changed, to make these patterns less like each other.

       6.   The shift amounts in each round have been approximately
       optimized, to yield a faster "avalanche effect." The shifts in
       different rounds are distinct.










Rivest                                                          [Page 6]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


References

   [1] Rivest, R., "The MD4 Message Digest Algorithm", RFC 1320, MIT and
       RSA Data Security, Inc., April 1992.

   [2] Rivest, R., "The MD4 message digest algorithm", in A.J.  Menezes
       and S.A. Vanstone, editors, Advances in Cryptology - CRYPTO '90
       Proceedings, pages 303-311, Springer-Verlag, 1991.

   [3] CCITT Recommendation X.509 (1988), "The Directory -
       Authentication Framework."

APPENDIX A - Reference Implementation

   This appendix contains the following files taken from RSAREF: A
   Cryptographic Toolkit for Privacy-Enhanced Mail:

     global.h -- global header file

     md5.h -- header file for MD5

     md5c.c -- source code for MD5

   For more information on RSAREF, send email to <[email protected]>.

   The appendix also includes the following file:

     mddriver.c -- test driver for MD2, MD4 and MD5

   The driver compiles for MD5 by default but can compile for MD2 or MD4
   if the symbol MD is defined on the C compiler command line as 2 or 4.

   The implementation is portable and should work on many different
   plaforms. However, it is not difficult to optimize the implementation
   on particular platforms, an exercise left to the reader. For example,
   on "little-endian" platforms where the lowest-addressed byte in a 32-
   bit word is the least significant and there are no alignment
   restrictions, the call to Decode in MD5Transform can be replaced with
   a typecast.

A.1 global.h

/* GLOBAL.H - RSAREF types and constants
*/

/* PROTOTYPES should be set to one if and only if the compiler supports
  function argument prototyping.
The following makes PROTOTYPES default to 0 if it has not already



Rivest                                                          [Page 7]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


  been defined with C compiler flags.
*/
#ifndef PROTOTYPES
#define PROTOTYPES 0
#endif

/* POINTER defines a generic pointer type */
typedef unsigned char *POINTER;

/* UINT2 defines a two byte word */
typedef unsigned short int UINT2;

/* UINT4 defines a four byte word */
typedef unsigned long int UINT4;

/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
  returns an empty list.
*/
#if PROTOTYPES
#define PROTO_LIST(list) list
#else
#define PROTO_LIST(list) ()
#endif

A.2 md5.h

/* MD5.H - header file for MD5C.C
*/

/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.

License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.

License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.

RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.




Rivest                                                          [Page 8]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


These notices must be retained in any copies of any part of this
documentation and/or software.
*/

/* MD5 context. */
typedef struct {
  UINT4 state[4];                                   /* state (ABCD) */
  UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
  unsigned char buffer[64];                         /* input buffer */
} MD5_CTX;

void MD5Init PROTO_LIST ((MD5_CTX *));
void MD5Update PROTO_LIST
  ((MD5_CTX *, unsigned char *, unsigned int));
void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));

A.3 md5c.c

/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
*/

/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.

License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.

License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.

RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.

These notices must be retained in any copies of any part of this
documentation and/or software.
*/

#include "global.h"
#include "md5.h"

/* Constants for MD5Transform routine.
*/



Rivest                                                          [Page 9]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21

static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
static void Encode PROTO_LIST
  ((unsigned char *, UINT4 *, unsigned int));
static void Decode PROTO_LIST
  ((UINT4 *, unsigned char *, unsigned int));
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));

static unsigned char PADDING[64] = {
  0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

/* F, G, H and I are basic MD5 functions.
*/
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))

/* ROTATE_LEFT rotates x left n bits.
*/
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))

/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/
#define FF(a, b, c, d, x, s, ac) { \\
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \\
(a) = ROTATE_LEFT ((a), (s)); \\



Rivest                                                         [Page 10]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


(a) += (b); \\
  }
#define GG(a, b, c, d, x, s, ac) { \\
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \\
(a) = ROTATE_LEFT ((a), (s)); \\
(a) += (b); \\
  }
#define HH(a, b, c, d, x, s, ac) { \\
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \\
(a) = ROTATE_LEFT ((a), (s)); \\
(a) += (b); \\
  }
#define II(a, b, c, d, x, s, ac) { \\
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \\
(a) = ROTATE_LEFT ((a), (s)); \\
(a) += (b); \\
  }

/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
void MD5Init (context)
MD5_CTX *context;                                        /* context */
{
  context->count[0] = context->count[1] = 0;
  /* Load magic initialization constants.
*/
  context->state[0] = 0x67452301;
  context->state[1] = 0xefcdab89;
  context->state[2] = 0x98badcfe;
  context->state[3] = 0x10325476;
}

/* MD5 block update operation. Continues an MD5 message-digest
  operation, processing another message block, and updating the
  context.
*/
void MD5Update (context, input, inputLen)
MD5_CTX *context;                                        /* context */
unsigned char *input;                                /* input block */
unsigned int inputLen;                     /* length of input block */
{
  unsigned int i, index, partLen;

  /* Compute number of bytes mod 64 */
  index = (unsigned int)((context->count[0] >> 3) & 0x3F);

  /* Update number of bits */
  if ((context->count[0] += ((UINT4)inputLen << 3))



Rivest                                                         [Page 11]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


   < ((UINT4)inputLen << 3))
context->count[1]++;
  context->count[1] += ((UINT4)inputLen >> 29);

  partLen = 64 - index;

  /* Transform as many times as possible.
*/
  if (inputLen >= partLen) {
MD5_memcpy
   ((POINTER)&context->buffer[index], (POINTER)input, partLen);
MD5Transform (context->state, context->buffer);

for (i = partLen; i + 63 < inputLen; i += 64)
   MD5Transform (context->state, &input);

index = 0;
  }
  else
i = 0;

  /* Buffer remaining input */
  MD5_memcpy
((POINTER)&context->buffer[index], (POINTER)&input,
  inputLen-i);
}

/* MD5 finalization. Ends an MD5 message-digest operation, writing the
  the message digest and zeroizing the context.
*/
void MD5Final (digest, context)
unsigned char digest[16];                         /* message digest */
MD5_CTX *context;                                       /* context */
{
  unsigned char bits[8];
  unsigned int index, padLen;

  /* Save number of bits */
  Encode (bits, context->count, 8);

  /* Pad out to 56 mod 64.
*/
  index = (unsigned int)((context->count[0] >> 3) & 0x3f);
  padLen = (index < 56) ? (56 - index) : (120 - index);
  MD5Update (context, PADDING, padLen);

  /* Append length (before padding) */
  MD5Update (context, bits, 8);



Rivest                                                         [Page 12]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


  /* Store state in digest */
  Encode (digest, context->state, 16);

  /* Zeroize sensitive information.
*/
  MD5_memset ((POINTER)context, 0, sizeof (*context));
}

/* MD5 basic transformation. Transforms state based on block.
*/
static void MD5Transform (state, block)
UINT4 state[4];
unsigned char block[64];
{
  UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];

  Decode (x, block, 64);

  /* Round 1 */
  FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */

/* Round 2 */
  GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
  GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */



Rivest                                                         [Page 13]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


  GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */

  /* Round 3 */
  HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
  HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */

  /* Round 4 */
  II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */

  state[0] += a;
  state[1] += b;
  state[2] += c;
  state[3] += d;

  /* Zeroize sensitive information.



Rivest                                                         [Page 14]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


*/
  MD5_memset ((POINTER)x, 0, sizeof (x));
}

/* Encodes input (UINT4) into output (unsigned char). Assumes len is
  a multiple of 4.
*/
static void Encode (output, input, len)
unsigned char *output;
UINT4 *input;
unsigned int len;
{
  unsigned int i, j;

  for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char)(input & 0xff);
output[j+1] = (unsigned char)((input >> 8) & 0xff);
output[j+2] = (unsigned char)((input >> 16) & 0xff);
output[j+3] = (unsigned char)((input >> 24) & 0xff);
  }
}

/* Decodes input (unsigned char) into output (UINT4). Assumes len is
  a multiple of 4.
*/
static void Decode (output, input, len)
UINT4 *output;
unsigned char *input;
unsigned int len;
{
  unsigned int i, j;

  for (i = 0, j = 0; j < len; i++, j += 4)
output = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
   (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}

/* Note: Replace "for loop" with standard memcpy if possible.
*/

static void MD5_memcpy (output, input, len)
POINTER output;
POINTER input;
unsigned int len;
{
  unsigned int i;

  for (i = 0; i < len; i++)



Rivest                                                         [Page 15]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


output = input;
}

/* Note: Replace "for loop" with standard memset if possible.
*/
static void MD5_memset (output, value, len)
POINTER output;
int value;
unsigned int len;
{
  unsigned int i;

  for (i = 0; i < len; i++)
((char *)output) = (char)value;
}

A.4 mddriver.c

/* MDDRIVER.C - test driver for MD2, MD4 and MD5
*/

/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
rights reserved.

RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.

These notices must be retained in any copies of any part of this
documentation and/or software.
*/

/* The following makes MD default to MD5 if it has not already been
  defined with C compiler flags.
*/
#ifndef MD
#define MD MD5
#endif

#include <stdio.h>
#include <time.h>
#include <string.h>
#include "global.h"
#if MD == 2
#include "md2.h"
#endif
#if MD == 4



Rivest                                                         [Page 16]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


#include "md4.h"
#endif
#if MD == 5
#include "md5.h"
#endif

/* Length of test block, number of test blocks.
*/
#define TEST_BLOCK_LEN 1000
#define TEST_BLOCK_COUNT 1000

static void MDString PROTO_LIST ((char *));
static void MDTimeTrial PROTO_LIST ((void));
static void MDTestSuite PROTO_LIST ((void));
static void MDFile PROTO_LIST ((char *));
static void MDFilter PROTO_LIST ((void));
static void MDPrint PROTO_LIST ((unsigned char [16]));

#if MD == 2
#define MD_CTX MD2_CTX
#define MDInit MD2Init
#define MDUpdate MD2Update
#define MDFinal MD2Final
#endif
#if MD == 4
#define MD_CTX MD4_CTX
#define MDInit MD4Init
#define MDUpdate MD4Update
#define MDFinal MD4Final
#endif
#if MD == 5
#define MD_CTX MD5_CTX
#define MDInit MD5Init
#define MDUpdate MD5Update
#define MDFinal MD5Final
#endif

/* Main driver.

Arguments (may be any combination):
  -sstring - digests string
  -t       - runs time trial
  -x       - runs test script
  filename - digests file
  (none)   - digests standard input
*/
int main (argc, argv)
int argc;



Rivest                                                         [Page 17]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


char *argv[];
{
  int i;

  if (argc > 1)
for (i = 1; i < argc; i++)
   if (argv[0] == '-' && argv[1] == 's')
     MDString (argv + 2);
   else if (strcmp (argv, "-t") == 0)
     MDTimeTrial ();
   else if (strcmp (argv, "-x") == 0)
     MDTestSuite ();
   else
     MDFile (argv);
  else
MDFilter ();

  return (0);
}

/* Digests a string and prints the result.
*/
static void MDString (string)
char *string;
{
  MD_CTX context;
  unsigned char digest[16];
  unsigned int len = strlen (string);

  MDInit (&context);
  MDUpdate (&context, string, len);
  MDFinal (digest, &context);

  printf ("MD%d (\\"%s\\") = ", MD, string);
  MDPrint (digest);
  printf ("\\n");
}

/* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
  blocks.
*/
static void MDTimeTrial ()
{
  MD_CTX context;
  time_t endTime, startTime;
  unsigned char block[TEST_BLOCK_LEN], digest[16];
  unsigned int i;




Rivest                                                         [Page 18]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


  printf
("MD%d time trial. Digesting %d %d-byte blocks ...", MD,
  TEST_BLOCK_LEN, TEST_BLOCK_COUNT);

  /* Initialize block */
  for (i = 0; i < TEST_BLOCK_LEN; i++)
block = (unsigned char)(i & 0xff);

  /* Start timer */
  time (&startTime);

  /* Digest blocks */
  MDInit (&context);
  for (i = 0; i < TEST_BLOCK_COUNT; i++)
MDUpdate (&context, block, TEST_BLOCK_LEN);
  MDFinal (digest, &context);

  /* Stop timer */
  time (&endTime);

  printf (" done\\n");
  printf ("Digest = ");
  MDPrint (digest);
  printf ("\\nTime = %ld seconds\\n", (long)(endTime-startTime));
  printf
("Speed = %ld bytes/second\\n",
  (long)TEST_BLOCK_LEN * (long)TEST_BLOCK_COUNT/(endTime-startTime));
}

/* Digests a reference suite of strings and prints the results.
*/
static void MDTestSuite ()
{
  printf ("MD%d test suite:\\n", MD);

  MDString ("");
  MDString ("a");
  MDString ("abc");
  MDString ("message digest");
  MDString ("abcdefghijklmnopqrstuvwxyz");
  MDString
("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
  MDString
("1234567890123456789012345678901234567890\\
1234567890123456789012345678901234567890");
}

/* Digests a file and prints the result.



Rivest                                                         [Page 19]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


*/
static void MDFile (filename)
char *filename;
{
  FILE *file;
  MD_CTX context;
  int len;
  unsigned char buffer[1024], digest[16];

  if ((file = fopen (filename, "rb")) == NULL)
printf ("%s can't be opened\\n", filename);

  else {
MDInit (&context);
while (len = fread (buffer, 1, 1024, file))
   MDUpdate (&context, buffer, len);
MDFinal (digest, &context);

fclose (file);

printf ("MD%d (%s) = ", MD, filename);
MDPrint (digest);
printf ("\\n");
  }
}

/* Digests the standard input and prints the result.
*/
static void MDFilter ()
{
  MD_CTX context;
  int len;
  unsigned char buffer[16], digest[16];

  MDInit (&context);
  while (len = fread (buffer, 1, 16, stdin))
MDUpdate (&context, buffer, len);
  MDFinal (digest, &context);

  MDPrint (digest);
  printf ("\\n");
}

/* Prints a message digest in hexadecimal.
*/
static void MDPrint (digest)
unsigned char digest[16];
{



Rivest                                                         [Page 20]

RFC 1321              MD5 Message-Digest Algorithm            April 1992


  unsigned int i;

  for (i = 0; i < 16; i++)
printf ("%02x", digest);
}

A.5 Test suite

   The MD5 test suite (driver option "-x") should print the following
   results:

MD5 test suite:
MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
d174ab98d277d9f5a5611c2c9f419d9f
MD5 ("123456789012345678901234567890123456789012345678901234567890123456
78901234567890") = 57edf4a22be3c955ac49da2e2107b67a

Security Considerations

   The level of security discussed in this memo is considered to be
   sufficient for implementing very high security hybrid digital-
   signature schemes based on MD5 and a public-key cryptosystem.

Author's Address

   Ronald L. Rivest
   Massachusetts Institute of Technology
   Laboratory for Computer Science
   NE43-324
   545 Technology Square
   Cambridge, MA  02139-1986

   Phone: (617) 253-5880
   EMail: [email protected]
回复

使用道具 举报

发表于 2007-1-1 14:46:35 | 显示全部楼层
这个偶也有啊。只是看不懂英文。
主要是512字节分组。
每一位都是byte的吧?
然后分成16组32位的。
也都是byte的?byte[32]
然后接下来的。
FF(a,b,c,d,Mj,s,ti) => a=b+((a+(F(b,c,d)+Mj+ti)
如此。
Mj应该是一个byte[32]。这样如何相加呢?

5555,好吧。我现在米有认真的看到那个文档。跑去再看一次。
回复

使用道具 举报

发表于 2007-1-1 14:49:11 | 显示全部楼层
555,好吧。我看到RFC上说的是bits。
不是byte。看来网上流传的那个中文的文章真是害我不浅啊。
继续研究。
回复

使用道具 举报

发表于 2007-1-1 15:10:55 | 显示全部楼层
终于知道为什么中文不对了——因为该Flash代码有Bug!


该Flash为了支持中文,修改了原来的str2binl函数:
如果是U+0000~U+00FF之间的字符,输出一个字节(低8位)
如果是U+0100~U+FFFF之间的字符,输出两个字节(UTF-16)

表面上看这样似乎很完美
但是,它没有修改hex_md5函数
该函数仍然是“core_md5(str2binl(s), s.length*chrsz)”

假设现在输入的是“中文”
那么str2binl的结果是“2D 4E FD 56”这4个字节
可s.length还是2
所以“core_md5(str2binl(s), s.length*chrsz)”等价于“core_md5(2D 4E FD 56, 16)”

虽然MD5运算程序是按照16位数据来计算的
可传过来的32位数据已经破坏了缓冲区

由于.net中的MD5是不存在Bug,一定会自动截取数据
所以用.net中的MD5类是无法模拟出该Flash的运算结果的
回复

使用道具 举报

发表于 2007-1-1 15:14:08 | 显示全部楼层
所以要自己写MD5算法...

难道某A也准备做一个地精MD5大作战?
回复

使用道具 举报

发表于 2007-1-1 15:17:13 | 显示全部楼层
555,只是为老研究而已。
为啥米要做地精MD5大战呢。
太米创意老。

现在偶又混乱老。
512素
512个字符。还素512位呢?
好像应该素512位。
如此的话。16组32位。就是16个32位的整数老。
嗯嗯。如果素这样的话。就可以计算老。555。
试一下看看。
回复

使用道具 举报

发表于 2007-1-1 22:24:21 | 显示全部楼层
MD5作战flash版,v1.20

spinoza  HP:388 攻:90 防:83 速:56 技:82 运:51
地精研究院  HP:309 攻:59 防:67 速:82 技:50 运:89

[地精研究院]向[spinoza]发起攻击,[spinoza]受到30点伤害
[spinoza]向[地精研究院]发起攻击,[地精研究院]受到113点伤害
[地精研究院]向[spinoza]发起攻击,但是被[spinoza]闪开了
[spinoza]向[地精研究院]发起攻击,[地精研究院]受到117点伤害
[地精研究院]向[spinoza]发起攻击,但是却被[spinoza]绊倒了,[地精研究院]受到49点伤害
[spinoza]向[地精研究院]发起攻击,[地精研究院]受到94点伤害
[地精研究院]被击败了
回复

使用道具 举报

发表于 2007-1-1 23:11:53 | 显示全部楼层
调试了了一晚上,终于将MD5转换给搞定了
明天再去弄人物属性转换吧

C#
  1. class MyMD5
  2. {
  3.     static char[] hexDigits = {
  4.                                   '0', '1', '2', '3', '4', '5', '6', '7',
  5.                                   '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  6.     public static string ToHexString(byte[] bytes)
  7.     {
  8.         char[] chars = new char[bytes.Length * 2];
  9.         for (int i = 0; i < bytes.Length; i++)
  10.         {
  11.             int b = bytes[i];
  12.             chars[i * 2] = hexDigits[b >> 4];
  13.             chars[i * 2 + 1] = hexDigits[b & 0xF];
  14.         }
  15.         return new string(chars);
  16.     }
  17.     public static string ToHexString(UInt32[] Arr)
  18.     {
  19.         char[] chars = new char[Arr.Length * 8];
  20.         for (int i = 0; i < Arr.Length; i++)
  21.         {
  22.             UInt32 b = Arr[i];
  23.             chars[i * 8 + 0] = hexDigits[(b & 0xF0000000)>>28];
  24.             chars[i * 8 + 1] = hexDigits[(b & 0x0F000000)>>24];
  25.             chars[i * 8 + 2] = hexDigits[(b & 0x00F00000)>>20];
  26.             chars[i * 8 + 3] = hexDigits[(b & 0x000F0000)>>16];
  27.             chars[i * 8 + 4] = hexDigits[(b & 0x0000F000)>>12];
  28.             chars[i * 8 + 5] = hexDigits[(b & 0x00000F00)>> 8];
  29.             chars[i * 8 + 6] = hexDigits[(b & 0x000000F0)>> 4];
  30.             chars[i * 8 + 7] = hexDigits[(b & 0x0000000F)>> 0];
  31.         }
  32.         return new string(chars);
  33.     }
  34.     public static int Array1to4(byte[] arrS, UInt32[] arrD)
  35.     {
  36.         UInt32 dw = 0;
  37.         int cb = 0;
  38.         int i,j;
  39.         j=0;
  40.         for(i=0; i<arrS.Length; i++)
  41.         {
  42.             dw |= (UInt32)arrS[i] << (cb*8);
  43.             cb++;
  44.             if(cb>=4)
  45.             {
  46.                 cb -= 4;
  47.                 arrD[j++] = dw;
  48.                 dw=0;
  49.             }
  50.         }
  51.         if (cb!=0)
  52.         {
  53.             arrD[j++] = dw;
  54.         }
  55.         return j;
  56.     }
  57.     public static int Array4to1(UInt32[] arrS, byte[] arrD)
  58.     {
  59.         int i=0;
  60.         foreach(UInt32 dw in arrS)
  61.         {
  62.             UInt32 u=dw;
  63.             arrD[i++] = (byte)u; u>>=8;
  64.             arrD[i++] = (byte)u; u>>=8;
  65.             arrD[i++] = (byte)u; u>>=8;
  66.             arrD[i++] = (byte)u; //dw>>=8;
  67.         }
  68.         return arrS.Length*4;
  69.     }
  70.     public static byte[] str2binV2(string s)
  71.     {
  72.         /*Encoding conv = Encoding.Unicode;
  73.             return conv.GetBytes(s);*/
  74.         char[] chArr = s.ToCharArray();
  75.         int cb=0;
  76.         foreach(char ch in chArr)
  77.         {
  78.             cb += (ch<256)?1:2;
  79.         }
  80.         byte[] buf = new byte[cb];
  81.         int I=0;
  82.         foreach(char ch in chArr)
  83.         {
  84.             if (ch<256)
  85.             {
  86.                 buf[I] = (byte)ch;
  87.                 I += 1;
  88.             }
  89.             else
  90.             {
  91.                 buf[I] = (byte)ch;
  92.                 buf[I+1] = (byte)(ch >> 8);
  93.                 I += 2;
  94.             }
  95.         }
  96.         return buf; // "core_md5(str2binl(s), s.length*chrsz)",限制了长度
  97.         /*byte[] buf2 = new byte[s.Length];
  98.             Array.Copy(buf,0,buf2,0,s.Length);
  99.             return buf2;*/
  100.     }
  101.     public static string hex_md5(string s)
  102.     {
  103.         /*return binl2hex(core_md5(str2binl(s), s.length*chrsz));*/
  104.         byte[] buf = str2binV2(s);
  105.         int n = (buf.Length + 3)/4;
  106.         n = (n+15) & -16;
  107.         UInt32[] buf4B = new UInt32[n];
  108.         Array1to4(buf, buf4B);
  109.         //return ToHexString(core_md5(buf4B, s.Length * 8));
  110.         byte[] bufmd5 = new byte[16];
  111.         Array4to1(core_md5(buf4B, s.Length * 8),bufmd5);
  112.         return ToHexString(bufmd5);
  113.     }
  114.     public static UInt32[] core_md5(UInt32[] x, int len)
  115.     {
  116.         x[len >> 5] |= (UInt32)0x80 << ((len)%32); x[(((len+64) >> 9) << 4)+14] = unchecked((UInt32)len);
  117.         UInt32 a = 0x67452301, b = 0xefcdab89, c = 0x98badcfe, d = 0x10325476;
  118.         for (int i = 0; i<x.Length; i += 16)
  119.         {
  120.             UInt32 olda = a, oldb = b, oldc = c, oldd = d;
  121.             a = md5_ff(a, b, c, d, x[i+0], 7, 0xd76aa478);
  122.             d = md5_ff(d, a, b, c, x[i+1], 12, 0xe8c7b756);
  123.             c = md5_ff(c, d, a, b, x[i+2], 17, 0x242070db);
  124.             b = md5_ff(b, c, d, a, x[i+3], 22, 0xc1bdceee);
  125.             a = md5_ff(a, b, c, d, x[i+4], 7, 0xf57c0faf);
  126.             d = md5_ff(d, a, b, c, x[i+5], 12, 0x4787c62a);
  127.             c = md5_ff(c, d, a, b, x[i+6], 17, 0xa8304613);
  128.             b = md5_ff(b, c, d, a, x[i+7], 22, 0xfd469501);
  129.             a = md5_ff(a, b, c, d, x[i+8], 7, 0x698098d8);
  130.             d = md5_ff(d, a, b, c, x[i+9], 12, 0x8b44f7af);
  131.             c = md5_ff(c, d, a, b, x[i+10], 17, 0xffff5bb1);
  132.             b = md5_ff(b, c, d, a, x[i+11], 22, 0x895cd7be);
  133.             a = md5_ff(a, b, c, d, x[i+12], 7, 0x6b901122);
  134.             d = md5_ff(d, a, b, c, x[i+13], 12, 0xfd987193);
  135.             c = md5_ff(c, d, a, b, x[i+14], 17, 0xa679438e);
  136.             b = md5_ff(b, c, d, a, x[i+15], 22, 0x49b40821);
  137.             a = md5_gg(a, b, c, d, x[i+1], 5, 0xf61e2562);
  138.             d = md5_gg(d, a, b, c, x[i+6], 9, 0xc040b340);
  139.             c = md5_gg(c, d, a, b, x[i+11], 14, 0x265e5a51);
  140.             b = md5_gg(b, c, d, a, x[i+0], 20, 0xe9b6c7aa);
  141.             a = md5_gg(a, b, c, d, x[i+5], 5, 0xd62f105d);
  142.             d = md5_gg(d, a, b, c, x[i+10], 9, 0x2441453);
  143.             c = md5_gg(c, d, a, b, x[i+15], 14, 0xd8a1e681);
  144.             b = md5_gg(b, c, d, a, x[i+4], 20, 0xe7d3fbc8);
  145.             a = md5_gg(a, b, c, d, x[i+9], 5, 0x21e1cde6);
  146.             d = md5_gg(d, a, b, c, x[i+14], 9, 0xc33707d6);
  147.             c = md5_gg(c, d, a, b, x[i+3], 14, 0xf4d50d87);
  148.             b = md5_gg(b, c, d, a, x[i+8], 20, 0x455a14ed);
  149.             a = md5_gg(a, b, c, d, x[i+13], 5, 0xa9e3e905);
  150.             d = md5_gg(d, a, b, c, x[i+2], 9, 0xfcefa3f8);
  151.             c = md5_gg(c, d, a, b, x[i+7], 14, 0x676f02d9);
  152.             b = md5_gg(b, c, d, a, x[i+12], 20, 0x8d2a4c8a);
  153.             a = md5_hh(a, b, c, d, x[i+5], 4, 0xfffa3942);
  154.             d = md5_hh(d, a, b, c, x[i+8], 11, 0x8771f681);
  155.             c = md5_hh(c, d, a, b, x[i+11], 16, 0x6d9d6122);
  156.             b = md5_hh(b, c, d, a, x[i+14], 23, 0xfde5380c);
  157.             a = md5_hh(a, b, c, d, x[i+1], 4, 0xa4beea44);
  158.             d = md5_hh(d, a, b, c, x[i+4], 11, 0x4bdecfa9);
  159.             c = md5_hh(c, d, a, b, x[i+7], 16, 0xf6bb4b60);
  160.             b = md5_hh(b, c, d, a, x[i+10], 23, 0xbebfbc70);
  161.             a = md5_hh(a, b, c, d, x[i+13], 4, 0x289b7ec6);
  162.             d = md5_hh(d, a, b, c, x[i+0], 11, 0xeaa127fa);
  163.             c = md5_hh(c, d, a, b, x[i+3], 16, 0xd4ef3085);
  164.             b = md5_hh(b, c, d, a, x[i+6], 23, 0x4881d05);
  165.             a = md5_hh(a, b, c, d, x[i+9], 4, 0xd9d4d039);
  166.             d = md5_hh(d, a, b, c, x[i+12], 11, 0xe6db99e5);
  167.             c = md5_hh(c, d, a, b, x[i+15], 16, 0x1fa27cf8);
  168.             b = md5_hh(b, c, d, a, x[i+2], 23, 0xc4ac5665);
  169.             a = md5_ii(a, b, c, d, x[i+0], 6, 0xf4292244);
  170.             d = md5_ii(d, a, b, c, x[i+7], 10, 0x432aff97);
  171.             c = md5_ii(c, d, a, b, x[i+14], 15, 0xab9423a7);
  172.             b = md5_ii(b, c, d, a, x[i+5], 21, 0xfc93a039);
  173.             a = md5_ii(a, b, c, d, x[i+12], 6, 0x655b59c3);
  174.             d = md5_ii(d, a, b, c, x[i+3], 10, 0x8f0ccc92);
  175.             c = md5_ii(c, d, a, b, x[i+10], 15, 0xffeff47d);
  176.             b = md5_ii(b, c, d, a, x[i+1], 21, 0x85845dd1);
  177.             a = md5_ii(a, b, c, d, x[i+8], 6, 0x6fa87e4f);
  178.             d = md5_ii(d, a, b, c, x[i+15], 10, 0xfe2ce6e0);
  179.             c = md5_ii(c, d, a, b, x[i+6], 15, 0xa3014314);
  180.             b = md5_ii(b, c, d, a, x[i+13], 21, 0x4e0811a1);
  181.             a = md5_ii(a, b, c, d, x[i+4], 6, 0xf7537e82);
  182.             d = md5_ii(d, a, b, c, x[i+11], 10, 0xbd3af235);
  183.             c = md5_ii(c, d, a, b, x[i+2], 15, 0x2ad7d2bb);
  184.             b = md5_ii(b, c, d, a, x[i+9], 21, 0xeb86d391);
  185.             a = safe_add(a, olda); b = safe_add(b, oldb);
  186.             c = safe_add(c, oldc); d = safe_add(d, oldd);
  187.         }
  188.         return new UInt32[] {a, b, c, d};
  189.     }
  190.     private static UInt32 md5_cmn(UInt32 q, UInt32 a, UInt32 b, UInt32 x, UInt32 s, UInt32 t) { return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b); }
  191.     private static UInt32 md5_ff(UInt32 a, UInt32 b, UInt32 c, UInt32 d, UInt32 x, UInt32 s, UInt32 t) { return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); }
  192.     private static UInt32 md5_gg(UInt32 a, UInt32 b, UInt32 c, UInt32 d, UInt32 x, UInt32 s, UInt32 t) { return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); }
  193.     private static UInt32 md5_hh(UInt32 a, UInt32 b, UInt32 c, UInt32 d, UInt32 x, UInt32 s, UInt32 t) { return md5_cmn(b ^ c ^ d, a, b, x, s, t); }
  194.     private static UInt32 md5_ii(UInt32 a, UInt32 b, UInt32 c, UInt32 d, UInt32 x, UInt32 s, UInt32 t) { return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); }
  195.     private static UInt32 safe_add(UInt32 x, UInt32 y)
  196.     {
  197.         UInt32 lsw = (x & 0xFFFF)+(y & 0xFFFF); UInt32 msw = (x >> 16)+(y >> 16)+(lsw >> 16);
  198.         return (msw << 16) | (lsw & 0xFFFF);
  199.     }
  200.     private static UInt32 bit_rol(UInt32 num, UInt32 cnt) { return (num << (int)cnt) | (num >> (int)(32-cnt)); }
  201. }
复制代码
回复

使用道具 举报

发表于 2007-1-1 23:27:51 | 显示全部楼层
太强大鸟...
现在java和c#都有鸟...
偶再传个c++版的...
这样基本就齐料...
回复

使用道具 举报

发表于 2007-1-1 23:30:41 | 显示全部楼层
作废...
回复

使用道具 举报

发表于 2007-1-2 09:42:10 | 显示全部楼层
555,可素JAVA版本根本米正确嘛。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-11-25 00:25 , Processed in 0.154798 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表