in reply to RC4 cipher performance
You shell out to get the date? Change
to$dt=`/cygwin/bin/date`; chomp $dt;
$dt=localtime;
Searching for a hi-bit character
$clen = length($ucrypt); @uchar = split(//,$ucrypt); for($i=0; $i<($clen); $i++) { $val = ord($uchar[$i]); if($val>127) { $SKIP=1; last; } }
can be done much cleaner.
while ($ucrypt =~ /(.)/g) { if (ord($1)>127) { $SKIP=1; last; } }
But it's probably faster with a regexp.
$SKIP = $ucrypt =~ /[\x80-\xFF]/;
And then there's the issue of checking the same thing ($val > 127 and $SKIP == 0) in two different locations.
my $plaintext; my $ct; my $key = 'A'; while ( 1 ) { $plaintext = RC4($key, $ciphertext); if ( $plaintext !~ /[\x80-\xFF]/ ) { print "matched using key:$key \n"; print "$plaintext \n"; } if ( ++$ct == 10000 ) { $dt = localtime; print "[$dt] count: $ct key: $key \n"; $ct = 0; } $key++; }
I don't expect any of these changes to have a significant on the speed. (Explanation follows.)
I would appreciate any suggestions and advice and would be really happy to prove my code is the problem and not perl.
The fact that a scalar can hold a number of data types is a great strength, but it has some effect on performance. Unfortunately, Crypt::RC4 does heavy number crunching, which means a lot of operations and a lot of variable usage, which means a lot of overhead. Another performance cost is the conversion from the C array of char you pass to RC4 to a Perl array of integers, and back to a C array of char.
Unless PDL is used, heavy number crunching is not where Perl will be at its best. That's why most of the Crypt:: modules are actually written in C. Crypt::RC4 is Perl all the way.
He advises that this is a clear example of compiled code over interpreted code.
Perl is compiled, just not into machine code. Even if it was, it wouldn't be any faster. It's not "interpreted vs compiled" that affects the speed, it's the extra baggage needed to support Perl's features.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RC4 cipher performance
by jaiello (Novice) on Nov 15, 2008 at 23:30 UTC | |
by ikegami (Patriarch) on Nov 16, 2008 at 02:03 UTC |