需要帮助Vb6 Xor Large Numbers

时间:2012-02-18 17:46:11

标签: vb.net

Dim Key As Long
Packet = txtSend.Text
PacketLength = Len(txtSend.Text)
key = &H82381AC + PacketLength * "17"
For ix = 1 To PacketLength - 1
OneCharacter = Mid$(Packet, ix, 1)
NewCharacter = Asc(OneCharacter) Xor key And &H1F
key = key * "13" Xor &H43B
Next ix

循环将运行大约3次然后溢出。我想无论你做什么xor都会导致Byte,Integer或Long。 CDec(Key)不起作用我需要一种方法来绕过这个,所以我可以Xor大数。

1 个答案:

答案 0 :(得分:1)

您只能对整数进行异或,而不是字符串。如果要使用XOR加密字符串,请通过逐字符对字符代码

应用XOR来执行此操作
Public Function Encrypt(ByVal s As String) As String
    Const key As String = "r5^245ADh3%^ywftGY53Gsdr245^Tsfdgw45^fGqw4%6243TefgH563&ot7y"
    Dim i As Integer

    For i = 1 To Len(s)
        Mid(s, i, 1) = Chr(Asc(Mid(s, i, 1)) Xor Asc(Mid(key, i, 1)))
    Next i
    Return s
End Function