in reply to RC4 cipher performance

  1. You don't need a loop to do character matching, and
  2. You don't need to call an external program to get the current date.

Try something like this:

#!/perl/bin/perl use warnings; use strict; use Crypt::RC4; my $foo1 = pack 'H*', 'C5C444220AD6FB08972792318300CC703814513EE013AF9 +7B94FF9ACF23F9C8F0E748C04B2E18BB5A1B491BB73E23EC9A4233B9BCDE4854FD03D +CBAC4B3E9EA00F5BF7A3A119B0FF2E66C9DD96E7F4F0972959082601AA5DD202DFB05 +039CA4FDC280517E244353690C0DE1A'; my $dt = localtime; print "$dt Start\n"; my $key = 'A'; my $ct; while ( 1 ) { my $ucrypt = RC4( $key, $foo1 ); if ( ++$ct == 10_000 ) { $dt = localtime; print "$dt count $ct key: $key\n"; $ct = 0; } if ( $ucrypt !~ /[\x80-\xFF]/ ) { print "matched using key:$key\n$ucrypt\n"; } $key++; }

Replies are listed 'Best First'.
Re^2: RC4 cipher performance
by jaiello (Novice) on Nov 15, 2008 at 23:39 UTC
    I realize I did not need to shell for date. I know that I should have used localtime. I was an artifact of the old program I started with.

    I am evaluating you method of using a regex to look at the decrypted string. I used a loop to bomb out as soon as I found a character with the MSB bit set. I am not sure yet if this regex does the same. -- Actually, I just verified that is does work and is slightly faster by 10%.

    This code was about the same performance as mine. I have believed from the start that the RC4 mod will be the bottleneck even thou my code was a bit simple.

    Thanks.
      I used a loop to bomb out as soon as I found a character with the MSB bit set. I am not sure yet if this regex does the same.

      The regular expression matches a single character so as soon as that character is found it will stop searching.