PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/md5.inc

http://fsdkp.googlecode.com/
PHP | 444 lines | 396 code | 48 blank | 0 comment | 4 complexity | 83e7183405f26f2893bf6474b9b035d3 MD5 | raw file
  1. <%
  2. '??MD5????(?????COPY??).??VBSCRIPT/ASP???
  3. '????? ????Legume ????? ?????2004.08.17 ????? tg*ddvip.com
  4. ' Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm,
  5. ' as set out in the memo RFC1321.
  6. '
  7. ' See the VB6 project that accompanies this sample for full code comments on how
  8. ' it works.
  9. '
  10. ' ASP VBScript code for generating an MD5 'digest' or 'signature' of a string. The
  11. ' MD5 algorithm is one of the industry standard methods for generating digital
  12. ' signatures. It is generically known as a digest, digital signature, one-way
  13. ' encryption, hash or checksum algorithm. A common use for MD5 is for password
  14. ' encryption as it is one-way in nature, that does not mean that your passwords
  15. ' are not free from a dictionary attack.
  16. '
  17. ' This is 'free' software with the following restrictions:
  18. '
  19. ' You may not redistribute this code as a 'sample' or 'demo'. However, you are free
  20. ' to use the source code in your own code, but you may not claim that you created
  21. ' the sample code. It is expressly forbidden to sell or profit from this source code
  22. ' other than by the knowledge gained or the enhanced value added by your own code.
  23. '
  24. ' Use of this software is also done so at your own risk. The code is supplied as
  25. ' is without warranty or guarantee of any kind.
  26. '
  27. ' Should you wish to commission some derivative work based on this code provided
  28. ' here, or any consultancy work, please do not hesitate to contact us.
  29. '
  30. ' Web Site: http://www.frez.co.uk
  31. ' E-mail: sales@frez.co.uk
  32. Private Const BITS_TO_A_BYTE = 8
  33. Private Const BYTES_TO_A_WORD = 4
  34. Private Const BITS_TO_A_WORD = 32
  35. Private m_lOnBits(30)
  36. Private m_l2Power(30)
  37. m_lOnBits(0) = CLng(1)
  38. m_lOnBits(1) = CLng(3)
  39. m_lOnBits(2) = CLng(7)
  40. m_lOnBits(3) = CLng(15)
  41. m_lOnBits(4) = CLng(31)
  42. m_lOnBits(5) = CLng(63)
  43. m_lOnBits(6) = CLng(127)
  44. m_lOnBits(7) = CLng(255)
  45. m_lOnBits(8) = CLng(511)
  46. m_lOnBits(9) = CLng(1023)
  47. m_lOnBits(10) = CLng(2047)
  48. m_lOnBits(11) = CLng(4095)
  49. m_lOnBits(12) = CLng(8191)
  50. m_lOnBits(13) = CLng(16383)
  51. m_lOnBits(14) = CLng(32767)
  52. m_lOnBits(15) = CLng(65535)
  53. m_lOnBits(16) = CLng(131071)
  54. m_lOnBits(17) = CLng(262143)
  55. m_lOnBits(18) = CLng(524287)
  56. m_lOnBits(19) = CLng(1048575)
  57. m_lOnBits(20) = CLng(2097151)
  58. m_lOnBits(21) = CLng(4194303)
  59. m_lOnBits(22) = CLng(8388607)
  60. m_lOnBits(23) = CLng(16777215)
  61. m_lOnBits(24) = CLng(33554431)
  62. m_lOnBits(25) = CLng(67108863)
  63. m_lOnBits(26) = CLng(134217727)
  64. m_lOnBits(27) = CLng(268435455)
  65. m_lOnBits(28) = CLng(536870911)
  66. m_lOnBits(29) = CLng(1073741823)
  67. m_lOnBits(30) = CLng(2147483647)
  68. m_l2Power(0) = CLng(1)
  69. m_l2Power(1) = CLng(2)
  70. m_l2Power(2) = CLng(4)
  71. m_l2Power(3) = CLng(8)
  72. m_l2Power(4) = CLng(16)
  73. m_l2Power(5) = CLng(32)
  74. m_l2Power(6) = CLng(64)
  75. m_l2Power(7) = CLng(128)
  76. m_l2Power(8) = CLng(256)
  77. m_l2Power(9) = CLng(512)
  78. m_l2Power(10) = CLng(1024)
  79. m_l2Power(11) = CLng(2048)
  80. m_l2Power(12) = CLng(4096)
  81. m_l2Power(13) = CLng(8192)
  82. m_l2Power(14) = CLng(16384)
  83. m_l2Power(15) = CLng(32768)
  84. m_l2Power(16) = CLng(65536)
  85. m_l2Power(17) = CLng(131072)
  86. m_l2Power(18) = CLng(262144)
  87. m_l2Power(19) = CLng(524288)
  88. m_l2Power(20) = CLng(1048576)
  89. m_l2Power(21) = CLng(2097152)
  90. m_l2Power(22) = CLng(4194304)
  91. m_l2Power(23) = CLng(8388608)
  92. m_l2Power(24) = CLng(16777216)
  93. m_l2Power(25) = CLng(33554432)
  94. m_l2Power(26) = CLng(67108864)
  95. m_l2Power(27) = CLng(134217728)
  96. m_l2Power(28) = CLng(268435456)
  97. m_l2Power(29) = CLng(536870912)
  98. m_l2Power(30) = CLng(1073741824)
  99. Private Function LShift(lValue, iShiftBits)
  100. If iShiftBits = 0 Then
  101. LShift = lValue
  102. Exit Function
  103. ElseIf iShiftBits = 31 Then
  104. If lValue And 1 Then
  105. LShift = &H80000000
  106. Else
  107. LShift = 0
  108. End If
  109. Exit Function
  110. ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  111. Err.Raise 6
  112. End If
  113. If (lValue And m_l2Power(31 - iShiftBits)) Then
  114. LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
  115. Else
  116. LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
  117. End If
  118. End Function
  119. Private Function RShift(lValue, iShiftBits)
  120. If iShiftBits = 0 Then
  121. RShift = lValue
  122. Exit Function
  123. ElseIf iShiftBits = 31 Then
  124. If lValue And &H80000000 Then
  125. RShift = 1
  126. Else
  127. RShift = 0
  128. End If
  129. Exit Function
  130. ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  131. Err.Raise 6
  132. End If
  133. RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
  134. If (lValue And &H80000000) Then
  135. RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
  136. End If
  137. End Function
  138. Private Function RotateLeft(lValue, iShiftBits)
  139. RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
  140. End Function
  141. Private Function AddUnsigned(lX, lY)
  142. Dim lX4
  143. Dim lY4
  144. Dim lX8
  145. Dim lY8
  146. Dim lResult
  147. lX8 = lX And &H80000000
  148. lY8 = lY And &H80000000
  149. lX4 = lX And &H40000000
  150. lY4 = lY And &H40000000
  151. lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
  152. If lX4 And lY4 Then
  153. lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
  154. ElseIf lX4 Or lY4 Then
  155. If lResult And &H40000000 Then
  156. lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
  157. Else
  158. lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
  159. End If
  160. Else
  161. lResult = lResult Xor lX8 Xor lY8
  162. End If
  163. AddUnsigned = lResult
  164. End Function
  165. Private Function F(x, y, z)
  166. F = (x And y) Or ((Not x) And z)
  167. End Function
  168. Private Function G(x, y, z)
  169. G = (x And z) Or (y And (Not z))
  170. End Function
  171. Private Function H(x, y, z)
  172. H = (x Xor y Xor z)
  173. End Function
  174. Private Function I2(x, y, z)
  175. I2 = (y Xor (x Or (Not z)))
  176. End Function
  177. Private Sub FF(a, b, c, d, x, s, ac)
  178. a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac))
  179. a = RotateLeft(a, s)
  180. a = AddUnsigned(a, b)
  181. End Sub
  182. Private Sub GG(a, b, c, d, x, s, ac)
  183. a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac))
  184. a = RotateLeft(a, s)
  185. a = AddUnsigned(a, b)
  186. End Sub
  187. Private Sub HH(a, b, c, d, x, s, ac)
  188. a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac))
  189. a = RotateLeft(a, s)
  190. a = AddUnsigned(a, b)
  191. End Sub
  192. Private Sub II(a, b, c, d, x, s, ac)
  193. a = AddUnsigned(a, AddUnsigned(AddUnsigned(I2(b, c, d), x), ac))
  194. a = RotateLeft(a, s)
  195. a = AddUnsigned(a, b)
  196. End Sub
  197. Private Function ConvertToWordArray(sMessage)
  198. Dim lMessageLength
  199. Dim lNumberOfWords
  200. Dim lWordArray()
  201. Dim lBytePosition
  202. Dim lByteCount
  203. Dim lWordCount
  204. Const MODULUS_BITS = 512
  205. Const CONGRUENT_BITS = 448
  206. lMessageLength = Len(sMessage)
  207. lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
  208. ReDim lWordArray(lNumberOfWords - 1)
  209. lBytePosition = 0
  210. lByteCount = 0
  211. Do Until lByteCount >= lMessageLength
  212. lWordCount = lByteCount \ BYTES_TO_A_WORD
  213. lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
  214. lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
  215. lByteCount = lByteCount + 1
  216. Loop
  217. lWordCount = lByteCount \ BYTES_TO_A_WORD
  218. lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
  219. lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)
  220. lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
  221. lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
  222. ConvertToWordArray = lWordArray
  223. End Function
  224. Private Function WordToHex(lValue)
  225. Dim lByte
  226. Dim lCount
  227. For lCount = 0 To 3
  228. lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
  229. WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
  230. Next
  231. End Function
  232. Public Function MD5(sMessage)
  233. Dim x
  234. Dim k
  235. Dim AA
  236. Dim BB
  237. Dim CC
  238. Dim DD
  239. Dim a
  240. Dim b
  241. Dim c
  242. Dim d
  243. Const S11 = 7
  244. Const S12 = 12
  245. Const S13 = 17
  246. Const S14 = 22
  247. Const S21 = 5
  248. Const S22 = 9
  249. Const S23 = 14
  250. Const S24 = 20
  251. Const S31 = 4
  252. Const S32 = 11
  253. Const S33 = 16
  254. Const S34 = 23
  255. Const S41 = 6
  256. Const S42 = 10
  257. Const S43 = 15
  258. Const S44 = 21
  259. x = ConvertToWordArray(sMessage)
  260. a = &H67452301
  261. b = &HEFCDAB89
  262. c = &H98BADCFE
  263. d = &H10325476
  264. For k = 0 To UBound(x) Step 16
  265. AA = a
  266. BB = b
  267. CC = c
  268. DD = d
  269. FF a, b, c, d, x(k + 0), S11, &HD76AA478
  270. FF d, a, b, c, x(k + 1), S12, &HE8C7B756
  271. FF c, d, a, b, x(k + 2), S13, &H242070DB
  272. FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
  273. FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
  274. FF d, a, b, c, x(k + 5), S12, &H4787C62A
  275. FF c, d, a, b, x(k + 6), S13, &HA8304613
  276. FF b, c, d, a, x(k + 7), S14, &HFD469501
  277. FF a, b, c, d, x(k + 8), S11, &H698098D8
  278. FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
  279. FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
  280. FF b, c, d, a, x(k + 11), S14, &H895CD7BE
  281. FF a, b, c, d, x(k + 12), S11, &H6B901122
  282. FF d, a, b, c, x(k + 13), S12, &HFD987193
  283. FF c, d, a, b, x(k + 14), S13, &HA679438E
  284. FF b, c, d, a, x(k + 15), S14, &H49B40821
  285. GG a, b, c, d, x(k + 1), S21, &HF61E2562
  286. GG d, a, b, c, x(k + 6), S22, &HC040B340
  287. GG c, d, a, b, x(k + 11), S23, &H265E5A51
  288. GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA
  289. GG a, b, c, d, x(k + 5), S21, &HD62F105D
  290. GG d, a, b, c, x(k + 10), S22, &H2441453
  291. GG c, d, a, b, x(k + 15), S23, &HD8A1E681
  292. GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8
  293. GG a, b, c, d, x(k + 9), S21, &H21E1CDE6
  294. GG d, a, b, c, x(k + 14), S22, &HC33707D6
  295. GG c, d, a, b, x(k + 3), S23, &HF4D50D87
  296. GG b, c, d, a, x(k + 8), S24, &H455A14ED
  297. GG a, b, c, d, x(k + 13), S21, &HA9E3E905
  298. GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8
  299. GG c, d, a, b, x(k + 7), S23, &H676F02D9
  300. GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A
  301. HH a, b, c, d, x(k + 5), S31, &HFFFA3942
  302. HH d, a, b, c, x(k + 8), S32, &H8771F681
  303. HH c, d, a, b, x(k + 11), S33, &H6D9D6122
  304. HH b, c, d, a, x(k + 14), S34, &HFDE5380C
  305. HH a, b, c, d, x(k + 1), S31, &HA4BEEA44
  306. HH d, a, b, c, x(k + 4), S32, &H4BDECFA9
  307. HH c, d, a, b, x(k + 7), S33, &HF6BB4B60
  308. HH b, c, d, a, x(k + 10), S34, &HBEBFBC70
  309. HH a, b, c, d, x(k + 13), S31, &H289B7EC6
  310. HH d, a, b, c, x(k + 0), S32, &HEAA127FA
  311. HH c, d, a, b, x(k + 3), S33, &HD4EF3085
  312. HH b, c, d, a, x(k + 6), S34, &H4881D05
  313. HH a, b, c, d, x(k + 9), S31, &HD9D4D039
  314. HH d, a, b, c, x(k + 12), S32, &HE6DB99E5
  315. HH c, d, a, b, x(k + 15), S33, &H1FA27CF8
  316. HH b, c, d, a, x(k + 2), S34, &HC4AC5665
  317. II a, b, c, d, x(k + 0), S41, &HF4292244
  318. II d, a, b, c, x(k + 7), S42, &H432AFF97
  319. II c, d, a, b, x(k + 14), S43, &HAB9423A7
  320. II b, c, d, a, x(k + 5), S44, &HFC93A039
  321. II a, b, c, d, x(k + 12), S41, &H655B59C3
  322. II d, a, b, c, x(k + 3), S42, &H8F0CCC92
  323. II c, d, a, b, x(k + 10), S43, &HFFEFF47D
  324. II b, c, d, a, x(k + 1), S44, &H85845DD1
  325. II a, b, c, d, x(k + 8), S41, &H6FA87E4F
  326. II d, a, b, c, x(k + 15), S42, &HFE2CE6E0
  327. II c, d, a, b, x(k + 6), S43, &HA3014314
  328. II b, c, d, a, x(k + 13), S44, &H4E0811A1
  329. II a, b, c, d, x(k + 4), S41, &HF7537E82
  330. II d, a, b, c, x(k + 11), S42, &HBD3AF235
  331. II c, d, a, b, x(k + 2), S43, &H2AD7D2BB
  332. II b, c, d, a, x(k + 9), S44, &HEB86D391
  333. a = AddUnsigned(a, AA)
  334. b = AddUnsigned(b, BB)
  335. c = AddUnsigned(c, CC)
  336. d = AddUnsigned(d, DD)
  337. Next
  338. MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
  339. End Function
  340. Function GetSysInfo(InfoType)'??????
  341. Dim WshShell,WshSysEnv
  342. Set WshShell = Server.CreateObject("WScript.Shell")
  343. Set WshSysEnv = WshShell.Environment("SYSTEM")
  344. If InfoType="CPUNums" Then
  345. GetSysInfo=Cstr(WshSysEnv("NUMBER_OF_PROCESSORS"))
  346. If IsNull(GetSysInfo) Then
  347. GetSysInfo = Request.ServerVariables("NUMBER_OF_PROCESSORS")
  348. ElseIf GetSysInfo="" Then
  349. GetSysInfo = Request.ServerVariables("NUMBER_OF_PROCESSORS")
  350. End If
  351. ElseIf InfoType="CPUInfo" Then
  352. GetSysInfo = Cstr(WshSysEnv("PROCESSOR_IDENTIFIER"))
  353. ElseIf InfoType="OSInfo" Then
  354. GetSysInfo = Cstr(WshSysEnv("OS"))
  355. If Request.ServerVariables("OS")="" Then GetSysInfo=GetSysInfo & "(?Windows Server 2003)"
  356. End If
  357. End Function
  358. Function CheckObjInstalled(strClassString)'????????
  359. On Error Resume Next
  360. Dim TmpObj
  361. Set TmpObj = Server.CreateObject(strClassString)
  362. IF Err = 0 OR Err = -2147221477 Then
  363. CheckObjInstalled= "??"
  364. ElseIF Err = 1 OR Err = -2147221005 Then
  365. CheckObjInstalled="???"
  366. End IF
  367. Err.Clear
  368. Set TmpObj = Nothing
  369. End Function
  370. Function GetTotalSize(GetLocal,GetType)'??????????
  371. Dim FSO
  372. Set FSO=Server.CreateObject("Scripting.FileSystemObject")
  373. IF Err<>0 Then
  374. Err.Clear
  375. GetTotalSize="?????FSO??"
  376. Else
  377. Dim SiteFolder
  378. IF GetType="Folder" Then
  379. Set SiteFolder=FSO.GetFolder(GetLocal)
  380. Else
  381. Set SiteFolder=FSO.GetFile(GetLocal)
  382. End IF
  383. GetTotalSize=SiteFolder.Size
  384. IF GetTotalSize>1024*1024 Then
  385. GetTotalSize=GetTotalSize/1024/1024
  386. IF inStr(GetTotalSize,".") Then GetTotalSize = Left(GetTotalSize,inStr(GetTotalSize,".")+2)
  387. GetTotalSize=GetTotalSize&" MB"
  388. Else
  389. GetTotalSize=Fix(GetTotalSize/1024)&" KB"
  390. End IF
  391. Set SiteFolder=Nothing
  392. End IF
  393. Set FSO=Nothing
  394. End Function
  395. %>