Jump to content

Rc4 Text Encryption


RazerM
 Share

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • 2 months later...
  • Moderators

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

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Faster string->hex functions:

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

Func _StringToHexEx($strChar)
   Return Hex(BinaryString($strChar))
EndFunc
:whistle:
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • 9 months later...

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?

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...