Jump to content
argumentum

RC4 on win98, ws2003, win10

Recommended Posts

argumentum

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

Share this post


Link to post
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

  • Similar Content

    • nooneclose
      By nooneclose
      I am sure you guys know of a simple solution but I am still kind of new to AutoIt and its special functions. I want my code to be able to know how to encrypt and decrypt "A" and "a" as two different chars.
      my code is very long so here is just a snippet/example of it.  
      ;Encode== Global $charAA = "" ; ( Capital letter A ) = Global 184 = ¸ ( Cedilla ) $charAA = $charAA & Chr(65) Global $chara = "" ; ( Lowercase letter a ) = Global 251 = û ( û Latin Small Letter U With Circumflex ) $chara = $chara & Chr(97) ;Decode== Global $ch184 = "" ;( Copyright symbol ) = $charAA $ch184 = $ch184 & Chr(184) Global $ch251 = "" ;( û Latin Small Letter U With Circumflex ) = $chara $ch251 = $ch251 & Chr(251) ;Encode== stringreplace($test_String, $charAA, $ch184) stringreplace($test_String, $chara, $ch251) ;Decode== stringreplace($$new_String, $ch184, $charAA) stringreplace($$new_String, $ch251, $chara) ( NOTE: my stringreplace function is nested in my actual code. I only separated them here for readability. )

      I know there are better ways to Encrypt and Decrypt a message but I'm doing this as a fun side project for me and a select group of friends to enjoy. 
      Again My code is not encrypting or decrypting capitals and lower case properly even though I use their ANSI codes. 
       
      Example: Input "A a B b"  Encrypt: ". . $ $"  Decrypt: "A A B B"
      Any and all help will be greatly appreciated.  
    • SC0U7
      By SC0U7
      Hello i have a text file which contain over 600KB of BASE64 strings like :
      TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
      Now what i need is divide this long string as autoit variable each max lenght (4000characters per line) example:
      Local $var
      $var &=  TVqQAAMAAAAEAAA..
      $var &=  VbAmejwqqqAACEE..
      and then how to i add encrypt function on every line ? how to i can xor it? example final will be :
      $var &=  XorEnc(TVqQAAMAAAAEAAA..)
      $var &=  XorEncVbAmejwqqqAACEE..)
       
      Thanks for any help and ideas 
    • FMS
      By FMS
      Hello,
      I think this is a simple question if you know the answer.
      At this function i try to  (encrypt -> decrypt -> change -> encrypt ->decrypt->check ) an array.
      This is a snippet from a larger script but the error is the same.
      I do this encrypt decrypt action so i can save some setting along the way in a file.
      But at the end (when i change the data and not when i dont change the data) is empty.
      does somebody see what i'm doing wrong here?
       
      Func test() Local $LC_timestamp = @MDAY & "." & @MON & "." & @YEAR & "_" & @HOUR & ":" & @MIN & ":" & @SEC Global $GL_USS_base_count = 4 Global $GL_USS_base[$GL_USS_base_count][2] = [["nickname", "FMS"], ["last_login", $LC_timestamp], ["login_count", "1" ], ["naam3", $LC_timestamp]] Global $encrypted_GL_USS_true[$GL_USS_base_count] Global $encrypted_GL_USS_content_true[$GL_USS_base_count] Global $GL_array_decrypted_USS_names[$GL_USS_base_count] Global $GL_array_decrypted_USS_settings[$GL_USS_base_count] MsgBox($MB_SYSTEMMODAL, "should be 1", $GL_USS_base[2][1]) ;make for $i = 0 to $GL_USS_base_count -1 $encrypted_GL_USS_true[$i] = _Crypt_EncryptData($GL_USS_base[$i][0], $GL_encr_key_settings, $CALG_AES_128) $encrypted_GL_USS_content_true[$i] = _Crypt_EncryptData($GL_USS_base[$i][1], $GL_encr_key_settings, $CALG_AES_128) Next ;get for $i = 0 to $GL_USS_base_count -1 $GL_array_decrypted_USS_names[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) $GL_array_decrypted_USS_settings[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_content_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) Next MsgBox($MB_SYSTEMMODAL, "should be 1", $GL_array_decrypted_USS_settings[2]) ;change $GL_array_decrypted_USS_settings[2] = $GL_array_decrypted_USS_settings[2] + "1" MsgBox($MB_SYSTEMMODAL, "should be 2", $GL_array_decrypted_USS_settings[2]) ;save for $i = 0 to $GL_USS_base_count -1 $encrypted_GL_USS_true[$i] = _Crypt_EncryptData($GL_array_decrypted_USS_names[$i], $GL_encr_key_settings, $CALG_AES_128) $encrypted_GL_USS_content_true[$i] = _Crypt_EncryptData($GL_array_decrypted_USS_settings[$i], $GL_encr_key_settings, $CALG_AES_128) Next ;get for $i = 0 to $GL_USS_base_count -1 $GL_array_decrypted_USS_names[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) $GL_array_decrypted_USS_settings[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_content_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) Next ;check MsgBox($MB_SYSTEMMODAL, "should be 2", $GL_array_decrypted_USS_settings[2]) ;why is this emty????? EndFunc thanks in advanced
    • 31290
      By 31290
      Hi everyone, 
      I'm building some script that will encrypt some user password and store it in an ini file.
      I'd like to recall the password in a putty session but I can't figure out how to decrypt it:

      So far, I have:
      Global $Images = "C:\SAC_IS\ATL_Laptop\Resources\Images\" Global $WorkingDir = "C:\SAC_IS\Switches_Toolbox\" Global $Settings = $WorkingDir & "\Settings.ini" DirCreate ($WorkingDir) _FirstRun() While 1 Sleep(10) WEnd Func _FirstRun() If FileExists ("C:\SAC_IS\Switches_Toolbox\Settings.ini") Then _LoginfoGUI() Else MsgBox (64, "PUTTY EXECUTABLE", "First, select PUTTY.EXE path") Global $PuttyPath = FileOpenDialog("Please indicate putty.exe path", @HomeDrive, "exe (*.exe)") _LoginfoGUI() If @Error Then Global $Error = MsgBox(21, "Error!", "Can't find PUTTY.EXE!"& @CRLF & "Click Retry or Cancel to Quit") If $Error = $IDRETRY Then _FirstRun() Else _Exit() EndIf Else FileInstall ("C:\Users\h74033\Desktop\Scirpts\Switches\Settings.ini", $WorkingDir & "\Settings.ini", 1) IniWrite ($Settings, "Putty", "Path", $PuttyPath) EndIf EndIf ; SwitchesToolboxGui() Endfunc Func _Exit() Exit EndFunc Func _LoginfoGUI() Global $LoginfoGUI = GUICreate("Switches Toolbox Configuration", 300, 300, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $LoginfoGUI) GUICtrlCreatePic ($Images & "\SAClogo.jpg", 30, 10, 240, 80) GUISetBkColor ($Color_White) GUICtrlCreateLabel("-- SWITCHES TOOLBOX --", 85, 100, 150, 25) GUICtrlSetFont (-1, 8.5, 700, 0) GUICtrlCreateLabel("Please provide required information:", 10, 130, 250, 25) GUICtrlCreateLabel("-Global ID:", 10, 170, 60, 30) GUICtrlSetFont (-1, 8.5, 700, 0) GUICtrlCreateLabel("-Password:", 10, 210, 70, 30) GUICtrlSetFont (-1, 8.5, 700, 0) Global $GIDInput = GUICtrlCreateInput("", 90, 168, 80, 20) Global $PassInput = GUICtrlCreateInput("", 90, 205, 150, 20, $ES_PASSWORD) GUICtrlCreateButton ("Submit", 100, 245, 100, 25) GUICtrlSetOnEvent(-1, "_Submit") GUISetState(@SW_SHOW) EndFunc Func _Submit() Global $GID = GuiCtrlRead($GIDInput) Global $EncryptedPwd = _Crypt_HashData (GuiCtrlRead($PassInput), $CALG_MD2) IniWrite ($Settings, "Username", "Gid", $Gid) IniWrite ($Settings, "Encryption", "Password", $EncryptedPwd) ;MsgBox(0, "re", $EncryptedPwd) EndFunc How can I achieve that please?
      Thanks in advance
       
    • MikahS
      By MikahS

      Short-Order Encrypter
      Just a fun project I had making a Crypt GUI that will encrypt and decrypt messages and files. All regular encryption types have been included for use. It will dynamically ask for a password, making it so there are never any passwords stored inside script. All dynamically built. I have included source code for your pleasure
       
       
       
      I wanted to get this onto the forum just see if anyone had any use for it. I am open and listening for questions, concerns, and comments
       
      Short-Order Encrypter.zip
      Short-Order EncrypterV1.0.5.zip
      Short-Order EncrypterV1.5.0.zip
      Short-Order Encrypter V1.6.0.zip
      Short-Order Encrypter V1.6.1.zip
       
      Current Version: 1.6.1.0
       
       
      Version History:



×