[ 來源:動網(wǎng) |作者:佚名 ]
VB版rc4算法
Public Sub main()Dim key As StringFor i = 1 To 16Randomizekey = key & Chr(Rnd * 255)Next iMsgBox RC4(RC4("Welcome To Plindge Studio!", key), key)End SubPublic Function RC4(inp As String, key As String) As StringDim S(0 To 255) As Byte, K(0 To 255) As Byte, i As LongDim j As Long, temp As Byte, Y As Byte, t As Long, x As LongDim Outp As String
For i = 0 To 255S(i) = iNext
j = 1For i = 0 To 255If j > Len(key) Then j = 1K(i) = Asc(Mid(key, j, 1))j = j + 1Next i
j = 0For i = 0 To 255j = (j + S(i) + K(i)) Mod 256temp = S(i)S(i) = S(j)S(j) = tempNext i
i = 0j = 0For x = 1 To Len(inp)i = (i + 1) Mod 256j = (j + S(i)) Mod 256temp = S(i)S(i) = S(j)S(j) = tempt = (S(i) + (S(j) Mod 256)) Mod 256Y = S(t)
Outp = Outp & Chr(Asc(Mid(inp, x, 1)) Xor Y)NextRC4 = OutpEnd Function
來源:http://edu.chinaz.com