⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sha512managed.cls

📁 这是一个在vb下实现的各种加密程序,可以实现一般的文本加密和文件加密,但是很多算法都是已经被人破解过的.
💻 CLS
📖 第 1 页 / 共 2 页
字号:

Private Function BigSIG0Lo(ByVal xh As Long, ByVal xl As Long) As Long
    BigSIG0Lo = RRotateLo(xh, xl, 28) Xor RRotateLo(xh, xl, 34) Xor RRotateLo(xh, xl, 39)
End Function

Private Function BigSIG1Hi(ByVal xh As Long, ByVal xl As Long) As Long
    BigSIG1Hi = RRotateHi(xh, xl, 14) Xor RRotateHi(xh, xl, 18) Xor RRotateHi(xh, xl, 41)
End Function

Private Function BigSIG1Lo(ByVal xh As Long, ByVal xl As Long) As Long
    BigSIG1Lo = RRotateLo(xh, xl, 14) Xor RRotateLo(xh, xl, 18) Xor RRotateLo(xh, xl, 41)
End Function

Private Function LilSig0Hi(ByVal xh As Long, ByVal xl As Long) As Long
    LilSig0Hi = RRotateHi(xh, xl, 1) Xor RRotateHi(xh, xl, 8) Xor RShiftHi(xh, xl, 7)
End Function

Private Function LilSig0Lo(ByVal xh As Long, ByVal xl As Long) As Long
    LilSig0Lo = RRotateLo(xh, xl, 1) Xor RRotateLo(xh, xl, 8) Xor RShiftLo(xh, xl, 7)
End Function

Private Function LilSig1Hi(ByVal xh As Long, ByVal xl As Long) As Long
    LilSig1Hi = RRotateHi(xh, xl, 19) Xor RRotateHi(xh, xl, 61) Xor RShiftHi(xh, xl, 6)
End Function

Private Function LilSig1Lo(ByVal xh As Long, ByVal xl As Long) As Long
    LilSig1Lo = RRotateLo(xh, xl, 19) Xor RRotateLo(xh, xl, 61) Xor RShiftLo(xh, xl, 6)
End Function



''
' Runs when compiled. Must disable Integer overflow checks.
'
Private Sub TransformNative(ByRef Bytes() As Byte, ByVal Index As Long)
    Dim i As Long
    For i = 0 To 15
        mWh(i) = (Bytes(Index) * &H1000000) Or (Bytes(Index + 1) * &H10000) Or (Bytes(Index + 2) * &H100&) Or Bytes(Index + 3)
        Index = Index + 4
        mWl(i) = (Bytes(Index) * &H1000000) Or (Bytes(Index + 1) * &H10000) Or (Bytes(Index + 2) * &H100&) Or Bytes(Index + 3)
        Index = Index + 4
    Next i
    
    Dim Lo As Long
    Dim th As Long: Dim tl As Long
    Dim sh As Long: Dim sl As Long
    
    For i = 16 To 79
        '
        ' sum = LittleSigma1(W(i-2)) + W(i-7)
        '
        tl = mWl(i - 2)
        th = mWh(i - 2)
        sh = (((((th And &HFFF80000) \ &H80000) And &H1FFF&) Or (tl * &H2000&)) Xor _
             ((th * &H8&) Or (((tl And &HE0000000) \ &H20000000) And &H7&)) Xor _
             (((th And &HFFFFFFC0) \ &H40&) And &H3FFFFFF)) + _
             mWh(i - 7)
        sl = (((((tl And &HFFF80000) \ &H80000) And &H1FFF&) Or (th * &H2000&)) Xor _
             ((tl * &H8&) Or (((th And &HE0000000) \ &H20000000) And &H7&)) Xor _
             ((th * &H4000000) Or (((tl And &HFFFFFFC0) \ &H40&) And &H3FFFFFF))) + _
             mWl(i - 7)
        If (sl - &H80000000) < (mWl(i - 7) - &H80000000) Then sh = sh + 1

        '
        ' sum = sum + LittleSigma0(W(i-15))
        '
        tl = mWl(i - 15)
        th = mWh(i - 15)
        sh = sh + (((tl * &H80000000) Or (((th And &HFFFFFFFE) \ &H2) And &H7FFFFFFF)) Xor _
                  ((tl * &H1000000) Or (((th And &HFFFFFF00) \ &H100&) And &HFFFFFF)) Xor _
                  (((th And &HFFFFFF80) \ &H80&) And &H1FFFFFF))
        Lo = ((th * &H80000000) Or (((tl And &HFFFFFFFE) \ &H2) And &H7FFFFFFF)) Xor _
             ((th * &H1000000) Or (((tl And &HFFFFFF00) \ &H100&) And &HFFFFFF)) Xor _
             ((th * &H2000000) Or (((tl And &HFFFFFF80) \ &H80&) And &H1FFFFFF))
        sl = sl + Lo
        If (sl - &H80000000) < (Lo - &H80000000) Then sh = sh + 1
        
        '
        ' sum = sum + W(i-16)
        '
        sh = sh + mWh(i - 16)
        sl = sl + mWl(i - 16)
        If (sl - &H80000000) < (mWl(i - 16) - &H80000000) Then sh = sh + 1
        
        '
        ' W(i) = sum
        '
        mWh(i) = sh
        mWl(i) = sl
    Next i
    
    Dim Ah As Long, Al As Long
    Dim Bh As Long, Bl As Long
    Dim Ch As Long, Cl As Long
    Dim Dh As Long, Dl As Long
    Dim Eh As Long, El As Long
    Dim Fh As Long, Fl As Long
    Dim Gh As Long, Gl As Long
    Dim Hh As Long, Hl As Long
    
    Ah = mStateH(0): Al = mStateL(0)
    Bh = mStateH(1): Bl = mStateL(1)
    Ch = mStateH(2): Cl = mStateL(2)
    Dh = mStateH(3): Dl = mStateL(3)
    Eh = mStateH(4): El = mStateL(4)
    Fh = mStateH(5): Fl = mStateL(5)
    Gh = mStateH(6): Gl = mStateL(6)
    Hh = mStateH(7): Hl = mStateL(7)
    
    
    Dim T1h As Long: Dim T1l As Long
    Dim T2h As Long: Dim T2l As Long
    
    For i = 0 To 79
        
        'BigSigma0  : ROTR(x,28) XOR ROTR(x,34) XOR ROTR(x,39)
        'BigSigma1  : ROTR(x,14) XOR ROTR(x,18) XOR ROTR(x,41)
        'Ch         : (x AND y) XOR ((NOT x) AND z)
        'Maj        : (x AND y) XOR (x AND z) XOR (y AND z)
        '
        'T1 = H + BigSigma1(E) + Ch(E,F,G) + K(i) + W(i)
        'T2 = BigSigma0(A) + Maj(A,B,C)
        '
        
        '
        ' T1 = H + BigSigma1(E)
        '
        T1h = Hh + _
              (((((Eh And &HFFFFC000) \ &H4000) And &H3FFFF) Or (El * &H40000)) Xor _
              ((((Eh And &HFFFC0000) \ &H40000) And &H3FFF) Or (El * &H4000)) Xor _
              ((Eh * &H800000) Or (((El And &HFFFFFE00) \ &H200&) And &H7FFFFF)))
        Lo = (((((El And &HFFFFC000) \ &H4000) And &H3FFFF) Or (Eh * &H40000)) Xor _
             ((((El And &HFFFC0000) \ &H40000) And &H3FFF) Or (Eh * &H4000)) Xor _
             ((El * &H800000) Or (((Eh And &HFFFFFE00) \ &H200&) And &H7FFFFF)))
        T1l = Hl + Lo
        If (T1l - &H80000000) < (Lo - &H80000000) Then T1h = T1h + 1
        
        '
        ' T1 = T1 + Ch(E,F,G)
        '
        T1h = T1h + ((Eh And Fh) Xor ((Not Eh) And Gh))
        Lo = ((El And Fl) Xor ((Not El) And Gl))
        T1l = T1l + Lo
        If (T1l - &H80000000) < (Lo - &H80000000) Then T1h = T1h + 1
        
        '
        ' T1 = T1 + K(i)
        '
        T1h = T1h + mKh(i)
        T1l = T1l + mKl(i)
        If (T1l - &H80000000) < (mKl(i) - &H80000000) Then T1h = T1h + 1
        
        '
        ' T1 = T1 + W(i)
        '
        T1h = T1h + mWh(i)
        T1l = T1l + mWl(i)
        If (T1l - &H80000000) < (mWl(i) - &H80000000) Then T1h = T1h + 1
        
        '
        ' T2 = BigSigma0(A)
        '
        T2h = ((((Ah And &HF0000000) \ &H10000000) And &HF&) Or (Al * &H10&)) Xor _
              ((Ah * &H40000000) Or (((Al And &HFFFFFFFC) \ &H4&) And &H3FFFFFFF)) Xor _
              ((Ah * &H2000000) Or (((Al And &HFFFFFF80) \ &H80&) And &H1FFFFFF))
        T2l = ((((Al And &HF0000000) \ &H10000000) And &HF&) Or (Ah * &H10&)) Xor _
              ((Al * &H40000000) Or (((Ah And &HFFFFFFFC) \ &H4&) And &H3FFFFFFF)) Xor _
              ((Al * &H2000000) Or (((Ah And &HFFFFFF80) \ &H80&) And &H1FFFFFF))
        
        '
        ' T2 = T2 + Maj(A,B,C)
        '
        T2h = T2h + ((Ah And Bh) Xor (Ah And Ch) Xor (Bh And Ch))
        Lo = (Al And Bl) Xor (Al And Cl) Xor (Bl And Cl)
        T2l = T2l + Lo
        If (T2l - &H80000000) < (Lo - &H80000000) Then T2h = T2h + 1
        
        Hh = Gh: Hl = Gl
        Gh = Fh: Gl = Fl
        Fh = Eh: Fl = El
        Eh = Dh + T1h
        El = Dl + T1l
        If (El - &H80000000) < (T1l - &H80000000) Then Eh = Eh + 1
        
        Dh = Ch: Dl = Cl
        Ch = Bh: Cl = Bl
        Bh = Ah: Bl = Al
        Ah = T1h + T2h
        Al = T1l + T2l
        If (Al - &H80000000) < (T2l - &H80000000) Then Ah = Ah + 1
    Next i
    
    mStateH(0) = mStateH(0) + Ah: mStateL(0) = mStateL(0) + Al: If (mStateL(0) - &H80000000) < (Al - &H80000000) Then mStateH(0) = mStateH(0) + 1
    mStateH(1) = mStateH(1) + Bh: mStateL(1) = mStateL(1) + Bl: If (mStateL(1) - &H80000000) < (Bl - &H80000000) Then mStateH(1) = mStateH(1) + 1
    mStateH(2) = mStateH(2) + Ch: mStateL(2) = mStateL(2) + Cl: If (mStateL(2) - &H80000000) < (Cl - &H80000000) Then mStateH(2) = mStateH(2) + 1
    mStateH(3) = mStateH(3) + Dh: mStateL(3) = mStateL(3) + Dl: If (mStateL(3) - &H80000000) < (Dl - &H80000000) Then mStateH(3) = mStateH(3) + 1
    mStateH(4) = mStateH(4) + Eh: mStateL(4) = mStateL(4) + El: If (mStateL(4) - &H80000000) < (El - &H80000000) Then mStateH(4) = mStateH(4) + 1
    mStateH(5) = mStateH(5) + Fh: mStateL(5) = mStateL(5) + Fl: If (mStateL(5) - &H80000000) < (Fl - &H80000000) Then mStateH(5) = mStateH(5) + 1
    mStateH(6) = mStateH(6) + Gh: mStateL(6) = mStateL(6) + Gl: If (mStateL(6) - &H80000000) < (Gl - &H80000000) Then mStateH(6) = mStateH(6) + 1
    mStateH(7) = mStateH(7) + Hh: mStateL(7) = mStateL(7) + Hl: If (mStateL(7) - &H80000000) < (Hl - &H80000000) Then mStateH(7) = mStateH(7) + 1
End Sub


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   Class Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
    With modStaticClasses.SHA512
        Call CopyMemory(mKh(0), ByVal .KPtr.HiDWord, 320)
        Call CopyMemory(mKl(0), ByVal .KPtr.LoDWord, 320)
        mStatePtr = .StatePtr
    End With
    
    Set mBase = Cor.NewHashAlgorithmBase(Me, True, True, 128)
    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


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   IHashAlgorithm 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 BufferCount As Long, ByVal MessageLength As Currency) As Byte()
    IHashAlgorithm_HashFinal = HashFinal(Buffer, BufferCount, MessageLength)
End Function

Private Sub IHashAlgorithm_Initialize()
    Call 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


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   SHA512 Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get SHA512_CanReuseTransform() As Boolean
    SHA512_CanReuseTransform = CanReuseTransform
End Property

Private Property Get SHA512_CanTransformMultipleBlocks() As Boolean
    SHA512_CanTransformMultipleBlocks = CanTransformMultipleBlocks
End Property

Private Sub SHA512_Clear()
    Call Clear
End Sub

Private Function SHA512_ComputeHash(Source As Variant, Optional Index As Variant, Optional Count As Variant) As Byte()
    SHA512_ComputeHash = ComputeHash(Source, Index, Count)
End Function

Private Function SHA512_Equals(Value As Variant) As Boolean
    SHA512_Equals = Equals(Value)
End Function

Private Function SHA512_GetHashCode() As Long
    SHA512_GetHashCode = GetHashCode
End Function

Private Property Get SHA512_Hash() As Byte()
    SHA512_Hash = Hash
End Property

Private Property Get SHA512_HashSize() As Long
    SHA512_HashSize = HashSize
End Property

Private Sub SHA512_Initialize()
    Call Initialize
End Sub

Private Property Get SHA512_InputBlockSize() As Long
    SHA512_InputBlockSize = InputBlockSize
End Property

Private Property Get SHA512_OutputBlockSize() As Long
    SHA512_OutputBlockSize = OutputBlockSize
End Property

Private Function SHA512_ToString() As String
    SHA512_ToString = ToString
End Function

Private Function SHA512_TransformBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long, OutputBuffer() As Byte, ByVal OutputOffset As Long) As Long
    SHA512_TransformBlock = TransformBlock(InputBuffer, InputOffset, InputCount, OutputBuffer, OutputOffset)
End Function

Private Function SHA512_TransformFinalBlock(InputBuffer() As Byte, ByVal InputOffset As Long, ByVal InputCount As Long) As Byte()
    SHA512_TransformFinalBlock = TransformFinalBlock(InputBuffer, InputOffset, InputCount)
End Function




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -