Implementation of 64-bit MD5 encryption algorithm by ASP

Source: Internet
Author: User
Tags exit md5 md5 encryption

  <%

Private Const BITS_TO_A_BYTE = 8 Private Const BYTES_TO_A_WORD = 4 Private Const Bits_to_a_word = &nbsp; Private M_lo Nbits Private M_l2power (a) &nbsp; private Function LShift (LValue, ishiftbits) If ishiftbits = 0 Then lshift = lValue Exit Function ElseIf ishiftbits = to Then If lValue and 1 Then lshift = &amp;h80000000 Else lshift = 0 End If Exit functio N ElseIf ishiftbits &lt; 0 Or ishiftbits &gt; Then err.raise 6 End If &nbsp; if (LValue and M_l2power (31-ishiftbits)) Then LShift = (LValue and M_lonbits (to-(ishiftbits + 1))) * M_l2power (Ishiftbits)), Or &amp;h80000000 Else lshift = ((l Value and M_lonbits (31-ishiftbits)) * M_l2power (ishiftbits)) End If function &nbsp; Private Function rshift (LValue, ishiftbits) If ishiftbits = 0 Then rshift = lValue Exit Function ElseIf ishiftbits = to Then if LValue and &amp;h80000000 Then rshift = 1 Else rshift = 0 End If Exit Function ElseIf ishiftbits &lt; 0 Or ishiftbits &gt; Then err.raise 6 End I F &nbsp; Rshift = (LvaluE and &amp;h7ffffffe) M_l2power (ishiftbits) &nbsp; If (LValue and &amp;h80000000) Then Rshift = (rshift Or (&amp;h40000000 M_l2power (iShiftBits-1)) End-If End Function &nbsp; Private Function rotateleft (LValue, ishiftbits) Rotateleft = Lshif T (LValue, Ishiftbits) Or Rshift (LValue, (32-ishiftbits)) End Function &nbsp; Private Function addunsigned (LX, LY) Dim LX 4 Dim lY4 Dim LX8 Dim lY8 Dim lresult &nbsp; LX8 = lx and &amp;h80000000 lY8 = LY and &amp;h80000000 lX4 = LX and &amp;h40 000000 lY4 = LY and &amp;h40000000 &nbsp; lresult = (LX and &AMP;H3FFFFFFF) + (LY and &amp;h3fffffff) &nbsp; If lX4 and Ly 4 Then lresult = Lresult xor &amp;h80000000 xor lX8 xor lY8 ElseIf lX4 Or lY4 Then If lresult and &amp;h40000000 Then Ult = Lresult xor &amp;hc0000000 xor lX8 xor lY8 Else lresult = Lresult xor &amp;h40000000 xor lX8 xor lY8 end If Else lre Sult = Lresult xor lX8 xor lY8 end If &nbsp; addunsigned = Lresult End Function &nbsp; Private Function md5_f (x, Y, z) MD5 _f = (x and y) Or (notx) and Z) End Function &nbsp; Private Function md5_g (x, Y, z) md5_g = (x and z) Or (y and (don't)) End Function &nbsp; Pri vate function Md5_h (x, Y, z) md5_h = (x xor y xor z) end Function &nbsp; Private Function md5_i (x, Y, z) md5_i = (Y xor (x Or (not z)) end Function &nbsp; Private Sub md5_ff (A, B, C, D, X, S, ac) a = addunsigned (A, addunsigned (addunsigned md5_ F (b, C, D), x), ac)) A = Rotateleft (A, s) A = Addunsigned (A, b) end Sub &nbsp; Private Sub Md5_gg (A, B, C, D, X, S, AC) a = Addunsigned (A, addunsigned (addunsigned (Md5_g (b, C, D), x), ac)) A = Rotateleft (A, s) A = Addunsigned (A, b) end Sub &nbsp ; Private Sub md5_hh (A, B, C, D, X, S, ac) a = addunsigned (A, addunsigned (addunsigned (Md5_h (b, C, D), x), ac) A = Rotatelef T (A, s) A = Addunsigned (A, b) End Sub &nbsp; Private Sub Md5_ii (A, B, C, D, X, S, ac) a = addunsigned (A, addunsigned (Addun Signed (Md5_i (b, C, D), x), ac)) A = Rotateleft (A, s) A = Addunsigned (A, b) end Sub &nbsp; Private Function Converttowordar Ray (smessage) Dim LMEsSagelength Dim lnumberofwords Dim Lwordarray () Dim lbyteposition Dim Lbytecount Dim Lwordcount &nbsp; Const Modulus_bits = Congruent_bits = 448 &nbsp; Lmessagelength = Len (smessage) &nbsp; Lnumberofwords = ((Lmessagelength + () (modulu s_bits-congruent_bits) bits_to_a_byte)) (Modulus_bits bits_to_a_byte)) + 1) * (modulus_bits Bits_to_a_word) ReDim LWordA Rray (lNumberOfWords-1) &nbsp; lbyteposition = 0 Lbytecount = 0 do Until lbytecount &gt;= lmessagelength = Lwordcount Tecount Bytes_to_a_word lbyteposition = (lbytecount Mod bytes_to_a_word) * bits_to_a_byte lwordarray (lWordCount) = LWordA Rray (Lwordcount) Or LShift (ASC (Mid (smessage, Lbytecount + 1, 1), lbyteposition) Lbytecount = lbytecount + 1 Loop &nbsp; L WordCount = Lbytecount Bytes_to_a_word lbyteposition = (lbytecount Mod bytes_to_a_word) * bits_to_a_byte &nbsp; LWordArray (lwordcount) = Lwordarray (Lwordcount) Or lshift (&amp;h80, lbyteposition) &nbsp; Lwordarray (lNumberOfWords-2) = LShift (l Messagelength, 3) LwordarrAy (lNumberOfWords-1) = Rshift (Lmessagelength,) &nbsp; Converttowordarray = Lwordarray end Function &nbsp; Private Fun Ction Wordtohex (LValue) Dim lbyte Dim Lcount &nbsp; for lcount = 0 to 3 Lbyte = Rshift (LValue, Lcount * bits_to_a_byte) D m_lonbits (bits_to_a_byte-1) Wordtohex = Wordtohex &amp; Right ("0" &amp; Hex (Lbyte), 2) Next end Function &nbsp; Public Function MD5 (smessage) m_lonbits (0) = CLng (1) m_lonbits (1) = CLng (3) m_lonbits (2) = CLng (7) m_lonbits (3) = CLng (a) M_lon Bits (4) = CLng (To) m_lonbits (5) = CLng () m_lonbits (6) = CLng (127) m_lonbits (7) = CLng (255) m_lonbits (8) = CLng (511) M_lo Nbits (9) = CLng (1023) m_lonbits (+) = CLng (2047) m_lonbits (one) = CLng (4095) m_lonbits (a) = CLng (8191) m_lonbits (a) = CLn G (16383) m_lonbits = CLng (32767) m_lonbits (in) = CLng (65535) m_lonbits () = CLng (131071) m_lonbits (km) = CLng (262143) M_lonbits (m) = CLng (524287) m_lonbits (a) = CLng (1048575) m_lonbits (m) = CLng (2097151) m_lonbits (a) = CLng (4194303) m_ Lonbits (+) = CLng (83886m_lonbits) = CLng (16777215) m_lonbits = CLng (33554431) m_lonbits (a) = CLng (67108863) m_lonbits (num) = CLng (1342 17727) m_lonbits = CLng (268435455) m_lonbits (a) = CLng (536870911) m_lonbits (MB) = CLng (1073741823) m_lonbits (a) = CL Ng (2147483647) &nbsp; m_l2power (0) = CLng (1) m_l2power (1) = CLng (2) m_l2power (2) = CLng (4) m_l2power (3) = CLng (8) M_l2powe R (4) = CLng M_l2power (5) = CLng (M_l2power) (6) = CLng ($) m_l2power (7) = CLng (128) m_l2power (8) = CLng (256) M_l2powe R (9) = CLng (M_l2power) = CLng (1024) m_l2power (one) = CLng (2048) m_l2power (a) = CLng (4096) m_l2power (a) = CLng (819 2) M_l2power = CLng (16384) m_l2power (a) = CLng (32768) m_l2power (a) = CLng (65536) m_l2power (m) = CLng (131072) M_l2po Wer (m) = CLng (262144) m_l2power (a) = CLng (524288) m_l2power (m) = CLng (1048576) m_l2power (a) = CLng (2097152) M_l2power ( = CLng (4194304) m_l2power () = CLng (8388608) m_l2power () = CLng (16777216) m_l2power (a) = CLng (33554432) M_l2power ( ) = CLng (67108864) m_l2Power (m) = CLng (134217728) m_l2power = CLng (268435456) m_l2power (MB) = CLng (536870912) m_l2power (a) = CLng (1073741 824) &nbsp; &nbsp; Dim x Dim K Dim AA Dim BB Dim CC Dim DD Dim A Dim B Dim c Dim D &nbsp; Const S11 = 7 Const S12 = Con St S13 = S14 = Const S21 = 5 Const S22 = 9 Const S23 = Const S24 = Const S31 = 4 Const S32 = one const S3 3 = Const S34 = S41 = 6 Const S42 = + Const S43 = Const S44 = &nbsp; x = Converttowordarray (smessage) & nbsp A = &amp;h67452301 b = &amp;hefcdab89 c = &amp;h98badcfe d = &amp;h10325476 &nbsp; for k = 0 to UBound (x) Step AA = a b b = b CC = c DD = d &nbsp; MD5_FF A, B, C, D, X (k + 0), S11, &amp;hd76aa478 md5_ff D, a, B, C, x (k + 1), S12, &amp;he8c7b7 Md5_ff C, D, a, B, X (k + 2), S13, &amp;h242070db md5_ff B, C, D, A, X (K + 3), S14, &amp;hc1bdceee md5_ff A, B, C, D, X ( K + 4), S11, &AMP;HF57C0FAF md5_ff D, a, B, C, X (K + 5), S12, &amp;h4787c62a md5_ff C, D, a, B, X (k + 6), S13, &amp;ha8304 613 md5_ff B, C, D, A, X (k + 7), S14, &amp;hfd469501 md5_ff A, B, C, D, X (K + 8), S11, &amp;h698098d8 md5_ff D, a, B, C, X (K + 9), S12, &amp; H8B44F7AF md5_ff C, D, a, B, X (k +), S13, &amp;hffff5bb1 md5_ff B, C, D, A, X (k + one), S14, &amp;h895cd7be md5_ff A, B, C, D, X (K +), S11, &amp;h6b901122 md5_ff D, a, B, C, X (K +), S12, &amp;hfd987193 md5_ff C, D, a, B, X (k +), S13, &amp;ha679438e md5_ff B, C, D, A, X (k +), S14, &amp;h49b40821 &nbsp; Md5_gg A, B, C, D, X (k + 1), S21, &amp;hf61e2562 Md5_gg D, A, B, C, X (K + 6), S22, &amp;hc040b340 Md5_gg C, D, a, B, X (k + one), S23, &amp;h265e5a51 Md5_gg B, C, D, A, X (k + 0), S24, &amp;he9b6c7aa Md5_gg A, B, C, D, X (K + 5), S21, &amp;hd62f105d Md5_gg D, a, B, C, X (K +), S22, &amp;h244145 3 Md5_gg C, D, a, B, X (k +), S23, &amp;hd8a1e681 Md5_gg B, C, D, A, X (K + 4), S24, &amp;he7d3fbc8 Md5_gg A, B, C, D, X ( K + 9), S21, &amp;h21e1cde6 Md5_gg D, a, B, C, X (K +), S22, &amp;hc33707d6 Md5_gg C, D, a, B, X (k + 3), S23, &AMP;HF4D5 0d87 Md5_gg B, C, D, a,X (k + 8), S24, &amp;h455a14ed Md5_gg A, B, C, D, X (K +), S21, &amp;ha9e3e905 Md5_gg D, a, B, C, X (K + 2), S22, &AMP;HFC Efa3f8 Md5_gg C, D, a, B, X (k + 7), S23, &amp;h676f02d9 Md5_gg B, C, D, A, X (k +), S24, &amp;h8d2a4c8a &nbsp; md5_hh A, b, C, D, X (K + 5), S31, &amp;hfffa3942 md5_hh D, a, B, C, X (K + 8), S32, &amp;h8771f681 md5_hh C, D, a, B, X (k + one), S33 , &amp;h6d9d6122 md5_hh B, C, D, A, X (k +), S34, &amp;hfde5380c md5_hh A, B, C, D, X (k + 1), S31, &amp;ha4beea44 md5_hh D, A, B, C, X (K + 4), S32, &amp;h4bdecfa9 md5_hh C, D, a, B, X (k + 7), S33, &amp;hf6bb4b60 md5_hh B, C, D, A, X (k + 10), S34, &amp;hbebfbc70 md5_hh A, B, C, D, X (K +), S31, &amp;h289b7ec6 md5_hh D, a, B, C, x (k + 0), S32, &AMP;HEAA127FA MD5 _hh C, D, a, B, X (k + 3), S33, &amp;hd4ef3085 md5_hh B, C, D, A, X (k + 6), S34, &amp;h4881d05 md5_hh A, B, C, D, X (K + 9), S31, &amp;hd9d4d039 md5_hh D, a, B, C, X (K +), S32, &amp;he6db99e5 md5_hh C, D, a, B, X (k +), S33, &amp;h1fa27cf8 m D5_hh B, C, D, A, X (k +2), S34, &amp;hc4ac5665 &nbsp; Md5_ii A, B, C, D, X (k + 0), S41, &amp;hf4292244 Md5_ii D, a, B, C, X (k + 7), S42, &amp;h43 2AFF97 Md5_ii C, D, a, B, X (k +), S43, &amp;hab9423a7 Md5_ii B, C, D, A, X (K + 5), S44, &amp;hfc93a039 Md5_ii A, B, C, D, X (K +), S41, &amp;h655b59c3 Md5_ii D, a, B, C, X (K + 3), S42, &amp;h8f0ccc92 Md5_ii C, D, a, B, X (k +), S43, ; hffeff47d Md5_ii B, C, D, A, X (k + 1), S44, &amp;h85845dd1 Md5_ii A, B, C, D, X (K + 8), S41, &amp;h6fa87e4f Md5_ii D, a, b , C, X (K +), S42, &amp;hfe2ce6e0 Md5_ii C, D, a, B, X (k + 6), S43, &amp;ha3014314 Md5_ii B, C, D, A, X (k +), S44, &A mp H4E0811A1 Md5_ii A, B, C, D, X (K + 4), S41, &amp;hf7537e82 Md5_ii D, a, B, C, X (K + one), S42, &amp;hbd3af235 Md5_ii C, D, A, B, X (k + 2), S43, &AMP;H2AD7D2BB Md5_ii B, C, D, A, X (k + 9), S44, &amp;heb86d391 &nbsp; a = addunsigned (A, AA) b = Add Unsigned (b, BB) C = addunsigned (c, CC) d = addunsigned (d, DD) Next &nbsp; If Mdfive=16 then Md5=lcase (Wordtohex (b) &amp; W Ordtohex (c)) Else MD5=ucase (Wordtohex (a) &amp; Wordtohex (b) &amp; Wordtohex (c) &amp; Wordtohex (d)) End If &nbsp; End Function%&gt; &nbsp;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.