Sign in to follow this  
Followers 0

Rc4 Text Encryption

13 posts in this topic

#1 ·  Posted (edited)

I have made an RC4 Text Encryption UDF. I know RC4 isn't the strongest encryption but anyway here it is:

;===============================================================================
;
; Function Name:   _StringEncryptRC4
; Description::    Encrypts text using RC4 Encryption
; Parameter(s):    $text, $encryptkey
; Requirement(s):  AutoIt
; Return Value(s): Encrypted String
; Author(s):       RazerM
;
;===============================================================================
;
Func _StringEncryptRC4($text, $encryptkey)
    Local $sbox[256]
    Local $key[256]
    Local $temp
    Local $a
    Local $i
    Local $j
    Local $k
    Local $cipherby
    Local $cipher
    
    $i = 0
    $j = 0
    
    __RC4Initialize($encryptkey, $key, $sbox)
    
    For $a = 1 To StringLen($text)
        $i = Mod(($i + 1),256)
        $j = Mod(($j + $sbox[$i]),256)
        $temp = $sbox[$i]
        $sbox[$i] = $sbox[$j]
        $sbox[$j] = $temp
        
        $k = $sbox[Mod(($sbox[$i] + $sbox[$j]),256)]
        
        $cipherby = BitXOR(Asc(StringMid($text, $a, 1)),$k)
        $cipher = $cipher & Chr($cipherby)
    Next
    
    Return _StringToHexEx($cipher)
EndFunc   ;==>_StringEncryptRC4

;===============================================================================
;
; Function Name:   _StringDecryptRC4
; Description::    Decrypts text using RC4 Encryption
; Parameter(s):    $text, $encryptkey
; Requirement(s):  AutoIt
; Return Value(s): Decrypted String
; Author(s):       RazerM
; Note(s):         RC4 uses the same algorithm to encrypt and decrypt
;
;===============================================================================
;

Func _StringDecryptRC4($text, $encryptkey)
    Local $sbox[256]
    Local $key[256]
    Local $temp
    Local $a
    Local $i
    Local $j
    Local $k
    Local $cipherby
    Local $cipher
    $text = _HexToStringEx($text)
    
    $i = 0
    $j = 0
    
    __RC4Initialize($encryptkey, $key, $sbox)
    
    For $a = 1 To StringLen($text)
        $i = Mod(($i + 1),256)
        $j = Mod(($j + $sbox[$i]),256)
        $temp = $sbox[$i]
        $sbox[$i] = $sbox[$j]
        $sbox[$j] = $temp
        
        $k = $sbox[Mod(($sbox[$i] + $sbox[$j]),256)]
        
        $cipherby = BitXOR(Asc(StringMid($text, $a, 1)),$k)
        $cipher = $cipher & Chr($cipherby)
    Next
    Return $cipher
EndFunc   ;==>_StringDecryptRC4


; Helper function
Func __RC4Initialize($strPwd, ByRef $key, ByRef $sbox)
    Dim $tempSwap
    Dim $a
    Dim $b
    
    $intLength = StringLen($strPwd)
    For $a = 0 To 255
        $key[$a] = Asc(StringMid($strPwd, (Mod($a,$intLength))+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
EndFunc   ;==>__RC4Initialize

Func _HexToStringEx($strHex)
    Return BinaryToString("0x" & $strHex)
EndFunc   ;==>_HexToStringEx

Func _StringToHexEx($strChar)
    Return Hex(StringToBinary($strChar))
EndFunc   ;==>_StringToHexEx oÝ÷ Øw«z+-ç±jjey«­¢+Ø¥¹±ÕÅÕ½ÐíIйÔÌÅÕ½Ðì(ÀÌØíÑáÐô%¹ÁÕÑ ½à ÅÕ½ÐíQáÐÅÕ½Ðì°ÅÕ½Ðí¹ÑÈÑáÐѼ¹ÉåÁÐÅÕ½Ðì¤(ÀÌØí¹ÉåÁÑ­äô%¹ÁÕÑ  ½à ÅÕ½Ðí-äÅÕ½Ðì°ÅÕ½Ðí¹ÑÈ­äѼ¹ÉåÁÐÑ¡ÑáÐÅÕ½Ðì¤(ÀÌØíÉÐôQ¥µÉ%¹¥Ð ¤(ÀÌØí¹ÉåÁÑô}MÑÉ¥¹¹ÉåÁÑIÐ ÀÌØíÑáаÀÌØí¹ÉåÁÑ­ä¤)5Í ½à À°ÅÕ½Ðí¹ÉåÁÑ¥½¸Q½½¬èÅÕ½Ðì°Q¥µÉ¥ ÀÌØíÉФµÀìÅÕ½ÐìµÌÅÕ½Ðì¤)5Í    ½à À°ÅÕ½Ðí¹ÉåÁÑÅÕ½Ðì°ÅÕ½Ðí¹ÉåÁÑÑáÐ¥ÌèÅÕ½ÐìµÀìÀÌØí¹ÉåÁѤ)5Í   ½à À°ÅÕ½ÐíÉåÁÑÅÕ½Ðì°ÅÕ½ÐíÉåÁÑÑáÐ¥ÌèÅÕ½ÐìµÀì}MÑÉ¥¹ÉåÁÑIÐ ÀÌØí¹ÉåÁÑ°ÀÌØí¹ÉåÁѭ䤤((
Edited by RazerM

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites



#2 ·  Posted

Very nice and fast RazorM!

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thanks. It is about half the time of the built in _StringEncrypt function.


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

#4 ·  Posted

really nice!

Share this post


Link to post
Share on other sites

#5 ·  Posted

Nicely done RazerM.


[font="Lucida Sans Unicode"]M a k. a v e L ![/font]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Very nice indeed, nice job Razer.

Edit:

A suggestion though, since you're not using unique vars, is to keep them in a local scope.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#7 ·  Posted

I updated it. Thanks SmOke_N


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

#8 ·  Posted

Faster string->hex functions:

Func _HexToStringEX($strHex)
   Return BinaryString("0x" & $strHex)
EndFunc

Func _StringToHexEx($strChar)
   Return Hex(BinaryString($strChar))
EndFunc
:whistle:

Share this post


Link to post
Share on other sites

#9 ·  Posted

I would never have thought of doing that! Im implementing it now


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

#10 ·  Posted

Hey Razerm

It seems this script no longer works with the latest released version of the Autoit??

Return [b]BinaryString[/b]("0x" & $strHex)

The BinaryString function no longer works??

Any ideas?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I'll update in a few minutes.

Edit: Updated

Edited by RazerM

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

#12 ·  Posted

Gonna make a GUI for this as well.

Share this post


Link to post
Share on other sites

#13 ·  Posted

It doesn't need one, but if you do, don't post it in this topic.


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

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
Sign in to follow this  
Followers 0