File Coverage

blib/lib/Crypt/CVS.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Crypt::CVS;
2             BEGIN {
3 1     1   23441 $Crypt::CVS::AUTHORITY = 'cpan:AVAR';
4             }
5             BEGIN {
6 1     1   17 $Crypt::CVS::VERSION = '0.03';
7             }
8              
9 1     1   10 use strict;
  1         2  
  1         38  
10 1     1   5 use warnings;
  1         3  
  1         32  
11 1     1   6 use base 'Exporter';
  1         2  
  1         580  
12              
13             our @EXPORT = ();
14             our @EXPORT_OK = qw(scramble descramble);
15             our %EXPORT_TAGS;
16             $EXPORT_TAGS{'all'} = \@EXPORT_OK;
17              
18             # This table is from src/scramble.c in the CVS source
19             our @SHIFTS = (
20             0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
21             16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
22             114,120, 53, 79, 96,109, 72,108, 70, 64, 76, 67,116, 74, 68, 87,
23             111, 52, 75,119, 49, 34, 82, 81, 95, 65,112, 86,118,110,122,105,
24             41, 57, 83, 43, 46,102, 40, 89, 38,103, 45, 50, 42,123, 91, 35,
25             125, 55, 54, 66,124,126, 59, 47, 92, 71,115, 78, 88,107,106, 56,
26             36,121,117,104,101,100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48,
27             58,113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85,223,
28             225,216,187,166,229,189,222,188,141,249,148,200,184,136,248,190,
29             199,170,181,204,138,232,218,183,255,234,220,247,213,203,226,193,
30             174,172,228,252,217,201,131,230,197,211,145,238,161,179,160,212,
31             207,221,254,173,202,146,224,151,140,196,205,130,135,133,143,246,
32             192,159,244,239,185,168,215,144,139,165,180,157,147,186,214,176,
33             227,231,219,169,175,156,206,198,129,164,150,210,154,177,134,127,
34             182,128,158,208,162,132,167,209,149,241,153,251,237,236,171,195,
35             243,233,253,240,194,250,191,155,142,137,245,235,163,242,178,152
36             );
37              
38             sub scramble
39             {
40 1257     1257 0 1627919 my ($str) = @_;
41 1257         5425 my @str = unpack "C*", $str;
42 1257         5640 my $ret = join '', map { chr $SHIFTS[$_] } @str;
  10840         21883  
43 1257         5144 return "A$ret";
44             }
45              
46             sub descramble
47             {
48 1062     1062 0 26544 my ($str) = @_;
49              
50             # This should never happen, the same password format (A) has been
51             # used by CVS since the beginning of time
52             {
53 1062         1278 my $fmt = substr($str, 0, 1);
  1062         2058  
54 1062 100       3795 die "invalid password format `$fmt'" unless $fmt eq 'A';
55             }
56              
57 1001         3374 my @str = unpack "C*", substr($str, 1);
58 1001         1797 my $ret = join '', map { chr $SHIFTS[$_] } @str;
  10572         20889  
59 1001         4430 return $ret;
60             }
61              
62             1;
63              
64             __END__