a6m1n0 Posted September 24, 2006 Posted September 24, 2006 (edited) What is posted I ported from ASP VBScript to AutoIt3 as the syntax was the most similar. Tested with ASP VBScript, PHP with mcrypt, and Flash AsCrypt Library. Please note that I use the _StringToHex and _HexToString UDF's to handle the case of non-printable characters. Also note that the same function is used to decrypt as well as encrypt.expandcollapse popupFunc _RC4Crypt($plaintxt, $psw) Local $sbox[256] Local $key[256] Local $temp, $a, $k, $cipherby, $cipher, $tempSwap, $aa, $bb, $intLength Local $i = 0 Local $j = 0 $intLength = StringLen($psw) For $aa = 0 To 255 $key[$aa] = Asc(StringMid($psw, Mod($aa,$intLength)+1, 1)) $sbox[$aa] = $aa Next $bb = 0 For $aa = 0 To 255 $bb = Mod(($bb + $sbox[$aa] + $key[$aa]), 256) $tempSwap = $sbox[$aa] $sbox[$aa] = $sbox[$bb] $sbox[$bb] = $tempSwap Next For $a = 1 To StringLen($plaintxt) $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($plaintxt, $a, 1)), $k) $cipher &= Chr($cipherby) Next Return $cipher EndFunc; _RC4CryptoÝ÷ ØLZ^RÆ y«¢+Ø¥¹±Õ±ÐíÍÑÉ¥¹¹ÔÌÐì(¥¹±Õ±ÐíIйÔÌÐì)¥´ÀÌØíµåÁḬ́ÀÌØíµåÑáаÀÌØíµå¹ÑáаÀÌØíµå¡á¹ÑáаÀÌØíµåÑáаÀÌØíµ½áÑáÐ(ÀÌØíµåÁÍÌôÅÕ½ÐìÄÈÌÐÔØÅÕ½Ðì(ÀÌØíµåÑáÐôÅÕ½ÐíQ¡¥Ì¥ÌͽµÑáÐѼ¹ÉåÁСɸÅÕ½Ðì(ÀÌØíµå¹ÑáÐô}MÑÉ¥¹Q½!à¡}IÑ ÉåÁÐ ÀÌØíµåÑáаÀÌØíµåÁÍ̤¤(ÀÌØíµåÑáÐô}IÑ ÉåÁС}!áQ½MÑÉ¥¹ ÀÌØíµå¹ÑáФ°ÀÌØíµåÁÍ̤(ÀÌØíµ½áÑáÐôÅÕ½ÐìÅÕ½Ðì(ÀÌØíµ½áÑáеÀìôÅÕ½ÐíAÍÍݽÉèÅÕ½ÐìµÀí I1µÀìÀÌØíµåÁÍ̵Àí I1µÀí I1(ÀÌØíµ½áÑáеÀìôÅÕ½ÐíQáÐMÑÉ¥¹èÅÕ½ÐìµÀí I1µÀìÀÌØíµåÑáеÀí I1µÀí I1(ÀÌØíµ½áÑáеÀìôÅÕ½Ðí!`ÌäíIйÉåÁÑèÅÕ½ÐìµÀí I1µÀìÀÌØíµå¹ÑáеÀí I1µÀí I1(ÀÌØíµ½áÑáеÀìôÅÕ½Ðí!`ÌäíIÐÉåÁÑÅÕ½ÐìµÀí I1µÀìÀÌØíµåÑáеÀí I1µÀí I1)5Í ½à À°ÅÕ½ÐìÅÕ½Ðì°ÀÌØíµ½áÑáаÈÀ¤I hope someone finds this useful. Edited September 24, 2006 by a6m1n0
Valik Posted September 24, 2006 Posted September 24, 2006 As far as I know, the version I posted for you the other day is correct. I don't see any appreciable difference in your version which would make it any more "right" than what I've posted. Some of the others were broken, yes, but nobody has ever shown mine to be broken. In short, before you say all the others are wrong, please prove they are wrong, mine in particular.
a6m1n0 Posted September 24, 2006 Author Posted September 24, 2006 (edited) My apologies if I gave you the impression your code was wrong or broken, but I never stated that the your RC4 UDF or the others available here were 'wrong' or 'broken'. I stated they were incompatible with the implementations that I use in other programming languages. I am no expert in cryptography just a user of the methods. However, the scope of my current project require using AutoIt to interface with my existing code base, some of which was acquired from the links in my first post. Otherwise your RC4 implementation as well as the others offered here seem to work fine within AutoIt3 itself. EDIT: I planned to post a 'thank you' directly after posting this with a thorough explanation but was called away from my computer before I had a chance. So, Thank you for digging up your old code and posting it -- if I weren't in need of interfacing with RC4 implementations I already have then it would have been fine I am certain. Edited September 24, 2006 by a6m1n0
Valik Posted September 24, 2006 Posted September 24, 2006 My code produces the same output as your code does with your example.
RazerM Posted September 24, 2006 Posted September 24, 2006 I also have an RC4 Encryption UDF, check my signature. It works perfectly as far as i know. 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.
a6m1n0 Posted September 24, 2006 Author Posted September 24, 2006 (edited) Well I'll be damned. When you're wrong you are just wrong, and wrong I was, lol. I ran a test (attached) and it seems that I didn't do enough testing. But I have a good excuse. My first attempt using RC4 in AutoIt was _StingEncrypt. My second attempt was using RazerM's _StringEncryptRC4/_StringDecryptRC4 BUT I did not realize that the HEX conversion was called from within that UDF, and I was using it like _StringToHexEx(_StringEncryptRC4($mytext,$mypass)) and hence the assumed incompatibility. My third attempt was using Valik's script, and to be honest I can't remember what I was doing with it, but whatever it was it was not producing compatible results -- by this time it was early morning and I was to tired to worry about it deciding that I just needed to port it from something I knew worked. So, I stand corrected and apologies all around -- your script Valik, as well as your script RazerM, both work fine. I can at least say I learned a great deal about porting ASP VBScript to AutoIt3. The only bonus my UDF seems to have is that it is defined as one function instead of two, otherwise it produces the same results.RC4Test.au3 Edited September 24, 2006 by a6m1n0
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now