function RC4(data,key) Dim s(256),k(256),outstr,Acii,j,tst,xre1,xre2,temp,x,t,y,qwe,zxc for i = 1 To 256 s(i) = i - 1 Next j = 1 for i = 1 To 256 dex = dex + 1 if j > len(key) Then j = 1 End if Acii = Asc(Mid(key,j,1)) if Acii < 0 Then tst = Hex(Acii) xre1 = Mid(tst,1,2) xre2 = Mid(tst,3,2) k(i) = Int("&H" & xre1) k(i + 1) = Int("&H" & xre2) i = i +1 else k(i) = Acii End if
j = j + 1 Next j = 0 for i = 1 To 256 j = (j + s(i) + k(i)) Mod 256 + 1 temp = s(i) s(i) = s(j) s(j) = temp Next j = 0 for i = 1 To len(data) x = (x + 1) Mod 256 + 1 j = (j + s(x)) Mod 256 + 1 temp = s(x) s(x) = s(j) s(j) = temp t = (s(x) + s(j) Mod 256) Mod 256 + 1 y = s(t) Acii = Asc(Mid(data,i,1)) if Acii < 0 Then tst = Hex(Acii) qwe = qwe + 1 if qwe >= 2 Then zxc = Int("&H" & Mid(tst,3,2)) qwe = 0 else zxc = Int("&H" & Mid(tst,1,2)) i = i -1 End if else zxc = Acii End if outstr = outstr & Bitsor(zxc,y) Next RC4 = outstr End function //---------------------位异或->到十六进制