Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Rc4 Text Encryption


  • Please log in to reply
12 replies to this topic

#1 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 16 May 2006 - 03:14 PM

I have made an RC4 Text Encryption UDF. I know RC4 isn't the strongest encryption but anyway here it is:
AutoIt         
;=============================================================================== ; ; 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, 04 June 2007 - 03:36 PM.

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.







#2 dash007

dash007

    Wayfarer

  • Active Members
  • Pip
  • 79 posts

Posted 16 May 2006 - 08:44 PM

Very nice and fast RazorM!

#3 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 17 May 2006 - 08:49 PM

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.

#4 vikingnor

vikingnor

    Seeker

  • Active Members
  • 25 posts

Posted 18 May 2006 - 01:17 AM

really nice!

#5 M a k a v e l !

M a k a v e l !

    Seeker

  • Active Members
  • 37 posts

Posted 12 August 2006 - 05:40 PM

Nicely done RazerM.
M a k. a v e L !Posted ImagePosted Image

#6 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 16,014 posts

Posted 12 August 2006 - 05:51 PM

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, 12 August 2006 - 05:52 PM.

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.


#7 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 12 August 2006 - 07:20 PM

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.

#8 erifash

erifash

    autoit - think free

  • Active Members
  • PipPipPipPipPipPip
  • 517 posts

Posted 13 August 2006 - 02:39 AM

Faster string->hex functions:
Func _HexToStringEX($strHex)    Return BinaryString("0x" & $strHex) EndFunc Func _StringToHexEx($strChar)    Return Hex(BinaryString($strChar)) EndFunc
:whistle:

#9 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 13 August 2006 - 10:57 AM

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.

#10 lyledg

lyledg

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 296 posts

Posted 04 June 2007 - 06:11 AM

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?

#11 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 04 June 2007 - 03:28 PM

I'll update in a few minutes.

Edit: Updated

Edited by RazerM, 04 June 2007 - 03:37 PM.

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.

#12 AngelSL

AngelSL

    Seeker

  • Active Members
  • 44 posts

Posted 04 June 2007 - 03:41 PM

Gonna make a GUI for this as well.

#13 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 04 June 2007 - 03:42 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users