This program brute force decodes an RC4 encrypted message. On my Core2Quad 2.4ghz, it processed about 2000 iterations a second. A C programmer has his own similar brute force code that processes about 300,000 iterations a second. He advises that this is a clear example of compiled code over interpreted code. Since I learned most my perl from perlmonks, web sites and books, this is the most optimized code I could manage.
It could be that the RC4 algorithm is much slower than the C lib or maybe there is some glaring element of my code that can be optimized.
I would appreciate any suggestions and advice and would be really happy to prove my code is the problem and not perl.
Thanks!
#!/perl/bin/perl
use Crypt::RC4;
$data1="C5C444220AD6FB08972792318300CC703814513EE013AF97B94FF9ACF23F9C
+8F0E748C04B2E18BB5A1B491BB73E23EC9A4233B9BCDE4854FD03DCBAC4B3E9EA00F5
+BF7A3A119B0FF2E66C9DD96E7F4F0972959082601AA5DD202DFB0
5039CA4FDC280517E244353690C0DE1A";
$foo1=pack('H*',"$data1");
$dt=`/cygwin/bin/date`;
chomp $dt;
print "$dt Start \n";
$key=A;
while ( 1 ){
$SKIP=0;
$ct++;
$ucrypt=RC4($key,$foo1);
$clen = length($ucrypt);
@uchar = split(//,$ucrypt);
for($i=0; $i<($clen); $i++) {
$val = ord($uchar[$i]);
if($val>127) {
$SKIP=1;
last;
}
}
if ( $ct == 10000 ){
$dt=`/cygwin/bin/date`;
chomp $dt;
print "$dt count $ct key: $key \n";
$ct=0;
}
if ($SKIP == 0 ){
print "matched using key:$key \n";
print "$ucrypt \n";
}
$key++;
}
exit;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.