Home > Software engineering >  Returns an array of VB function is called.
Returns an array of VB function is called.

Time:10-04

 Function SM4_string (ByVal data As String, ByVal Key As String) As String 
Dim dataarray (15) As Byte
Dim keyarray (15) As Byte
Dim the output (15) As Byte
Dim As Integer I

Dataarray=BCD2bytearray (data)
'For I=0 To 15

Keyarray=BCD2bytearray (Key)
Call SM4_DECRY (dataarray (0), keyarray (0), the output (0))

SM4_string=bytearray2string (output)

End the Function

'turn hexadecimal integer byte array string
The Function bytearray2string (ByRef bytearray containing () As Byte) As String
Dim hexstring As String
Dim As Integer I
Dim temp As String

Bytearray2string=""

For I=0 To 15
Temp=fun_DEC_to_HEX (bytearray containing (I))
Bytearray2string=bytearray2string & amp; Temp
I=I + 1
Next I
End the Function

'type String BCD code (32 hexadecimal character to 16 decimal byte array)

The Public Function BCD2bytearray (ByVal BCD As String)
Dim bcdint (15) As Byte
Dim As Integer I
Dim temp As String
Dim j As Integer


J=0
For I=1 To 31 Step 2
Temp=Mid (BCD, I, 2)

Bcdint (j)=fun_BCD_to_DEC (temp)
J=j + 1
Next I
BCD2bytearray=bcdint
End the Function


The BCD2bytearray function is divided type string into decimal byte array, and then in sm4_string is called, but in dataarray=BCD2bytearray (data) of an error, can 't assign to array, I am a rookie, a great god solution,

CodePudding user response:

 Function SM4_string (ByVal data As String, ByVal Key As String) As String 
Dim dataarray (15) As Byte
Dim keyarray (15) As Byte
Dim the output (15) As Byte
Dim As Integer I

Dataarray=BCD2bytearray (data)
'For I=0 To 15

Keyarray=BCD2bytearray (Key)
Call SM4_DECRY (dataarray (0), keyarray (0), the output (0))

SM4_string=bytearray2string (output)

End the Function

'turn hexadecimal integer byte array string
The Function bytearray2string (ByRef bytearray containing () As Byte) As String
Dim hexstring As String
Dim As Integer I
Dim temp As String

Bytearray2string=""

For I=0 To 15
Temp=fun_DEC_to_HEX (bytearray containing (I))
Bytearray2string=bytearray2string & amp; Temp
I=I + 1
Next I
End the Function

'type String BCD code (32 hexadecimal character to 16 decimal byte array)

The Public Function BCD2bytearray (ByVal BCD As String) As Byte ()
Dim bcdint (15) As Byte
Dim As Integer I
Dim temp As String
Dim j As Integer


J=0
For I=1 To 31 Step 2
Temp=Mid (BCD, I, 2)

Bcdint (j)=fun_BCD_to_DEC (temp)
J=j + 1
Next I
BCD2bytearray=bcdint
End the Function


Less as a byte () statement, but still won't do, please instruct ahhh I!

CodePudding user response:

Assigned data can't be a static array, instead of to dynamic
 Dim dataarray () As Byte 
Dim keyarray () As Byte
  • Related