29/06/2006, 07:00
|
| | | Fecha de Ingreso: septiembre-2004
Mensajes: 2.749
Antigüedad: 20 años, 3 meses Puntos: 18 | |
MD5 (y 2)
Código:
' Private methods and properties
Private m_lMask()
Private m_lPow()
Private Function F(lX, lY, lZ)
F = (lX And lY) Or ((Not lX) And lZ)
End Function
Private Function G(lX, lY, lZ)
G = (lX And lZ) Or (lY And (Not lZ))
End Function
Private Function H(lX, lY, lZ)
H = lX Xor lY Xor lZ
End Function
Private Function I(lX, lY, lZ)
I = lY Xor (lX Or (Not lZ))
End Function
Private Sub FF(lA, lB, lC, lD, lX, lS, lAC)
lA = Add32(lA,Add32(Add32(F(lB,lC,lD),lX),lAC))
lA = RotateLeft32(lA,lS)
lA = Add32(lA,lB)
End Sub
Private Sub GG(lA, lB, lC, lD, lX, lS, lAC)
lA = Add32(lA,Add32(Add32(G(lB,lC,lD),lX),lAC))
lA = RotateLeft32(lA,lS)
lA = Add32(lA,lB)
End Sub
Private Sub HH(lA, lB, lC, lD, lX, lS, lAC)
lA = Add32(lA,Add32(Add32(H(lB,lC,lD),lX),lAC))
lA = RotateLeft32(lA,lS)
lA = Add32(lA,lB)
End Sub
Private Sub II(lA, lB, lC, lD, lX, lS, lAC)
lA = Add32(lA,Add32(Add32(I(lB,lC,lD),lX),lAC))
lA = RotateLeft32(lA,lS)
lA = Add32(lA,lB)
End Sub
Private Function ConvertToWordArray(sText)
Dim lTextLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount
lTextLength = Len(sText)
lNumberOfWords = (((lTextLength + 8) \ 64) + 1) * 16
ReDim lWordArray(lNumberOfWords - 1)
lBytePosition = 0
lByteCount = 0
Do Until lByteCount >= lTextLength
lWordCount = lByteCount \ 4
lBytePosition = (lByteCount Mod 4) * 8
lWordArray(lWordCount) = lWordArray(lWordCount) Or ShiftLeft(Asc(Mid(sText,lByteCount + 1,1)),lBytePosition)
lByteCount = lByteCount + 1
Loop
lWordCount = lByteCount \ 4
lBytePosition = (lByteCount Mod 4) * 8
lWordArray(lWordCount) = lWordArray(lWordCount) Or ShiftLeft(&H80,lBytePosition)
lWordArray(lNumberOfWords - 2) = ShiftLeft(lTextLength,3)
lWordArray(lNumberOfWords - 1) = ShiftRight(lTextLength,29)
ConvertToWordArray = lWordArray
End Function
Private Function WordToHex(lValue)
Dim lTemp
For lTemp = 0 To 3
WordToHex = WordToHex & Right("00" & Hex(ShiftRight(lValue,lTemp * 8) And m_lMask(7)),2)
Next
End Function
' Unsigned value arithmetic functions for rotating, shifting and adding
Private Function ShiftLeft(lValue,iBits)
' Guilty until proven innocent
ShiftLeft = 0
If iBits = 0 then
ShiftLeft = lValue ' No shifting to do
ElseIf iBits = 31 Then ' Quickly shift left if there is a value, being aware of the sign
If lValue And 1 Then
ShiftLeft = &H80000000
End If
Else ' Shift left x bits, being careful with the sign
If (lValue And m_lPow(31 - iBits)) Then
ShiftLeft = ((lValue And m_lMask(31 - (iBits + 1))) * m_lPow(iBits)) Or &H80000000
Else
ShiftLeft = ((lValue And m_lMask(31 - iBits)) * m_lPow(iBits))
End If
End If
End Function
Private Function ShiftRight(lValue,iBits)
' Guilty until proven innocent
ShiftRight = 0
If iBits = 0 then
ShiftRight = lValue ' No shifting to do
ElseIf iBits = 31 Then ' Quickly shift to the right if there is a value in the sign
If lValue And &H80000000 Then
ShiftRight = 1
End If
Else
ShiftRight = (lValue And &H7FFFFFFE) \ m_lPow(iBits)
If (lValue And &H80000000) Then
ShiftRight = (ShiftRight Or (&H40000000 \ m_lPow(iBits - 1)))
End If
End If
End Function
Private Function RotateLeft32(lValue,iBits)
RotateLeft32 = ShiftLeft(lValue,iBits) Or ShiftRight(lValue,(32 - iBits))
End Function
Private Function Add32(lA,lB)
Dim lA4
Dim lB4
Dim lA8
Dim lB8
Dim lA32
Dim lB32
Dim lA31
Dim lB31
Dim lTemp
lA32 = lA And &H80000000
lB32 = lB And &H80000000
lA31 = lA And &H40000000
lB31 = lB And &H40000000
lTemp = (lA And &H3FFFFFFF) + (lB And &H3FFFFFFF)
If lA31 And lB31 Then
lTemp = lTemp Xor &H80000000 Xor lA32 Xor lB32
ElseIf lA31 Or lB31 Then
If lTemp And &H40000000 Then
lTemp = lTemp Xor &HC0000000 Xor lA32 Xor lB32
Else
lTemp = lTemp Xor &H40000000 Xor lA32 Xor lB32
End If
Else
lTemp = lTemp Xor lA32 Xor lB32
End If
Add32 = lTemp
End Function
' Class initialization
Private Sub Class_Initialize()
Text = ""
Redim m_lMask(30)
Redim m_lPow(30)
' Make arrays of these values to save some time during the calculation
m_lMask(0) = CLng(&H00000001&)
m_lMask(1) = CLng(&H00000003&)
m_lMask(2) = CLng(&H00000007&)
m_lMask(3) = CLng(&H0000000F&)
m_lMask(4) = CLng(&H0000001F&)
m_lMask(5) = CLng(&H0000003F&)
m_lMask(6) = CLng(&H0000007F&)
m_lMask(7) = CLng(&H000000FF&)
m_lMask(8) = CLng(&H000001FF&)
m_lMask(9) = CLng(&H000003FF&)
m_lMask(10) = CLng(&H000007FF&)
m_lMask(11) = CLng(&H00000FFF&)
m_lMask(12) = CLng(&H00001FFF&)
m_lMask(13) = CLng(&H00003FFF&)
m_lMask(14) = CLng(&H00007FFF&)
m_lMask(15) = CLng(&H0000FFFF&)
m_lMask(16) = CLng(&H0001FFFF&)
m_lMask(17) = CLng(&H0003FFFF&)
m_lMask(18) = CLng(&H0007FFFF&)
m_lMask(19) = CLng(&H000FFFFF&)
m_lMask(20) = CLng(&H001FFFFF&)
m_lMask(21) = CLng(&H003FFFFF&)
m_lMask(22) = CLng(&H007FFFFF&)
m_lMask(23) = CLng(&H00FFFFFF&)
m_lMask(24) = CLng(&H01FFFFFF&)
m_lMask(25) = CLng(&H03FFFFFF&)
m_lMask(26) = CLng(&H07FFFFFF&)
m_lMask(27) = CLng(&H0FFFFFFF&)
m_lMask(28) = CLng(&H1FFFFFFF&)
m_lMask(29) = CLng(&H3FFFFFFF&)
m_lMask(30) = CLng(&H7FFFFFFF&)
' Power operations always take time to calculate
m_lPow(0) = CLng(&H00000001&)
m_lPow(1) = CLng(&H00000002&)
m_lPow(2) = CLng(&H00000004&)
m_lPow(3) = CLng(&H00000008&)
m_lPow(4) = CLng(&H00000010&)
m_lPow(5) = CLng(&H00000020&)
m_lPow(6) = CLng(&H00000040&)
m_lPow(7) = CLng(&H00000080&)
m_lPow(8) = CLng(&H00000100&)
m_lPow(9) = CLng(&H00000200&)
m_lPow(10) = CLng(&H00000400&)
m_lPow(11) = CLng(&H00000800&)
m_lPow(12) = CLng(&H00001000&)
m_lPow(13) = CLng(&H00002000&)
m_lPow(14) = CLng(&H00004000&)
m_lPow(15) = CLng(&H00008000&)
m_lPow(16) = CLng(&H00010000&)
m_lPow(17) = CLng(&H00020000&)
m_lPow(18) = CLng(&H00040000&)
m_lPow(19) = CLng(&H00080000&)
m_lPow(20) = CLng(&H00100000&)
m_lPow(21) = CLng(&H00200000&)
m_lPow(22) = CLng(&H00400000&)
m_lPow(23) = CLng(&H00800000&)
m_lPow(24) = CLng(&H01000000&)
m_lPow(25) = CLng(&H02000000&)
m_lPow(26) = CLng(&H04000000&)
m_lPow(27) = CLng(&H08000000&)
m_lPow(28) = CLng(&H10000000&)
m_lPow(29) = CLng(&H20000000&)
m_lPow(30) = CLng(&H40000000&)
End Sub
End Class
Y para llamarlo
Código:
cadena="cadena a pasar"
Dim objMD5
Set objMD5 = New MD5
objMD5.Text = cadena
response.write objMD5.HEXMD5
|