我用以下得DES加密VB程序得出得结果和vc中得结果为什么不同?
在vc中得出得ee和vb中得ee相同,而vc中做了一个这样得处理
For i = 0 To 7
s+ =(char)ee(i)
Next i
在vb中做了一个
For i = 0 To 7
s = s & Chr(ee(i))
Next i
这样处理,这里vc和vb得结果为什么不同?以下是DES加密vb程序
private sub command_click
Dim inEncARR() As Byte
Dim ee() As Byte
ReDim inEncARR(8) As Byte
inEncARR(0) = 48
inEncARR(1) = 48
inEncARR(2) = 57
inEncARR(3) = 66
inEncARR(4) = 48
inEncARR(5) = 83
inEncARR(6) = 77
inEncARR(7) = 53
DES_Encode inEncARR, "12345678", ee
'将DES加密得出得结果转换成字符串
For i = 0 To 7
s = s & Chr(ee(i))
Next i end sub'''''''''''''''''''''''''''''''''''''''''以下是DES加密过程'''''''''''''''''''''''''''''
Public Sub DES_Decode(ByRef sCode() As Byte, ByVal sKey As String, ByRef bReturn() As Byte)
Attribute DES_Decode.VB_Description = "解密 sCode:密文16进制串 sKey:密钥文本,前8位有效 bReturn:明文16进制串"
Dim LenTimes As Integer '明文
Dim tempKey() As Byte '存放密钥
Dim BinKey(63) As Byte '64位二进制原始密钥
Dim KeyPC_1(55) As Byte '存放56位密钥
Dim tempCode(7) As Byte '存放8位原始密文
Dim tempReturn(7) As Byte '存放8位明文
Dim BinCode(63) As Byte '存放64位明文
Dim CodeIP(63) As Byte '存放IP置换结果
Dim CodeE(47) As Byte 'E膨胀结果
Dim CodeP(31) As Byte 'P变换结果
Dim RetS(47) As Byte 'S盒运算32位结果
Dim S(7) As Byte 'S盒运算8个结果
Dim CodeS1(5) As Byte: Dim CodeS2(5) As Byte: Dim CodeS3(5) As Byte: Dim CodeS4(5) As Byte
Dim CodeS5(5) As Byte: Dim CodeS6(5) As Byte: Dim CodeS7(5) As Byte: Dim CodeS8(5) As Byte
CodeP(i) = RetS(P(i))
'产生L15,R15
R15(i) = L14(i) Xor CodeP(i)
L15(i) = R14(i)
Next
'进行第16次迭代
For i = 0 To 47
CodeE(i) = R15(E(i)) '经过E变换扩充,由32位变为48位
CodeE(i) = CodeE(i) Xor K1(i) '与K1按位作不进位加法运算
Next
For i = 0 To 7
tempReturn(i) = CodeIP(i * 8 + 0) * &H80
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 1) * &H40
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 2) * &H20
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 3) * &H10
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 4) * &H8
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 5) * &H4
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 6) * &H2
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 7) * &H1
Next CopyMemory bReturn(j), tempReturn(0), 8
Next
End Sub
在vc中得出得ee和vb中得ee相同,而vc中做了一个这样得处理
For i = 0 To 7
s+ =(char)ee(i)
Next i
在vb中做了一个
For i = 0 To 7
s = s & Chr(ee(i))
Next i
这样处理,这里vc和vb得结果为什么不同?以下是DES加密vb程序
private sub command_click
Dim inEncARR() As Byte
Dim ee() As Byte
ReDim inEncARR(8) As Byte
inEncARR(0) = 48
inEncARR(1) = 48
inEncARR(2) = 57
inEncARR(3) = 66
inEncARR(4) = 48
inEncARR(5) = 83
inEncARR(6) = 77
inEncARR(7) = 53
DES_Encode inEncARR, "12345678", ee
'将DES加密得出得结果转换成字符串
For i = 0 To 7
s = s & Chr(ee(i))
Next i end sub'''''''''''''''''''''''''''''''''''''''''以下是DES加密过程'''''''''''''''''''''''''''''
Public Sub DES_Decode(ByRef sCode() As Byte, ByVal sKey As String, ByRef bReturn() As Byte)
Attribute DES_Decode.VB_Description = "解密 sCode:密文16进制串 sKey:密钥文本,前8位有效 bReturn:明文16进制串"
Dim LenTimes As Integer '明文
Dim tempKey() As Byte '存放密钥
Dim BinKey(63) As Byte '64位二进制原始密钥
Dim KeyPC_1(55) As Byte '存放56位密钥
Dim tempCode(7) As Byte '存放8位原始密文
Dim tempReturn(7) As Byte '存放8位明文
Dim BinCode(63) As Byte '存放64位明文
Dim CodeIP(63) As Byte '存放IP置换结果
Dim CodeE(47) As Byte 'E膨胀结果
Dim CodeP(31) As Byte 'P变换结果
Dim RetS(47) As Byte 'S盒运算32位结果
Dim S(7) As Byte 'S盒运算8个结果
Dim CodeS1(5) As Byte: Dim CodeS2(5) As Byte: Dim CodeS3(5) As Byte: Dim CodeS4(5) As Byte
Dim CodeS5(5) As Byte: Dim CodeS6(5) As Byte: Dim CodeS7(5) As Byte: Dim CodeS8(5) As Byte
CodeP(i) = RetS(P(i))
'产生L15,R15
R15(i) = L14(i) Xor CodeP(i)
L15(i) = R14(i)
Next
'进行第16次迭代
For i = 0 To 47
CodeE(i) = R15(E(i)) '经过E变换扩充,由32位变为48位
CodeE(i) = CodeE(i) Xor K1(i) '与K1按位作不进位加法运算
Next
For i = 0 To 7
tempReturn(i) = CodeIP(i * 8 + 0) * &H80
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 1) * &H40
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 2) * &H20
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 3) * &H10
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 4) * &H8
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 5) * &H4
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 6) * &H2
tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 7) * &H1
Next CopyMemory bReturn(j), tempReturn(0), 8
Next
End Sub
For i = 0 To 7
s = s & Chr(ee(i))
Next iVB 中文版会将不可打印字符直接转成 "?"
For i = 0 To 7
s+ =(char)ee(i)
Next i
这个转换存在不同,所以造成后面得错误,现在就是如何吧他转成字符后和vc中转得相同