At present, it can be realized: MD5 algorithm, SHA256 algorithm, first MD5 SHA256, SHA256 after MD5, two MD5, two times SHA256, 8-bit MD5 algorithm after the first 8-bit SHA256, 8-bit SHA256 algorithm after the former 8-bit MD5 algorithm, Password the last character of the ASCW value and the remainder of 8 as the encryption scheme coefficient, 16-bit MD5 encryption, 32-bit MD5 encryption, 8-bit SHA256 encryption, 16-bit SHA256 encryption, 24-bit SHA256 encryption, 32-bit SHA256 encryption, 40-bit SHA256 encryption, 48-bit SHA256 encryption, 56-bit SHA256 encryption, 64-bit SHA256 encryption algorithms, see the source code, more can be customized more encryption and encryption algorithm, and brute force to crack MD5 algorithm say goodbye ~ ~
Cls_encrypt.asp Source:
Copy Code code as follows:
<%
Private Const Bits_to_a_byte = 8
Private Const Bytes_to_a_word = 4
Private Const Bits_to_a_word = 32
Class Cls_encrypt
Private Md5_m_lonbits (30)
Private Md5_m_l2power (30)
Private Sha256_m_lonbits (30)
Private Sha256_m_l2power (30)
Private Sha256_k (63)
Private Sub Class_Initialize
Md5_m_lonbits (0) = CLng (1)
Md5_m_lonbits (1) = CLng (3)
Md5_m_lonbits (2) = CLng (7)
Md5_m_lonbits (3) = CLng (15)
Md5_m_lonbits (4) = CLng (31)
Md5_m_lonbits (5) = CLng (63)
Md5_m_lonbits (6) = CLng (127)
Md5_m_lonbits (7) = CLng (255)
Md5_m_lonbits (8) = CLng (511)
Md5_m_lonbits (9) = CLng (1023)
Md5_m_lonbits (+) = CLng (2047)
Md5_m_lonbits (one) = CLng (4095)
Md5_m_lonbits (a) = CLng (8191)
Md5_m_lonbits (+) = CLng (16383)
Md5_m_lonbits (+) = CLng (32767)
Md5_m_lonbits (+) = CLng (65535)
Md5_m_lonbits (+) = CLng (131071)
Md5_m_lonbits (+) = CLng (262143)
Md5_m_lonbits (km) = CLng (524287)
Md5_m_lonbits (a) = CLng (1048575)
Md5_m_lonbits (+) = CLng (2097151)
Md5_m_lonbits = CLng (4194303)
Md5_m_lonbits (+) = CLng (8388607)
Md5_m_lonbits (+) = CLng (16777215)
Md5_m_lonbits (+) = CLng (33554431)
Md5_m_lonbits (+) = CLng (67108863)
Md5_m_lonbits (num) = CLng (134217727)
Md5_m_lonbits (+) = CLng (268435455)
Md5_m_lonbits = CLng (536870911)
Md5_m_lonbits (+) = CLng (1073741823)
Md5_m_lonbits (+) = CLng (2147483647)
Md5_m_l2power (0) = CLng (1)
Md5_m_l2power (1) = CLng (2)
Md5_m_l2power (2) = CLng (4)
Md5_m_l2power (3) = CLng (8)
Md5_m_l2power (4) = CLng (16)
Md5_m_l2power (5) = CLng (32)
Md5_m_l2power (6) = CLng (64)
Md5_m_l2power (7) = CLng (128)
Md5_m_l2power (8) = CLng (256)
Md5_m_l2power (9) = CLng (512)
Md5_m_l2power (+) = CLng (1024)
Md5_m_l2power (one) = CLng (2048)
Md5_m_l2power (a) = CLng (4096)
Md5_m_l2power (+) = CLng (8192)
Md5_m_l2power (+) = CLng (16384)
Md5_m_l2power (+) = CLng (32768)
Md5_m_l2power (+) = CLng (65536)
Md5_m_l2power (+) = CLng (131072)
Md5_m_l2power (km) = CLng (262144)
Md5_m_l2power (a) = CLng (524288)
Md5_m_l2power (+) = CLng (1048576)
Md5_m_l2power = CLng (2097152)
Md5_m_l2power (+) = CLng (4194304)
Md5_m_l2power (+) = CLng (8388608)
Md5_m_l2power (+) = CLng (16777216)
Md5_m_l2power (+) = CLng (33554432)
Md5_m_l2power (num) = CLng (67108864)
Md5_m_l2power (+) = CLng (134217728)
Md5_m_l2power = CLng (268435456)
Md5_m_l2power (+) = CLng (536870912)
Md5_m_l2power (+) = CLng (1073741824)
Sha256_m_lonbits (0) = CLng (1)
Sha256_m_lonbits (1) = CLng (3)
Sha256_m_lonbits (2) = CLng (7)
Sha256_m_lonbits (3) = CLng (15)
Sha256_m_lonbits (4) = CLng (31)
Sha256_m_lonbits (5) = CLng (63)
Sha256_m_lonbits (6) = CLng (127)
Sha256_m_lonbits (7) = CLng (255)
Sha256_m_lonbits (8) = CLng (511)
Sha256_m_lonbits (9) = CLng (1023)
Sha256_m_lonbits (+) = CLng (2047)
Sha256_m_lonbits (one) = CLng (4095)
Sha256_m_lonbits (a) = CLng (8191)
Sha256_m_lonbits (+) = CLng (16383)
Sha256_m_lonbits (+) = CLng (32767)
Sha256_m_lonbits (+) = CLng (65535)
Sha256_m_lonbits (+) = CLng (131071)
Sha256_m_lonbits (+) = CLng (262143)
Sha256_m_lonbits (km) = CLng (524287)
Sha256_m_lonbits (a) = CLng (1048575)
Sha256_m_lonbits (+) = CLng (2097151)
Sha256_m_lonbits = CLng (4194303)
Sha256_m_lonbits (+) = CLng (8388607)
Sha256_m_lonbits (+) = CLng (16777215)
Sha256_m_lonbits (+) = CLng (33554431)
Sha256_m_lonbits (+) = CLng (67108863)
Sha256_m_lonbits (num) = CLng (134217727)
Sha256_m_lonbits (+) = CLng (268435455)
Sha256_m_lonbits = CLng (536870911)
Sha256_m_lonbits (+) = CLng (1073741823)
Sha256_m_lonbits (+) = CLng (2147483647)
Sha256_m_l2power (0) = CLng (1)
Sha256_m_l2power (1) = CLng (2)
Sha256_m_l2power (2) = CLng (4)
Sha256_m_l2power (3) = CLng (8)
Sha256_m_l2power (4) = CLng (16)
Sha256_m_l2power (5) = CLng (32)
Sha256_m_l2power (6) = CLng (64)
Sha256_m_l2power (7) = CLng (128)
Sha256_m_l2power (8) = CLng (256)
Sha256_m_l2power (9) = CLng (512)
Sha256_m_l2power (+) = CLng (1024)
Sha256_m_l2power (one) = CLng (2048)
Sha256_m_l2power (a) = CLng (4096)
Sha256_m_l2power (+) = CLng (8192)
Sha256_m_l2power (+) = CLng (16384)
Sha256_m_l2power (+) = CLng (32768)
Sha256_m_l2power (+) = CLng (65536)
Sha256_m_l2power (+) = CLng (131072)
Sha256_m_l2power (km) = CLng (262144)
Sha256_m_l2power (a) = CLng (524288)
Sha256_m_l2power (+) = CLng (1048576)
Sha256_m_l2power = CLng (2097152)
Sha256_m_l2power (+) = CLng (4194304)
Sha256_m_l2power (+) = CLng (8388608)
Sha256_m_l2power (+) = CLng (16777216)
Sha256_m_l2power (+) = CLng (33554432)
Sha256_m_l2power (num) = CLng (67108864)
Sha256_m_l2power (+) = CLng (134217728)
Sha256_m_l2power = CLng (268435456)
Sha256_m_l2power (+) = CLng (536870912)
Sha256_m_l2power (+) = CLng (1073741824)
Sha256_k (0) = &h428a2f98
Sha256_k (1) = &h71374491
Sha256_k (2) = &HB5C0FBCF
Sha256_k (3) = &he9b5dba5
Sha256_k (4) = &h3956c25b
Sha256_k (5) = &h59f111f1
Sha256_k (6) = &h923f82a4
Sha256_k (7) = &hab1c5ed5
Sha256_k (8) = &hd807aa98
Sha256_k (9) = &h12835b01
Sha256_k (Ten) = &h243185be
Sha256_k (one) = &H550C7DC3
Sha256_k () = &h72be5d74
Sha256_k (+) = &h80deb1fe
Sha256_k () = &h9bdc06a7
Sha256_k () = &hc19bf174
Sha256_k = &he49b69c1
Sha256_k (km) = &hefbe4786
Sha256_k (km) = &HFC19DC6
Sha256_k = &h240ca1cc
Sha256_k = &h2de92c6f
Sha256_k = &H4A7484AA
Sha256_k = &H5CB0A9DC
Sha256_k () = &h76f988da
Sha256_k (in) = &h983e5152
Sha256_k = &ha831c66d
Sha256_k (num) = &hb00327c8
Sha256_k (+) = &hbf597fc7
Sha256_k = &hc6e00bf3
Sha256_k () = &hd5a79147
Sha256_k () = &h6ca6351
Sha256_k (a) = &h14292967
Sha256_k (+) = &h27b70a85
Sha256_k () = &h2e1b2138
Sha256_k (+) = &H4D2C6DFC
Sha256_k (km) = &H53380D13
Sha256_k (+) = &h650a7354
Sha256_k (Panax notoginseng) = &h766a0abb
Sha256_k () = &h81c2c92e
Sha256_k (km) = &h92722c85
Sha256_k (+) = &HA2BFE8A1
Sha256_k (+) = &ha81a664b
Sha256_k (+) = &hc24b8b70
Sha256_k (+) = &hc76c51a3
Sha256_k (+) = &hd192e819
Sha256_k () = &hd6990624
Sha256_k (+) = &hf40e3585
Sha256_k (+) = &h106aa070
Sha256_k (+) = &h19a4c116
Sha256_k (+) = &H1E376C08
Sha256_k (m) = &h2748774c
Sha256_k (Wuyi) = &H34B0BCB5
Sha256_k () = &H391C0CB3
Sha256_k (+) = &h4ed8aa4a
Sha256_k (SI) = &h5b9cca4f
Sha256_k (+) = &H682E6FF3
Sha256_k () = &h748f82ee
Sha256_k (+) = &h78a5636f
Sha256_k () = &h84c87814
Sha256_k = &h8cc70208
Sha256_k = &h90befffa
Sha256_k () = &ha4506ceb
Sha256_k (+) = &hbef9a3f7
Sha256_k () = &hc67178f2
End Sub
Private Sub Class_Terminate
End Sub
' Character Fu transform array function
Private Function Converttowordarray (ByVal smessage)
Dim Lmessagelength
Dim Lnumberofwords
Dim Lwordarray ()
Dim lbyteposition
Dim Lbytecount
Dim Lwordcount
Const modulus_bits = 512
Const congruent_bits = 448
Lmessagelength = Len (smessage)
Lnumberofwords = ((Lmessagelength + ((modulus_bits-congruent_bits) \ Bits_to_a_byte)) \ (modulus_bits \ BITS_TO_A_BYTE) ) + 1) * (modulus_bits \ Bits_to_a_word)
ReDim Lwordarray (lNumberOfWords-1)
lbyteposition = 0
Lbytecount = 0
Do Until lbytecount >= lmessagelength
Lwordcount = lbytecount \ Bytes_to_a_word
Lbyteposition = (Lbytecount Mod bytes_to_a_word) * Bits_to_a_byte
Lwordarray (Lwordcount) = Lwordarray (Lwordcount) or LShift (ASC (Mid smessage, Lbytecount + 1, 1), lbyteposition)
Lbytecount = Lbytecount + 1
Loop
Lwordcount = lbytecount \ Bytes_to_a_word
Lbyteposition = (Lbytecount Mod bytes_to_a_word) * Bits_to_a_byte
Lwordarray (Lwordcount) = Lwordarray (Lwordcount) or LShift (&h80, lbyteposition)
Lwordarray (lNumberOfWords-2) = LShift (Lmessagelength, 3)
Lwordarray (lNumberOfWords-1) = Rshift (lmessagelength, 29)
Converttowordarray = Lwordarray
End Function
' String left shift main function
Private Function LShift (byVal lValue, ByVal ishiftbits)
If ishiftbits = 0 Then
LShift = LValue
Exit Function
ElseIf ishiftbits = Then
If LValue and 1 Then
LShift = &h80000000
Else
LShift = 0
End If
Exit Function
ElseIf ishiftbits < 0 or ishiftbits > Then
Err.Raise 6
End If
If (LValue and Md5_m_l2power (31-ishiftbits)) Then
LShift = ((LValue and Md5_m_lonbits ()-(ishiftbits + 1)) * Md5_m_l2power (ishiftbits)) or &h80000000
Else
LShift = ((LValue and Md5_m_lonbits (31-ishiftbits)) * Md5_m_l2power (ishiftbits))
End If
End Function
' String right shift main function
Private Function Rshift (byVal lValue, ByVal ishiftbits)
If ishiftbits = 0 Then
Rshift = LValue
Exit Function
ElseIf ishiftbits = Then
If LValue and &h80000000 Then
Rshift = 1
Else
Rshift = 0
End If
Exit Function
ElseIf ishiftbits < 0 or ishiftbits > Then
Err.Raise 6
End If
Rshift = (lValue and &h7ffffffe) \ Md5_m_l2power (ishiftbits)
If (LValue and &h80000000) Then
Rshift = (rshift or (&h40000000 \ md5_m_l2power (iShiftBits-1))
End If
End Function
' String offset conversion, implemented by the left and right shift function
Private Function rotateleft (byVal lValue, ByVal ishiftbits)
Rotateleft = LShift (LValue, ishiftbits) or Rshift (LValue, (32-ishiftbits))
End Function
' Append unsigned 16-encoded
Private Function addunsigned (byVal LX, ByVal LY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim Lresult
LX8 = LX and &h80000000
LY8 = LY and &h80000000
LX4 = LX and &h40000000
LY4 = LY and &h40000000
LRESULT = (LX and &H3FFFFFFF) + (LY and &H3FFFFFFF)
If lX4 and LY4 Then
LRESULT = Lresult xor &h80000000 xor LX8 xor lY8
ElseIf lX4 or LY4 Then
If Lresult and &h40000000 Then
LRESULT = Lresult xor &hc0000000 xor LX8 xor lY8
Else
LRESULT = Lresult xor &h40000000 xor LX8 xor lY8
End If
Else
LRESULT = Lresult XOR lX8 xor lY8
End If
addunsigned = Lresult
End Function
' Md5_ff,md5_gg,md5_hh,md5_ii MD5 main encoding function
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
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
Private Sub md5_hh (A, B, C, D, X, S, AC)
A = addunsigned (A, addunsigned (addunsigned (Md5_h (b, C, D), x), AC)
A = Rotateleft (A, s)
A = Addunsigned (A, B)
End Sub
Private Sub Md5_ii (A, B, C, D, X, S, AC)
A = addunsigned (A, addunsigned (addunsigned (md5_i (b, C, D), x), AC)
A = Rotateleft (A, s)
A = Addunsigned (A, B)
End Sub
' Md5_f,md5_g,md5_h,md5_i MD5 Auxiliary coding function
Private Function md5_f (x, Y, z)
Md5_f = (x and y) or (not x) and Z)
End Function
Private Function md5_g (x, Y, z)
Md5_g = (x and z) or (Y and not z)
End Function
Private Function md5_h (x, Y, z)
Md5_h = (x xor y xor Z)
End Function
Private Function md5_i (x, Y, z)
Md5_i = (y Xor (x or not z))
End Function
' 16 in-process encoding conversion
Private Function Wordtohex (ByVal lValue)
Dim Lbyte
Dim Lcount
For lcount = 0 to 3
Lbyte = Rshift (LValue, Lcount * bits_to_a_byte) and md5_m_lonbits (bits_to_a_byte-1)
Wordtohex = Wordtohex & Right ("0" & Hex (Lbyte), 2)
Next
End Function
' MD5 main function MD5 (string, encoded bit)
Public Function MD5 (ByVal smessage, ByVal stype)
Dim x
Dim K
Dim AA
Dim BB
Dim CC
Dim DD
Dim A
Dim b
Dim C
Dim D
Const S11 = 7
Const S12 = 12
Const S13 = 17
Const S14 = 22
Const S21 = 5
Const S22 = 9
Const S23 = 14
Const S24 = 20
Const S31 = 4
Const S32 = 11
Const S33 = 16
Const S34 = 23
Const S41 = 6
Const S42 = 10
Const S43 = 15
Const S44 = 21
x = Converttowordarray (smessage) ' Encrypt step 1: Array conversion
A = &h67452301
b = &hefcdab89
c = &h98badcfe
D = &h10325476
For k = 0 to UBound (x) Step 16
AA = A
BB = b
CC = C
DD = d
' Encrypt step 2: Encoding conversion
Md5_ff A, B, C, D, X (k + 0), S11, &hd76aa478
Md5_ff D, A, B, C, x (k + 1), S12, &he8c7b756
Md5_ff C, D, a, B, X (k + 2), S13, &h242070db
Md5_ff B, C, D, A, X (K + 3), S14, &hc1bdceee
Md5_ff A, B, C, D, X (K + 4), S11, &HF57C0FAF
Md5_ff D, A, B, C, X (K + 5), S12, &h4787c62a
Md5_ff C, D, a, B, X (k + 6), S13, &ha8304613
Md5_ff B, C, D, A, X (k + 7), S14, &hfd469501
Md5_ff A, B, C, D, X (K + 8), S11, &h698098d8
Md5_ff D, A, B, C, X (K + 9), S12, &H8B44F7AF
Md5_ff C, D, a, B, X (k +), S13, &HFFFF5BB1
Md5_ff B, C, D, A, X (k + one), S14, &h895cd7be
Md5_ff A, B, C, D, X (K +), S11, &h6b901122
Md5_ff D, A, B, C, X (K +), S12, &hfd987193
Md5_ff C, D, a, B, X (k +), S13, &ha679438e
Md5_ff B, C, D, A, X (k +), S14, &h49b40821
Md5_gg A, B, C, D, X (k + 1), S21, &hf61e2562
Md5_gg D, A, B, C, X (K + 6), S22, &hc040b340
Md5_gg C, D, a, B, X (k + one), S23, &h265e5a51
Md5_gg B, C, D, A, X (k + 0), S24, &HE9B6C7AA
Md5_gg A, B, C, D, X (K + 5), S21, &hd62f105d
Md5_gg D, A, B, C, X (K +), S22, &h2441453
Md5_gg C, D, a, B, X (k +), S23, &hd8a1e681
Md5_gg B, C, D, A, X (K + 4), S24, &he7d3fbc8
Md5_gg A, B, C, D, X (K + 9), S21, &h21e1cde6
Md5_gg D, A, B, C, X (K +), S22, &hc33707d6
Md5_gg C, D, a, B, X (k + 3), S23, &hf4d50d87
Md5_gg B, C, D, A, X (K + 8), S24, &h455a14ed
Md5_gg A, B, C, D, X (K +), S21, &ha9e3e905
Md5_gg D, A, B, C, X (K + 2), S22, &hfcefa3f8
Md5_gg C, D, a, B, X (k + 7), S23, &h676f02d9
Md5_gg B, C, D, A, X (k +), S24, &h8d2a4c8a
Md5_hh A, B, C, D, X (K + 5), S31, &hfffa3942
Md5_hh D, A, B, C, X (K + 8), S32, &h8771f681
Md5_hh C, D, a, B, X (k + one), S33, &h6d9d6122
Md5_hh B, C, D, A, X (k +), S34, &hfde5380c
Md5_hh A, B, C, D, X (k + 1), S31, &ha4beea44
Md5_hh D, A, B, C, X (K + 4), S32, &h4bdecfa9
Md5_hh C, D, a, B, X (k + 7), S33, &hf6bb4b60
Md5_hh B, C, D, A, X (k +), S34, &hbebfbc70
Md5_hh A, B, C, D, X (K +), S31, &H289B7EC6
Md5_hh D, A, B, C, x (k + 0), S32, &HEAA127FA
Md5_hh C, D, a, B, X (k + 3), S33, &hd4ef3085
Md5_hh B, C, D, A, X (k + 6), S34, &h4881d05
Md5_hh A, B, C, D, X (K + 9), S31, &hd9d4d039
Md5_hh D, A, B, C, X (K +), S32, &he6db99e5
Md5_hh C, D, a, B, X (k +), S33, &h1fa27cf8
Md5_hh B, C, D, A, X (K + 2), S34, &hc4ac5665
Md5_ii A, B, C, D, X (k + 0), S41, &hf4292244
Md5_ii D, A, B, C, X (k + 7), S42, &h432aff97
Md5_ii C, D, a, B, X (k +), S43, &hab9423a7
Md5_ii B, C, D, A, X (K + 5), S44, &hfc93a039
Md5_ii A, B, C, D, X (K +), S41, &H655B59C3
Md5_ii D, A, B, C, X (K + 3), S42, &h8f0ccc92
Md5_ii C, D, a, B, X (k +), S43, &hffeff47d
Md5_ii B, C, D, A, X (k + 1), S44, &H85845DD1
Md5_ii A, B, C, D, X (K + 8), S41, &h6fa87e4f
Md5_ii D, A, B, C, X (K +), S42, &HFE2CE6E0
Md5_ii C, D, a, B, X (k + 6), S43, &ha3014314
Md5_ii B, C, D, A, X (k +), S44, &H4E0811A1
Md5_ii A, B, C, D, X (K + 4), S41, &hf7537e82
Md5_ii D, A, B, C, X (K + one), S42, &hbd3af235
Md5_ii C, D, a, B, X (k + 2), S43, &H2AD7D2BB
Md5_ii B, C, D, A, X (k + 9), S44, &heb86d391
' Encrypt step 3: Append unsigned conversion
A = addunsigned (A, AA)
b = addunsigned (b, BB)
c = addunsigned (c, CC)
D = addunsigned (d, DD)
Next
If stype = Then
' Encrypt step 4: Split-Merge each 8-bit 16-binary conversion
MD5 = LCase (Wordtohex (a) & Wordtohex (b) & Wordtohex (c) & Wordtohex (d))
Else
MD5 = LCase (Wordtohex (b) & Wordtohex (c))
End If
End Function
Private Function Sha256_lshift (byVal lValue, ByVal ishiftbits)
If ishiftbits = 0 Then
Sha256_lshift = LValue
Exit Function
ElseIf ishiftbits = Then
If LValue and 1 Then
Sha256_lshift = &h80000000
Else
Sha256_lshift = 0
End If
Exit Function
ElseIf ishiftbits < 0 or ishiftbits > Then
Err.Raise 6
End If
If (LValue and Sha256_m_l2power (31-ishiftbits)) Then
Sha256_lshift = ((LValue and Sha256_m_lonbits ()-(ishiftbits + 1)) * Sha256_m_l2power (ishiftbits)) or &h80000000
Else
Sha256_lshift = ((LValue and Sha256_m_lonbits (31-ishiftbits)) * Sha256_m_l2power (ishiftbits))
End If
End Function
Private Function Sha256_rshift (byVal lValue, ByVal ishiftbits)
If ishiftbits = 0 Then
Sha256_rshift = LValue
Exit Function
ElseIf ishiftbits = Then
If LValue and &h80000000 Then
Sha256_rshift = 1
Else
Sha256_rshift = 0
End If
Exit Function
ElseIf ishiftbits < 0 or ishiftbits > Then
Err.Raise 6
End If
Sha256_rshift = (lValue and &h7ffffffe) \ Sha256_m_l2power (ishiftbits)
If (LValue and &h80000000) Then
Sha256_rshift = (sha256_rshift or (&h40000000 \ sha256_m_l2power (iShiftBits-1))
End If
End Function
Private Function sha256_addunsigned (byVal LX, ByVal LY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim Lresult
LX8 = LX and &h80000000
LY8 = LY and &h80000000
LX4 = LX and &h40000000
LY4 = LY and &h40000000
LRESULT = (LX and &H3FFFFFFF) + (LY and &H3FFFFFFF)
If lX4 and LY4 Then
LRESULT = Lresult xor &h80000000 xor LX8 xor lY8
ElseIf lX4 or LY4 Then
If Lresult and &h40000000 Then
LRESULT = Lresult xor &hc0000000 xor LX8 xor lY8
Else
LRESULT = Lresult xor &h40000000 xor LX8 xor lY8
End If
Else
LRESULT = Lresult XOR lX8 xor lY8
End If
sha256_addunsigned = Lresult
End Function
Private Function sha256_ch (x, Y, z)
Sha256_ch = ((x and Y) Xor (not x) and Z)
End Function
Private Function Sha256_maj (x, Y, z)
Sha256_maj = ((x and Y) xor (x and Z) xor (Y and Z))
End Function
Private Function sha256_s (x, N)
sha256_s = (Sha256_rshift (x, (N and Sha256_m_lonbits (4))) or Sha256_lshift (x, (N and Sha256_m_lonbits (4)))
End Function
Private Function sha256_r (x, N)
Sha256_r = Sha256_rshift (x, CLng (N and Sha256_m_lonbits (4))
End Function
Private Function sha256_sigma0 (x)
Sha256_sigma0 = (sha256_s (x, 2) XOR sha256_s (x,) XOR sha256_s (x, 22))
End Function
Private Function sha256_sigma1 (x)
SHA256_SIGMA1 = (sha256_s (x, 6) XOR sha256_s (x, one) XOR sha256_s (x, 25)
End Function
Private Function sha256_gamma0 (x)
Sha256_gamma0 = (sha256_s (x, 7) XOR sha256_s (x,) XOR Sha256_r (x, 3))
End Function
Private Function sha256_gamma1 (x)
SHA256_GAMMA1 = (sha256_s (x,) XOR sha256_s (x,) XOR Sha256_r (x, 10)
End Function
Private Function Sha256_converttowordarray (ByVal smessage)
Dim Lmessagelength
Dim Lnumberofwords
Dim Lwordarray ()
Dim lbyteposition
Dim Lbytecount
Dim Lwordcount
Dim Lbyte
Const modulus_bits = 512
Const congruent_bits = 448
Lmessagelength = Len (smessage)
Lnumberofwords = ((Lmessagelength + ((modulus_bits-congruent_bits) \ Bits_to_a_byte)) \ (modulus_bits \ BITS_TO_A_BYTE) ) + 1) * (modulus_bits \ Bits_to_a_word)
ReDim Lwordarray (lNumberOfWords-1)
lbyteposition = 0
Lbytecount = 0
Do Until lbytecount >= lmessagelength
Lwordcount = lbytecount \ Bytes_to_a_word
Lbyteposition = (3-(Lbytecount Mod bytes_to_a_word)) * Bits_to_a_byte
Lbyte = AscB (Mid (smessage, Lbytecount + 1, 1))
Lwordarray (Lwordcount) = Lwordarray (Lwordcount) or Sha256_lshift (Lbyte, lbyteposition)
Lbytecount = Lbytecount + 1
Loop
Lwordcount = lbytecount \ Bytes_to_a_word
Lbyteposition = (3-(Lbytecount Mod bytes_to_a_word)) * Bits_to_a_byte
Lwordarray (Lwordcount) = Lwordarray (Lwordcount) or Sha256_lshift (&h80, lbyteposition)
Lwordarray (lNumberOfWords-1) = Sha256_lshift (Lmessagelength, 3)
Lwordarray (lNumberOfWords-2) = Sha256_rshift (lmessagelength, 29)
Sha256_converttowordarray = Lwordarray
End Function
' ==========================================================================================
' SHA256 encryption algorithm
' ========================================================================================
' Invoke method:
' SHA256 (smessage, P_len)
' P_len control generates string length, 1 is 8 bits, 2 is 16 bits, the maximum value is 8, that is, after encryption length is 64 bit
' Control 8-bit \ 16-bit \ 24-bit \ 32-bit \ 40-bit \ 48-bit \ 56-bit \ 64-bit encryption
Public Function SHA256 (ByVal smessage, ByVal P_len)
Dim HASH (7)
Dim M
Dim W (63)
Dim A
Dim b
Dim C
Dim D
Dim E
Dim F
Dim g
Dim h
Dim I
Dim J
Dim T1
Dim T2
HASH (0) = &h6a09e667
HASH (1) = &hbb67ae85
HASH (2) = &h3c6ef372
HASH (3) = &ha54ff53a
HASH (4) = &h510e527f
HASH (5) = &h9b05688c
HASH (6) = &h1f83d9ab
HASH (7) = &h5be0cd19
M = Sha256_converttowordarray (smessage)
For i = 0 to UBound (M) Step 16
A = HASH (0)
b = HASH (1)
c = HASH (2)
D = HASH (3)
E = HASH (4)
f = HASH (5)
g = HASH (6)
H = HASH (7)
For j = 0 to 63
If J < Then
W (j) = M (j + i)
Else
W (j) = Sha256_addunsigned (sha256_addunsigned (sha256_addunsigned (SHA256_GAMMA1 (w (j-2)), W (j-7)), Sha256_gamma0 (W (J- )), W (j-16))
End If
T1 = sha256_addunsigned (sha256_addunsigned sha256_addunsigned (sha256_addunsigned (H, SHA256_SIGMA1 (e)), SHA256_CH (E , F, g)), Sha256_k (j)), W (j))
T2 = sha256_addunsigned (Sha256_sigma0 (a), Sha256_maj (A, B, c))
h = g
g = f
F = E
E = sha256_addunsigned (d, T1)
D = C
c = b
b = A
A = sha256_addunsigned (T1, T2)
Next
Hash (0) = sha256_addunsigned (A, hash (0))
Hash (1) = sha256_addunsigned (b, hash (1))
Hash (2) = sha256_addunsigned (c, hash (2))
Hash (3) = sha256_addunsigned (d, hash (3))
Hash (4) = Sha256_addunsigned (E, HASH (4))
Hash (5) = sha256_addunsigned (f, hash (5))
Hash (6) = sha256_addunsigned (g, hash (6))
Hash (7) = sha256_addunsigned (h, hash (7))
Next
SHA256 = ""
If P_len >= 8 Then P_len = 8
If p_len <= 0 Then p_len = 2
For i = 0 to P_len-1
SHA256 = SHA256 & Right ("00000000" & Hex (HASH (i)), 8)
Next
SHA256 = LCase (SHA256)
End Function
Public Function Encryptmode (ByVal p_string, ByVal p_type)
Dim E1s, E2s
E1s = 16 ' first or MD5 algorithm encryption length 16-bit MD5 encryption length
E2s = 2 ' second or SHA256 algorithm encryption length 2*8=16 bit SHA256 encryption length, maximum encryption length is 8*8=64 bit
If not IsNumeric (p_type) Then
P_type = 1
ElseIf p_type > 7 or p_type < 0 Then ' judge the number of scenarios, based on the maximum value of P_type
P_type = 1
End If
If not IsNumeric (e1s) Then
E1s = 16
ElseIf e1s <> e1s <> Then
E1s = 16
End If
If not IsNumeric (E2S) Then
E2s = 2
ElseIf e2s > 8 or e2s < 0 Then
E2s = 2
End If
' ==========================================
' The best way to adjust the encryption scheme is to use it for the first time, now up to 8 options
' Encrypted string length is 16 bits and can be adjusted in use
' ==========================================
Select Case P_type
Case 0 ' MD5 algorithm
Encryptmode = MD5 (p_string, E1s)
Case 1 ' SHA256 algorithm
Encryptmode = SHA256 (p_string, E2s)
Case 2 ' first MD5 after SHA256
Encryptmode = SHA256 (MD5 (p_string, E1s), E2s)
Case 3 ' first SHA256 after MD5
Encryptmode = MD5 (SHA256 (p_string, E2s), E1s)
Case 4 ' two times MD5
Encryptmode = MD5 (MD5 (p_string, E1s), E2s)
Case 5 ' two times SHA256
Encryptmode = SHA256 (SHA256 (p_string, E1s), E2s)
Case 6 ' Top 8-bit MD5 algorithm after 8-bit SHA256 algorithm
Encryptmode = Left (MD5 (p_string, E1s), 8) & Right (SHA256 (p_string, E2s), 8)
Case 7 ' Top 8-bit SHA256 algorithm after 8-bit MD5 algorithm
Encryptmode = Left (SHA256 (p_string, E2s), 8) & Right (MD5 (p_string, E1s), 8)
End Select
End Function
' ============================================
' Total Station cipher class universal cryptographic function
' ============================================
Public Function passwordent (ByVal p_string)
If p_string = "" or IsNull (p_string) Then p_string = 1
' Take the ASCW value of the last character of the password and the remainder of 8 as the encryption scheme factor
Passwordent = Encryptmode (p_string, AscW (LCase (Right (p_string, 1)) Mod 8)
End Function
End Class
%>
Demonstrate:
Copy Code code as follows:
<!--#include file= "cls_encrypt.asp"-->
<%
Dim o
Set o = new Cls_encrypt
Response.Write "MD5 algorithm:" & O.encryptmode ("admin", 0) & "<br/>"
Response.Write "SHA256 algorithm:" & O.encryptmode ("admin", 1) & "<br/>"
Response.Write "MD5 First SHA256:" & O.encryptmode ("admin", 2) & "<br/>"
Response.Write "SHA256 First MD5:" & O.encryptmode ("admin", 3) & "<br/>"
Response.Write "two times MD5:" & O.encryptmode ("admin", 4) & "<br/>"
Response.Write "two times SHA256:" & O.encryptmode ("admin", 5) & "<br/>"
Response.Write "First 8-bit MD5 algorithm after 8-bit SHA256 algorithm:" & O.encryptmode ("admin", 6) & "<br/>"
Response.Write "First 8-bit SHA256 algorithm after 8-bit MD5 algorithm:" & O.encryptmode ("admin", 7) & "<br/><hr/>"
Response.Write The ASCW value of the last character of the password and the remainder of 8 as the encryption Scheme factor: "& O.passwordent (" admin ") &" <br/><hr/> "
Response.Write "16-bit MD5 encryption:" & O.md5 ("admin" & "<br/>")
Response.Write "32-bit MD5 encryption:" & O.md5 ("admin") & "<br/><hr/>"
Response.Write "8-bit SHA256 encryption:" & o.sha256 ("admin", 1) & "<br/>"
Response.Write "16-bit SHA256 encryption:" & o.sha256 ("admin", 2) & "<br/>"
Response.Write "24-bit SHA256 encryption:" & o.sha256 ("admin", 3) & "<br/>"
Response.Write "32-bit SHA256 encryption:" & o.sha256 ("admin", 4) & "<br/>"
Response.Write "40-bit SHA256 encryption:" & o.sha256 ("admin", 5) & "<br/>"
Response.Write "48-bit SHA256 encryption:" & o.sha256 ("admin", 6) & "<br/>"
Response.Write "56-bit SHA256 encryption:" & o.sha256 ("admin", 7) & "<br/>"
Response.Write "64-bit SHA256 encryption:" & o.sha256 ("admin", 8) & "<br/>"
Set o = Nothing
%>