Jump to content

RC4 on win98, ws2003, win10


argumentum
 Share

Recommended Posts

I wanted to use Ward's code but did'nt work on server2003, the old _StringEncrypt is not RC4, the one that comes now I can't use in win98, so here is a port. Could not find one in the forums. This should act just like Ward's, but a thousand times slower.

#include "RC4.au3"

Local $p = 'key'
Local $d = ', lots of data'
$d = $d & $d;&$d&$d&$d&$d&$d&$d&$d&$d&$d&$d&$d&$d&$d


Local $t = TimerInit()
$Encrypt = _RC4($d, $p)
ConsoleWrite("1 ward $Encrypt >" & $Encrypt & "<" & @CRLF)
$Decrypt = _RC4($Encrypt, $p)
ConsoleWrite("1 ward $Decrypt >" & BinaryToString($Decrypt) & "<" & @CRLF & " time: " & Round(TimerDiff($t), 5) & " mSec." & @CRLF & @CRLF)


$Encrypt = rc4(StringToBinary($p), StringToBinary($d))
ConsoleWrite("2 this $Encrypt >" & Binary($Encrypt) & "<" & @CRLF)
$Decrypt = rc4(StringToBinary($p), BinaryToString($Encrypt))
ConsoleWrite("2 this $Decrypt >" & BinaryToString($Decrypt) & "<" & @CRLF & " time: " & Round(TimerDiff($t), 5) & " mSec." & @CRLF & @CRLF)


Func rc4($key_str, $data_str)

    ; convert input strings to arrays
    Local $key_str_u = StringSplit(BinaryToString($key_str), "")
    Local $data_str_u = StringSplit(BinaryToString($data_str), "")
    Local $key[$key_str_u[0]]
    Local $data[$data_str_u[0]]
    Local $i
    For $i = 0 To $key_str_u[0] - 1
        $key[$i] = Asc($key_str_u[$i + 1])
    Next
    For $i = 0 To $data_str_u[0] - 1
        $data[$i] = Asc($data_str_u[$i + 1])
    Next

    ; prepare key
    Local $state[256]
    For $i = 0 To 255
        $state[$i] = $i
    Next
    Local $tmp, $x = 0, $y = 0
    For $i = 0 To 255
        $y = Mod($key[$x] + $state[$i] + $y, 256)
        $tmp = $state[$i]
        $state[$i] = $state[$y]
        $state[$y] = $tmp
        $x = Mod(($x + 1), $key_str_u[0])
    Next

    ; rc4
    $x = 0
    $y = 0
    For $i = 0 To $data_str_u[0] - 1
        $x = Mod(($x + 1), 256)
        $y = Mod(($state[$x] + $y), 256)
        $tmp = $state[$x];
        $state[$x] = $state[$y]
        $state[$y] = $tmp
        $data[$i] = BitXOR($data[$i], $state[Mod(($state[$x] + $state[$y]), 256)])
    Next

    ; convert output back to a string
    $data_str = ""
    For $i = 0 To $data_str_u[0] - 1
        $data_str &= Chr($data[$i])
    Next

    Return $data_str
EndFunc   ;==>rc4
 

hope it helps for those needing autoit v3.2.12.1

Edit 1: found working code at this post:  , next time I'll pay more attention  :sweating:

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...