|
|
|
RC4 Encryption Algorithm Script
Added on 4/9/2002
|
RC4 is a stream cipher.
Using a password, a string may be encrypted. By running the encrypted text through the same algorithm, the string becomes readable only when the password is the same as the one used during encryption.
Great for protecting your high score tables or prefs files from prying eyes and itchy hacker fingers!
;) PsychicParrot.
Download PC Source
-- RC4 Algorithm
--
-- Adapted from VB code written by Luke Bailey
-- Copyright 2002 PsychicParrot
-- oracle@psychicparrot.com
--
-- You are welcome to use this script as you wish, but keep these comments intact please!
--
global sbox,ke,scn,srn,tempswap,a,b
global temp,i,j,k,cipherkey,cipher
on beginsprite
sbox=[]
ke=[]
end
on Security_RC4Initialise(strpwd)
cipher=EMPTY
intlength = strpwd.length
sbox=[]
ke=[]
repeat with a=1 to 255
ke[a]=chartonum(strpwd.char[(a mod intlength+1)..(a mod intlength+1)])
sbox[a]=a
end repeat
b=0
repeat with a=1 to 255
b=((b+sbox[a]+ke[a]) mod 255)
tempswap = sbox[a]
sbox[a]=sbox[b]
sbox[b]=tempswap
end repeat
end
on Security_RC4(plaintxt)
i=0
j=0
repeat with a=1 to plaintxt.length
i=((i+1) mod 255)
j=((j+sbox[i]) mod 255)
temp=sbox[i]
sbox[i]=sbox[j]
sbox[j]=temp
k=sbox[((sbox[i]+sbox[j]) mod 255)]
cipherby=bitXor(chartonum(plaintxt.char[a..a]),k)
cipher=cipher&numtochar(cipherby)
end repeat
RETURN cipher
end
|
|