求教各位大虾,帮我解释下这段代码的意思
第一个:Private Sub Append(ByRef StringData As String, Optional Length As Long)
Dim DataLength As Long
If Length > 0 Then DataLength = Length Else DataLength = Len(StringData)
If DataLength + hiByte > hiBound Then
hiBound = hiBound + 1024
ReDim Preserve byteArray(hiBound)
End If
CopyMem ByVal VarPtr(byteArray(hiByte)), ByVal StringData, DataLength
hiByte = hiByte + DataLength
End Sub(关于blowfish加密上面的一些代码)
Private Property Get GData() As String
Dim StringData As String
StringData = Space(hiByte) '** 复制字符数组地址内容到字符串地址
CopyMem ByVal StringData, ByVal VarPtr(byteArray(0)), hiByte
GData = StringData
End Property
Private Sub Reset()
hiByte = 0
hiBound = 1024
ReDim byteArray(hiBound)
End Sub
Private Static Sub DecryptBlock(Xl As Long, Xr As Long)
Dim i As Long, j As Long, K As Long
K = Xr
Xr = Xl Xor m_pBox(ROUNDS + 1)
Xl = K Xor m_pBox(ROUNDS)
j = ROUNDS - 2
For i = 0 To (ROUNDS \ 2 - 1)
Xl = Xl Xor f(Xr)
Xr = Xr Xor m_pBox(j + 1)
Xr = Xr Xor f(Xl)
Xl = Xl Xor m_pBox(j)
j = j - 2
Next
End Sub
第二段:
Public Sub EncryptByte(byteArray() As Byte, Optional Key As String)
Dim Offset As Long, OrigLen As Long, LeftWord As Long, RightWord As Long, CipherLen As Long, CipherLeft As Long, CipherRight As Long, CurrPercent As Long, NextPercent As Long
If (Len(Key) > 0) Then Me.Key = Key
OrigLen = UBound(byteArray) + 1
CipherLen = OrigLen + 12
If (CipherLen Mod 8 <> 0) Then CipherLen = CipherLen + 8 - (CipherLen Mod 8)
ReDim Preserve byteArray(CipherLen - 1)
Call CopyMem(byteArray(12), byteArray(0), OrigLen)
Call CopyMem(byteArray(8), OrigLen, 4)
Call Randomize
Call CopyMem(byteArray(0), CLng(2147483647 * Rnd), 4)
Call CopyMem(byteArray(4), CLng(2147483647 * Rnd), 4)
'#####
With frmEncryption
.Progress.Min = 0
.Progress.Max = (CipherLen - 1)
End With
'#####
For Offset = 0 To (CipherLen - 1) Step 8
Call GetWord(LeftWord, byteArray(), Offset)
Call GetWord(RightWord, byteArray(), Offset + 4)
LeftWord = LeftWord Xor CipherLeft
RightWord = RightWord Xor CipherRight
Call EncryptBlock(LeftWord, RightWord)
Call PutWord(LeftWord, byteArray(), Offset)
Call PutWord(RightWord, byteArray(), Offset + 4)
CipherLeft = LeftWord
CipherRight = RightWord
If (Offset >= NextPercent) Then
CurrPercent = Int((Offset / CipherLen) * 100)
NextPercent = (CipherLen * ((CurrPercent + 1) / 100)) + 1
RaiseEvent Progress(CurrPercent)
End If
'####
DoEvents
frmEncryption.Progress.Value = Offset
'####
Next
If (CurrPercent <> 100) Then RaiseEvent Progress(100)
End Sub 加密 bytearray String ActionScript
补充:VB , 网络编程