A while back I posted an RC4 function, but it wasn't 100%. This was due to AutoIt not supporting NULs. Some additional work resulted in this itteration. To get around the NUL issue the function returns a HEX string rather than a character string. By the way this makes it easy to read/write encrypted text to/from the registry as REG_BINARY.
Test Code:
$pw = "~#[.ab!@MNmn6UVuv2-<EFef`$KLkl7&\XwABW{,CDcdx1+>}/GHgh9%]IJij8^|YZyz0=?*:OPop 5(""QRqr4);STst3_'"
$text = "AutoIt has been designed to work on Windows 95, 98, ME, NT 4, 2000, XP and 2003."
$Encrypted = RC4($text, $pw, 0)
MsgBox(0,"Encrypted Text",$Encrypted)
$Decrypted = RC4($Encrypted, $pw, 1)
MsgBox(0,"Decrypted Text",$Decrypted)
MsgBox(0,"Original = Decrypted",$text = $Decrypted)
RC4 Function
Func RC4($Data, $Phrase, $Decrypt)
Local $a, $b, $i, $j, $k, $cipherby, $cipher
Local $tempSwap, $temp, $PLen
Local $sbox[256], $key[256]
$PLen = StringLen($Phrase)
For $a = 0 To 255
$key[$a] = Asc(StringMid($Phrase, Mod($a, $PLen) + 1, 1))
$sbox[$a] = $a
Next
$b = 0
For $a = 0 To 255
$b = Mod( ($b + $sbox[$a] + $key[$a]), 256)
$tempSwap = $sbox[$a]
$sbox[$a] = $sbox[$b]
$sbox[$b] = $tempSwap
Next
If $Decrypt Then
For $a = 1 To StringLen($Data) Step 2
$i = Mod(($i + 1), 256)
$j = Mod(($j + $sbox[$i]), 256)
$k = $sbox[Mod(($sbox[$i] + $sbox[$j]), 256)]
$cipherby = BitXOR(Dec(StringMid($Data, $a, 2)), $k)
$cipher = $cipher & Chr($cipherby)
Next
Else
For $a = 1 To StringLen($Data)
$i = Mod(($i + 1), 256)
$j = Mod(($j + $sbox[$i]), 256)
$k = $sbox[Mod(($sbox[$i] + $sbox[$j]), 256)]
$cipherby = BitXOR(Asc(StringMid($Data, $a, 1)), $k)
$cipher = $cipher & Hex($cipherby, 2)
Next
EndIf
Return $cipher
EndFunc ;==>RC4