📄 sha1managed.cls
字号:
f = d Xor (b And (c Xor d))
K = &H5A827999
Case Is < 40
f = b Xor c Xor d
K = &H6ED9EBA1
Case Is < 60
f = (b And c) Or (d And (b Or c))
K = &H8F1BBCDC
Case Else
f = b Xor c Xor d
K = &HCA62C1D6
End Select
t = Helper.UAdd(Helper.UAdd(Helper.UAdd(Helper.UAdd(LRotate(a, 5), f), e), mW(i)), K)
e = d
d = c
c = LRotate(b, 30)
b = a
a = t
Next i
mState(0) = Helper.UAdd(mState(0), a)
mState(1) = Helper.UAdd(mState(1), b)
mState(2) = Helper.UAdd(mState(2), c)
mState(3) = Helper.UAdd(mState(3), d)
mState(4) = Helper.UAdd(mState(4), e)
End Sub
''
' Runs when compiled. Must disable Integer overflow checks.
'
Private Sub TransformNative(ByRef Bytes() As Byte, ByVal Index As Long)
Dim t As Long
Dim i As Long
For i = 0 To 15
mW(i) = (Bytes(Index) * &H1000000) Or (Bytes(Index + 1) * &H10000) Or (Bytes(Index + 2) * &H100&) Or Bytes(Index + 3)
Index = Index + 4
Next i
For i = 16 To 79
t = mW(i - 3) Xor mW(i - 8) Xor mW(i - 14) Xor mW(i - 16)
mW(i) = (t * &H2) Or ((t And &H80000000) \ &H80000000)
Next i
Dim a As Long
Dim b As Long
Dim c As Long
Dim d As Long
Dim e As Long
a = mState(0)
b = mState(1)
c = mState(2)
d = mState(3)
e = mState(4)
For i = 0 To 19
t = ((a * &H20&) Or (((a And &HF8000000) \ &H8000000) And &H1F&)) + (d Xor (b And (c Xor d))) + e + mW(i) + &H5A827999
e = d
d = c
c = (b * &H40000000) Or (((b And &HFFFFFFFC) \ &H4&) And &H3FFFFFFF)
b = a
a = t
Next i
For i = 20 To 39
t = ((a * &H20&) Or (((a And &HF8000000) \ &H8000000) And &H1F&)) + (b Xor c Xor d) + e + mW(i) + &H6ED9EBA1
e = d
d = c
c = (b * &H40000000) Or (((b And &HFFFFFFFC) \ &H4&) And &H3FFFFFFF)
b = a
a = t
Next i
For i = 40 To 59
t = ((a * &H20&) Or (((a And &HF8000000) \ &H8000000) And &H1F&)) + ((b And c) Or (d And (b Or c))) + e + mW(i) + &H8F1BBCDC
e = d
d = c
c = (b * &H40000000) Or (((b And &HFFFFFFFC) \ &H4&) And &H3FFFFFFF)
b = a
a = t
Next i
For i = 60 To 79
t = ((a * &H20&) Or (((a And &HF8000000) \ &H8000000) And &H1F&)) + (b Xor c Xor d) + e + mW(i) + &HCA62C1D6
e = d
d = c
c = (b * &H40000000) Or (((b And &HFFFFFFFC) \ &H4&) And &H3FFFFFFF)
b = a
a = t
Next i
mState(0) = mState(0) + a
mState(1) = mState(1) + b
mState(2) = mState(2) + c
mState(3) = mState(3) + d
mState(4) = mState(4) + e
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Class Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
Set mBase = Cor.NewHashAlgorithmBase(Me, True, True, 64)
Call Initialize
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' HashAlgorithm Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get HashAlgorithm_CanReuseTransform() As Boolean
HashAlgorithm_CanReuseTransform = CanReuseTransform
End Property
Private Property Get HashAlgorithm_CanTransformMultipleBlocks() As Boolean
HashAlgorithm_CanTransformMultipleBlocks = CanTransformMultipleBlocks
End Property
Private Sub HashAlgorithm_Clear()
Call Clear
End Sub
Private Function HashAlgorithm_ComputeHash(Source As Variant, Optional Index As Variant, Optional Count As Variant) As Byte()
HashAlgorithm_ComputeHash = ComputeHash(Source, Index, Count)
End Function
Private Function HashAlgorithm_Equals(Value As Variant) As Boolean
HashAlgorithm_Equals = Equals(Value)
End Function
Private Function HashAlgorithm_GetHashCode() As Long
HashAlgorithm_GetHashCode = GetHashCode
End Function
Private Property Get HashAlgorithm_Hash() As Byte()
HashAlgorithm_Hash = Hash
End Property
Private Property Get HashAlgorithm_HashSize() As Long
HashAlgorithm_HashSize = HashSize
End Property
Private Sub HashAlgorithm_Initialize()
Call Initialize
End Sub
Private Property Get HashAlgorithm_InputBlockSize() As Long
HashAlgorithm_InputBlockSize = InputBlockSize
End Property
Private Property Get HashAlgorithm_OutputBlockSize() As Long
HashAlgorithm_OutputBlockSize = OutputBlockSize
End Property
Private Function HashAlgorithm_ToString() As String
HashAlgorithm_ToString = ToString
End Function
Private Function HashAlgorithm_TransformBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long, OutputBuffer() As Byte, ByVal OutputOffset As Long) As Long
HashAlgorithm_TransformBlock = TransformBlock(InputBuffer, InputOffset, InputCount, OutputBuffer, OutputOffset)
End Function
Private Function HashAlgorithm_TransformFinalBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long) As Byte()
HashAlgorithm_TransformFinalBlock = TransformFinalBlock(InputBuffer, InputOffset, InputCount)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ICryptoTransform Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get ICryptoTransform_CanReuseTransform() As Boolean
ICryptoTransform_CanReuseTransform = CanReuseTransform
End Property
Private Property Get ICryptoTransform_CanTransformMultipleBlocks() As Boolean
ICryptoTransform_CanTransformMultipleBlocks = CanTransformMultipleBlocks
End Property
Private Property Get ICryptoTransform_InputBlockSize() As Long
ICryptoTransform_InputBlockSize = InputBlockSize
End Property
Private Property Get ICryptoTransform_OutputBlockSize() As Long
ICryptoTransform_OutputBlockSize = OutputBlockSize
End Property
Private Function ICryptoTransform_TransformBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long, OutputBuffer() As Byte, ByVal OutputOffset As Long) As Long
ICryptoTransform_TransformBlock = TransformBlock(InputBuffer, InputOffset, InputCount, OutputBuffer, OutputOffset)
End Function
Private Function ICryptoTransform_TransformFinalBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long) As Byte()
ICryptoTransform_TransformFinalBlock = TransformFinalBlock(InputBuffer, InputOffset, InputCount)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IHashAlgorithmCallback Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub IHashAlgorithm_HashCore(Bytes() As Byte, ByVal Index As Long, ByVal Count As Long)
Call Transform(Bytes, Index)
End Sub
Private Function IHashAlgorithm_HashFinal(ByRef Buffer() As Byte, ByVal ByteCount As Long, ByVal MessageLength As Currency) As Byte()
IHashAlgorithm_HashFinal = HashFinal(Buffer, ByteCount, MessageLength)
End Function
Private Sub IHashAlgorithm_Initialize()
Call Me.Initialize
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IObject Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IObject_Equals(Value As Variant) As Boolean
IObject_Equals = Equals(Value)
End Function
Private Function IObject_GetHashcode() As Long
IObject_GetHashcode = GetHashCode
End Function
Private Function IObject_ToString() As String
IObject_ToString = ToString
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SHA1 Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get SHA1_CanReuseTransform() As Boolean
SHA1_CanReuseTransform = CanReuseTransform
End Property
Private Property Get SHA1_CanTransformMultipleBlocks() As Boolean
SHA1_CanTransformMultipleBlocks = CanTransformMultipleBlocks
End Property
Private Sub SHA1_Clear()
Call Clear
End Sub
Private Function SHA1_ComputeHash(Source As Variant, Optional Index As Variant, Optional Count As Variant) As Byte()
SHA1_ComputeHash = ComputeHash(Source, Index, Count)
End Function
Private Function SHA1_Equals(Value As Variant) As Boolean
SHA1_Equals = Equals(Value)
End Function
Private Function SHA1_GetHashCode() As Long
SHA1_GetHashCode = GetHashCode
End Function
Private Property Get SHA1_Hash() As Byte()
SHA1_Hash = Hash
End Property
Private Property Get SHA1_HashSize() As Long
SHA1_HashSize = HashSize
End Property
Private Sub SHA1_Initialize()
Call Initialize
End Sub
Private Property Get SHA1_InputBlockSize() As Long
SHA1_InputBlockSize = InputBlockSize
End Property
Private Property Get SHA1_OutputBlockSize() As Long
SHA1_OutputBlockSize = OutputBlockSize
End Property
Private Function SHA1_ToString() As String
SHA1_ToString = ToString
End Function
Private Function SHA1_TransformBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long, OutputBuffer() As Byte, ByVal OutputOffset As Long) As Long
SHA1_TransformBlock = TransformBlock(InputBuffer, InputOffset, InputCount, OutputBuffer, OutputOffset)
End Function
Private Function SHA1_TransformFinalBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long) As Byte()
SHA1_TransformFinalBlock = TransformFinalBlock(InputBuffer, InputOffset, InputCount)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -