Profile of Crypt/RC4.pm

← Index
NYTProf Performance Profile «line view»
For t/bug-md-11.t
Run on Fri Mar 8 13:27:24 2024
Reported on Fri Mar 8 13:30:23 2024

Filename | /home/micha/.plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/Crypt/RC4.pm
Statements | Executed 10 statements in 298µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 9µs | 11µs | Crypt::RC4::::BEGIN@15Crypt::RC4::BEGIN@15
1 | 1 | 1 | 3µs | 27µs | Crypt::RC4::::BEGIN@16Crypt::RC4::BEGIN@16
0 | 0 | 0 | 0s | 0s | Crypt::RC4::::RC4Crypt::RC4::RC4
0 | 0 | 0 | 0s | 0s | Crypt::RC4::::SetupCrypt::RC4::Setup
0 | 0 | 0 | 0s | 0s | Crypt::RC4::::newCrypt::RC4::new

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | #--------------------------------------------------------------------#
2 |  |  |  |  | # Crypt::RC4
3 |  |  |  |  | # Date Written: 07-Jun-2000 04:15:55 PM
4 |  |  |  |  | # Last Modified: 13-Dec-2001 03:33:49 PM
5 |  |  |  |  | # Author: Kurt Kincaid (sifukurt@yahoo.com)
6 |  |  |  |  | # Copyright (c) 2001, Kurt Kincaid
7 |  |  |  |  | # All Rights Reserved.
8 |  |  |  |  | #
9 |  |  |  |  | # This is free software and may be modified and/or
10 |  |  |  |  | # redistributed under the same terms as Perl itself.
11 |  |  |  |  | #--------------------------------------------------------------------#
12 |  |  |  |  |
13 |  |  |  |  | package Crypt::RC4;
14 |  |  |  |  |
15 | 2 | 20µs | 2 | 12µs | # spent 11µs (9+1) within Crypt::RC4::BEGIN@15 which was called: # once (9µs+1µs) by Spreadsheet::ParseExcel::BEGIN@26 at line 15 use strict; # spent 11µs making 1 call to Crypt::RC4::BEGIN@15 # spent 1µs making 1 call to strict::import
16 | 2 | 269µs | 2 | 51µs | # spent 27µs (3+24) within Crypt::RC4::BEGIN@16 which was called: # once (3µs+24µs) by Spreadsheet::ParseExcel::BEGIN@26 at line 16 use vars qw( $VERSION @ISA @EXPORT $MAX_CHUNK_SIZE ); # spent 27µs making 1 call to Crypt::RC4::BEGIN@16 # spent 24µs making 1 call to vars::import
17 |  |  |  |  |
18 | 1 | 300ns |  |  | $MAX_CHUNK_SIZE = 1024 unless $MAX_CHUNK_SIZE;
19 |  |  |  |  |
20 | 1 | 300ns |  |  | require Exporter;
21 |  |  |  |  |
22 | 1 | 5µs |  |  | @ISA = qw(Exporter);
23 | 1 | 300ns |  |  | @EXPORT = qw(RC4);
24 | 1 | 100ns |  |  | $VERSION = '2.02';
25 |  |  |  |  |
26 |  |  |  |  | sub new {
27 |  |  |  |  | my ( $class, $key ) = @_;
28 |  |  |  |  | my $self = bless {}, $class;
29 |  |  |  |  | $self->{state} = Setup( $key );
30 |  |  |  |  | $self->{x} = 0;
31 |  |  |  |  | $self->{y} = 0;
32 |  |  |  |  | $self;
33 |  |  |  |  | }
34 |  |  |  |  |
35 |  |  |  |  | sub RC4 {
36 |  |  |  |  | my $self;
37 |  |  |  |  | my( @state, $x, $y );
38 |  |  |  |  | if ( ref $_[0] ) {
39 |  |  |  |  | $self = shift;
40 |  |  |  |  | @state = @{ $self->{state} };
41 |  |  |  |  | $x = $self->{x};
42 |  |  |  |  | $y = $self->{y};
43 |  |  |  |  | } else {
44 |  |  |  |  | @state = Setup( shift );
45 |  |  |  |  | $x = $y = 0;
46 |  |  |  |  | }
47 |  |  |  |  | my $message = shift;
48 |  |  |  |  | my $num_pieces = do {
49 |  |  |  |  | my $num = length($message) / $MAX_CHUNK_SIZE;
50 |  |  |  |  | my $int = int $num;
51 |  |  |  |  | $int == $num ? $int : $int+1;
52 |  |  |  |  | };
53 |  |  |  |  | for my $piece ( 0..$num_pieces - 1 ) {
54 |  |  |  |  | my @message = unpack "C*", substr($message, $piece * $MAX_CHUNK_SIZE, $MAX_CHUNK_SIZE);
55 |  |  |  |  | for ( @message ) {
56 |  |  |  |  | $x = 0 if ++$x > 255;
57 |  |  |  |  | $y -= 256 if ($y += $state[$x]) > 255;
58 |  |  |  |  | @state[$x, $y] = @state[$y, $x];
59 |  |  |  |  | $_ ^= $state[( $state[$x] + $state[$y] ) % 256];
60 |  |  |  |  | }
61 |  |  |  |  | substr($message, $piece * $MAX_CHUNK_SIZE, $MAX_CHUNK_SIZE) = pack "C*", @message;
62 |  |  |  |  | }
63 |  |  |  |  | if ($self) {
64 |  |  |  |  | $self->{state} = \@state;
65 |  |  |  |  | $self->{x} = $x;
66 |  |  |  |  | $self->{y} = $y;
67 |  |  |  |  | }
68 |  |  |  |  | $message;
69 |  |  |  |  | }
70 |  |  |  |  |
71 |  |  |  |  | sub Setup {
72 |  |  |  |  | my @k = unpack( 'C*', shift );
73 |  |  |  |  | my @state = 0..255;
74 |  |  |  |  | my $y = 0;
75 |  |  |  |  | for my $x (0..255) {
76 |  |  |  |  | $y = ( $k[$x % @k] + $state[$x] + $y ) % 256;
77 |  |  |  |  | @state[$x, $y] = @state[$y, $x];
78 |  |  |  |  | }
79 |  |  |  |  | wantarray ? @state : \@state;
80 |  |  |  |  | }
81 |  |  |  |  |
82 |  |  |  |  |
83 | 1 | 3µs |  |  | 1;
84 |  |  |  |  | __END__