in reply to Re: RC4 cipher performance
in thread RC4 cipher performance
I thought your suggestion for Inline C was good and I used it as an excuse to try it for the first time.
Using the openssl library that came with my linux this solution gets around 190k calcs/sec on my Celeron M 1.3Ghz and finds the key in 6 seconds! I'm guessing cygwin has a similar library installed but I'm not sure what different Config => LIBS or #include would be needed.
In your face, C! I mean, err... thanks for the help.
use POSIX qw/strftime/; use Inline C => Config => LIBS => '-lssl'; use Inline C; use Time::HiRes qw/clock/; use strict; use warnings; my $start = clock(); print strftime "%T Start\n", localtime(time); my $key='A'; my $count = 1; while(1) { if(check_key( $key, length $key )) { print strftime "%T cracked! key: $key\n", localtime(time); last; } ++$count; ++$key; } print "Calcs per second: ", int($count / (clock()-$start)), "\n"; __DATA__ __C__ #include <openssl/rc4.h>; #define DATALEN 108 unsigned char *crackme = "\xC5\xC4\x44\x22\x0A\xD6\xFB\x08\x97\x27\x92 +\x31\x83" "\x00\xCC\x70\x38\x14\x51\x3E\xE0\x13\xAF\x97 +\xB9\x4F" "\xF9\xAC\xF2\x3F\x9C\x8F\x0E\x74\x8C\x04\xB2 +\xE1\x8B" "\xB5\xA1\xB4\x91\xBB\x73\xE2\x3E\xC9\xA4\x23 +\x3B\x9B" "\xCD\xE4\x85\x4F\xD0\x3D\xCB\xAC\x4B\x3E\x9E +\xA0\x0F" "\x5B\xF7\xA3\xA1\x19\xB0\xFF\x2E\x66\xC9\xDD +\x96\xE7" "\xF4\xF0\x97\x29\x59\x08\x26\x01\xAA\x5D\xD2 +\x02\xDF" "\xB0\x50\x39\xCA\x4F\xDC\x28\x05\x17\xE2\x44 +\x35\x36" "\x90\xC0\xDE\x1A"; int check_key ( unsigned char *keystr, int keylen ) { RC4_KEY key; int i; unsigned char buffer[DATALEN]; RC4_set_key( &key, keylen, keystr ); RC4( &key, DATALEN, crackme, buffer ); for( i=0; i<DATALEN; ++i ) { if( buffer[i] & ~0x7F ) return 0; } return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: RC4 cipher performance
by Anonymous Monk on Nov 17, 2008 at 04:35 UTC | |
by juster (Friar) on Nov 17, 2008 at 08:39 UTC |