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; }

In reply to Re^2: RC4 cipher performance by juster
in thread RC4 cipher performance by jaiello

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.