⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 md5的介绍,算法和实现.htm

📁 MD5算法的相关资料
💻 HTM
📖 第 1 页 / 共 3 页
字号:
  /* 20 */ <BR>&nbsp; GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ 
  <BR>&nbsp; GG (d, a, b, c, x[10], S22,&nbsp; 0x2441453); /* 22 */ <BR>&nbsp; 
  GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ <BR>&nbsp; GG (b, c, d, a, 
  x[ 4], S24, 0xe7d3fbc8); /* 24 */ <BR>&nbsp; GG (a, b, c, d, x[ 9], S21, 
  0x21e1cde6); /* 25 */ <BR>&nbsp; GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 
  26 */ <BR>&nbsp; GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ <BR>&nbsp; 
  GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ <BR>&nbsp; GG (a, b, c, d, 
  x[13], S21, 0xa9e3e905); /* 29 */ <BR>&nbsp; GG (d, a, b, c, x[ 2], S22, 
  0xfcefa3f8); /* 30 */ <BR>&nbsp; GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 
  31 */ <BR>&nbsp; GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ 
  <BR><BR>&nbsp; /* 第三轮循环 */ <BR>&nbsp; HH (a, b, c, d, x[ 5], S31, 0xfffa3942); 
  /* 33 */ <BR>&nbsp; HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ 
  <BR>&nbsp; HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ <BR>&nbsp; HH (b, 
  c, d, a, x[14], S34, 0xfde5380c); /* 36 */ <BR>&nbsp; HH (a, b, c, d, x[ 1], 
  S31, 0xa4beea44); /* 37 */ <BR>&nbsp; HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); 
  /* 38 */ <BR>&nbsp; HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ 
  <BR>&nbsp; HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ <BR>&nbsp; HH (a, 
  b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ <BR>&nbsp; HH (d, a, b, c, x[ 0], 
  S32, 0xeaa127fa); /* 42 */ <BR>&nbsp; HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); 
  /* 43 */ <BR>&nbsp; HH (b, c, d, a, x[ 6], S34,&nbsp; 0x4881d05); /* 44 */ 
  <BR>&nbsp; HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ <BR>&nbsp; HH (d, 
  a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ <BR>&nbsp; HH (c, d, a, b, x[15], 
  S33, 0x1fa27cf8); /* 47 */ <BR>&nbsp; HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); 
  /* 48 */ <BR><BR>&nbsp; /* 第四轮循环 */ <BR>&nbsp; II (a, b, c, d, x[ 0], S41, 
  0xf4292244); /* 49 */ <BR>&nbsp; II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 
  50 */ <BR>&nbsp; II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ <BR>&nbsp; 
  II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ <BR>&nbsp; II (a, b, c, d, 
  x[12], S41, 0x655b59c3); /* 53 */ <BR>&nbsp; II (d, a, b, c, x[ 3], S42, 
  0x8f0ccc92); /* 54 */ <BR>&nbsp; II (c, d, a, b, x[10], S43, 0xffeff47d); /* 
  55 */ <BR>&nbsp; II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ <BR>&nbsp; 
  II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ <BR>&nbsp; II (d, a, b, c, 
  x[15], S42, 0xfe2ce6e0); /* 58 */ <BR>&nbsp; II (c, d, a, b, x[ 6], S43, 
  0xa3014314); /* 59 */ <BR>&nbsp; II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 
  60 */ <BR>&nbsp; II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ <BR>&nbsp; 
  II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ <BR>&nbsp; II (c, d, a, b, 
  x[ 2], S43, 0x2ad7d2bb); /* 63 */ <BR>&nbsp; II (b, c, d, a, x[ 9], S44, 
  0xeb86d391); /* 64 */ <BR><BR>&nbsp; state[0] += a; <BR>&nbsp; state[1] += b; 
  <BR>&nbsp; state[2] += c; <BR>&nbsp; state[3] += d; <BR><BR>&nbsp; MD5_memset 
  ((POINTER)x, 0, sizeof (x)); <BR><BR>} <BR>static void Encode (output, input, 
  len) <BR>unsigned char *output; <BR>UINT4 *input; <BR>unsigned int len; <BR>{ 
  <BR>&nbsp; unsigned int i, j; <BR><BR>&nbsp; for (i = 0, j = 0; j &lt; len; 
  i++, j += 4) { <BR>output[j] = (unsigned char)(input[i] &amp; 0xff); 
  <BR>output[j+1] = (unsigned char)((input[i] &gt;&gt; 8) &amp; 0xff); 
  <BR>output[j+2] = (unsigned char)((input[i] &gt;&gt; 16) &amp; 0xff); 
  <BR>output[j+3] = (unsigned char)((input[i] &gt;&gt; 24) &amp; 0xff); 
  <BR>&nbsp; } <BR>} <BR><BR>static void Decode (output, input, len) <BR>UINT4 
  *output; <BR>unsigned char *input; <BR>unsigned int len; <BR>{ <BR>&nbsp; 
  unsigned int i, j; <BR><BR>&nbsp; for (i = 0, j = 0; j &lt; len; i++, j += 4) 
  <BR>output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) &lt;&lt; 8) | 
  <BR>&nbsp; (((UINT4)input[j+2]) &lt;&lt; 16) | (((UINT4)input[j+3]) &lt;&lt; 
  24); <BR>} <BR><BR>static void MD5_memcpy (output, input, len) <BR>POINTER 
  output; <BR>POINTER input; <BR>unsigned int len; <BR>{ <BR>&nbsp; unsigned int 
  i; <BR><BR>&nbsp; for (i = 0; i &lt; len; i++) output[i] = input[i]; <BR>} 
  <BR><BR>static void MD5_memset (output, value, len) <BR>POINTER output; 
  <BR>int value; <BR>unsigned int len; <BR>{ <BR>&nbsp; unsigned int i; 
  <BR><BR>&nbsp; for (i = 0; i &lt; len; i++) <BR>((char *)output)[i] = 
  (char)value; <BR>} <BR>————————————————C代码结束—————————— <BR><BR><BR>在VB中实现MD5算法 
  <BR>—————————————————————————————————————————— <BR>Option Explicit <BR><BR>Dim 
  w1 As String, w2 As String, w3 As String, w4 As String <BR><BR>Function 
  MD5F(ByVal tempstr As String, ByVal w As String, ByVal X As String, ByVal y As 
  String, ByVal z As String, ByVal Xin As String, ByVal qdata As String, ByVal 
  rots As Integer) <BR>MD5F = BigMod32Add(RotLeft(BigMod32Add(BigMod32Add(w, 
  tempstr), BigMod32Add(Xin, qdata)), rots), X) <BR>End Function <BR><BR>Sub 
  MD5F1(w As String, ByVal X As String, ByVal y As String, ByVal z As String, 
  ByVal Xin As String, ByVal qdata As String, ByVal rots As Integer) <BR>Dim 
  tempstr As String <BR><BR>&nbsp; &nbsp; tempstr = BigXOR(z, BigAND(X, 
  BigXOR(y, z))) <BR>&nbsp; &nbsp; w = MD5F(tempstr, w, X, y, z, Xin, qdata, 
  rots) <BR>End Sub <BR><BR>Sub MD5F2(w As String, ByVal X As String, ByVal y As 
  String, ByVal z As String, ByVal Xin As String, ByVal qdata As String, ByVal 
  rots As Integer) <BR>Dim tempstr As String <BR><BR>&nbsp; &nbsp; tempstr = 
  BigXOR(y, BigAND(z, BigXOR(X, y))) <BR>&nbsp; &nbsp; w = MD5F(tempstr, w, X, 
  y, z, Xin, qdata, rots) <BR>End Sub <BR><BR>Sub MD5F3(w As String, ByVal X As 
  String, ByVal y As String, ByVal z As String, ByVal Xin As String, ByVal qdata 
  As String, ByVal rots As Integer) <BR>Dim tempstr As String <BR><BR>&nbsp; 
  &nbsp; tempstr = BigXOR(X, BigXOR(y, z)) <BR>&nbsp; &nbsp; w = MD5F(tempstr, 
  w, X, y, z, Xin, qdata, rots) <BR>End Sub <BR><BR>Sub MD5F4(w As String, ByVal 
  X As String, ByVal y As String, ByVal z As String, ByVal Xin As String, ByVal 
  qdata As String, ByVal rots As Integer) <BR>Dim tempstr As String 
  <BR><BR>&nbsp; &nbsp; tempstr = BigXOR(y, BigOR(X, BigNOT(z))) <BR>&nbsp; 
  &nbsp; w = MD5F(tempstr, w, X, y, z, Xin, qdata, rots) <BR>End Sub 
  <BR><BR>Function MD5_Calc(ByVal hashthis As String) As String <BR>ReDim buf(0 
  To 3) As String <BR>ReDim Xin(0 To 15) As String <BR>Dim tempnum As Integer, 
  tempnum2 As Integer, loopit As Integer, loopouter As Integer, loopinner As 
  Integer <BR>Dim a As String, b As String, c As String, d As String 
  <BR><BR>&nbsp; &nbsp; tempnum = 8 * Len(hashthis) <BR>&nbsp; &nbsp; hashthis = 
  hashthis + Chr$(128) 'Add binary 10000000 <BR>&nbsp; &nbsp; tempnum2 = 56 - 
  Len(hashthis) Mod 64 <BR><BR>&nbsp; &nbsp; If tempnum2 &lt; 0 Then <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; tempnum2 = 64 + tempnum2 <BR>&nbsp; &nbsp; End If 
  <BR><BR>&nbsp; &nbsp; hashthis = hashthis + String$(tempnum2, Chr$(0)) 
  <BR><BR>&nbsp; &nbsp; For loopit = 1 To 8 <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  hashthis = hashthis + Chr$(tempnum Mod 256) <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  tempnum = tempnum - tempnum Mod 256 <BR>&nbsp; &nbsp; &nbsp; &nbsp; tempnum = 
  tempnum / 256 <BR>&nbsp; &nbsp; Next loopit <BR><BR>&nbsp; &nbsp; <BR>&nbsp; 
  &nbsp; buf(0) = "67452301" <BR>&nbsp; &nbsp; buf(1) = "efcdab89" <BR>&nbsp; 
  &nbsp; buf(2) = "98badcfe" <BR>&nbsp; &nbsp; buf(3) = "10325476" 
  <BR><BR>&nbsp; &nbsp; <BR>For loopouter = 0 To Len(hashthis) / 64 - 1 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; a = buf(0) <BR>&nbsp; &nbsp; &nbsp; &nbsp; b = 
  buf(1) <BR>&nbsp; &nbsp; &nbsp; &nbsp; c = buf(2) <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; d = buf(3) <BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; ' Get the 512 bits 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; For loopit = 0 To 15 <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; Xin(loopit) = "" <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; For loopinner = 1 To 4 <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; Xin(loopit) = Hex$(Asc(Mid$(hashthis, 64 * loopouter + 4 * 
  loopit + loopinner, 1))) + Xin(loopit) <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; If Len(Xin(loopit)) Mod 2 Then Xin(loopit) = "0" + 
  Xin(loopit) <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next loopinner 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; Next loopit <BR><BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; </BLOCKQUOTE>
<BLOCKQUOTE>' 第一轮循环 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 a, b, c, d, Xin(0), 
  "d76aa478", 7 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 d, a, b, c, Xin(1), 
  "e8c7b756", 12 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 c, d, a, b, Xin(2), 
  "242070db", 17 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 b, c, d, a, Xin(3), 
  "c1bdceee", 22 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 a, b, c, d, Xin(4), 
  "f57c0faf", 7 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 d, a, b, c, Xin(5), 
  "4787c62a", 12 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 c, d, a, b, Xin(6), 
  "a8304613", 17 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 b, c, d, a, Xin(7), 
  "fd469501", 22 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 a, b, c, d, Xin(8), 
  "698098d8", 7 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 d, a, b, c, Xin(9), 
  "8b44f7af", 12 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 c, d, a, b, Xin(10), 
  "ffff5bb1", 17 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 b, c, d, a, Xin(11), 
  "895cd7be", 22 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 a, b, c, d, Xin(12), 
  "6b901122", 7 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 d, a, b, c, Xin(13), 
  "fd987193", 12 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 c, d, a, b, Xin(14), 
  "a679438e", 17 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F1 b, c, d, a, Xin(15), 
  "49b40821", 22 <BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; ' 第二轮循环 <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; MD5F2 a, b, c, d, Xin(1), "f61e2562", 5 <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; MD5F2 d, a, b, c, Xin(6), "c040b340", 9 <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  MD5F2 c, d, a, b, Xin(11), "265e5a51", 14 <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  MD5F2 b, c, d, a, Xin(0), "e9b6c7aa", 20 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 
  a, b, c, d, Xin(5), "d62f105d", 5 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 d, a, 
  b, c, Xin(10), "02441453", 9 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 c, d, a, b, 
  Xin(15), "d8a1e681", 14 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 b, c, d, a, 
  Xin(4), "e7d3fbc8", 20 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 a, b, c, d, 
  Xin(9), "21e1cde6", 5 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 d, a, b, c, 
  Xin(14), "c33707d6", 9 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 c, d, a, b, 
  Xin(3), "f4d50d87", 14 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 b, c, d, a, 
  Xin(8), "455a14ed", 20 <BR>&nbsp; &nbsp; &nbsp; &nbsp; MD5F2 a, b, c, d, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -