ASP 改良版MD5、SHA256多重加密类(二次及多次)(4)


Err.Raise 6
End If
If (lValue And MD5_m_l2Power(31 - iShiftBits)) Then
LShift = ((lValue And MD5_m_lOnBits(31 - (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
'字符串右移位主函数
Private Function RShift(byVal lValue, byVal iShiftBits)
If iShiftBits = 0 Then
RShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And &H80000000 Then
RShift = 1
Else
RShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 or iShiftBits > 31 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
'字符串偏移转换,通过左右移位函数实现
Private Function RotateLeft(byVal lValue, byVal iShiftBits)
RotateLeft = LShift(lValue, iShiftBits) or RShift(lValue, (32 - iShiftBits))
End Function
'追加无符号16进制编码
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主编码函数
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辅编码函数
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进制编码转换
Private Function WordToHex(byVal lValue)
Dim lByte
Dim lCount

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2198.html