EncryptDecrypt "the quick brown fox", "12345ABCDEF"
Code: Select all
global sbox
global key
Function EncryptDecrypt plaintxt, psw
put 0 into temp
put 0 into a
put 0 into i
put 0 into j
put 0 into k
put 0 into cipherby
put "" into cipher
put 0 into z
Initialize( psw )
repeat with a = 1 to Length(plaintxt)
put ( (i + 1) mod 256 ) into i
if i = 0 then put 1 into i
put ( (j + sbox[i]) mod 256 ) into j
if j = 0 then put 1 into j
put sbox[i] into temp
put sbox[j] into sbox[i]
put temp into sbox[j]
put ((sbox[i] + sbox[j]) mod 256) into z
if z = 0 then put 1 to z
put sbox[ z ] into k
if k = 0 then put 1 into k
put ( Asc(Mid(plaintxt, a, 1)) bitXOr k ) into cipherby
put cipher + Chr(cipherby) into cipher
end repeat
return cipher
end EncryptDecrypt
function Initialize pwd
put 0 into tempSwap
put 0 into a
put 0 into b
put 0 into intLength
put length(strPwd) into intLength
repeat with a = 1 to 256
put Asc( SubStr(strpwd, (a mod intLength)+1, 1) ) into key[a]
put a into sbox[a]
end repeat
put 1 into b
repeat with a = 1 to 256
put (( b + sbox[a] + key[a] ) mod 256 ) into b
if b = 0 then put 1 into b
put sbox[a] into tempSwap
put sbox[b] into sbox[a]
put tempSwap into sbox[b]
end repeat
end Initialize
function SubStr thestring, from_pos, to_pos
put char from_pos to from_pos of thestring into PartString
return PartString
end SubStr
function Asc theChar
return charToNum(theChar)
end Asc
function Chr theASCIIcode
return numToChar( theASCIIcode )
end Chr