字符串加密解密,用VB写的加密,要用java解密(附VB解密源代码)。会VB与java的请进!
因为原来网络客户端加密英文字符串时用的如下程序:
'加密
Private Function Cipher(ByVal password As String, ByVal from_text As String) As String
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1
Dim Offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
Dim to_text
Offset = NumericPassword(password)
Rnd -1
Randomize Offset
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, i, 1))
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch - MIN_ASC
Offset = Int((NUM_ASC + 1) * Rnd)
ch = ((ch + Offset) Mod NUM_ASC)
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
Cipher = to_text
End Function
'解密
Private Function Decipher(ByVal password As String, ByVal from_text As String) As String
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1
Dim Offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
Dim to_text
Offset = NumericPassword(password)
Rnd -1
Randomize Offset
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, i, 1))
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch - MIN_ASC
Offset = Int((NUM_ASC + 1) * Rnd)
ch = ((ch - Offset) Mod NUM_ASC)
If ch < 0 Then ch = ch + NUM_ASC
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
Decipher = to_text
End Function
Private Function NumericPassword(ByVal password As String) As Long
Dim value As Long
Dim ch As Long
Dim shift1 As Long
Dim shift2 As Long
Dim i As Integer
Dim str_len As Integer
str_len = Len(password)
For i = 1 To str_len
' Add the next letter.
ch = Asc(Mid$(password, i, 1))
value = value Xor (ch * 2 ^ shift1)
value = value Xor (ch * 2 ^ shift2)
shift1 = (shift1 + 7) Mod 19
shift2 = (shift2 + 13) Mod 23
Next i
NumericPassword = value
End Function
我在服务端想用java解密。但是就是因为:Rnd 这个值(生成的随机序列和java里生成的不一样) 所以没办法了!关键就是要用java写时也和上面的VB写的生成的随机数序列一样就好了。我想真的可能是没有办法一样的。因为一个是VB的,一个是java的随机生成器。
想问问,有没有办法?谢啦!!!
^_^