decrypt/encrypt

filter: Statementstmt 90.4% 38 / 42 Branchbran 45.4% 10 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 76.1% 51 / 67 CC 1 SCAR 0.0
CC
1
Cov
75%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Filter/cpp.pm ↑ Summary blib/lib/Filter/Util/Exec.pm »
1 #!perl
2 1 require 5.002 ;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 use vars qw($XOR $BLOCKSIZE $HEADERSIZE $CRYPT_MAGIC_1 $CRYPT_MAGIC_2
8 $size $mode $line $Fingerprint $file $block
9 1 ▶ ) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 $XOR = 'Perl' ;
12 1 $BLOCKSIZE = length $XOR ;
13 1 $HEADERSIZE = 2 ;
14 1 $CRYPT_MAGIC_1 = 0xff ;
15 1 $CRYPT_MAGIC_2 = 0x00 ;
16  
17 1 $Fingerprint = pack ("C*", $CRYPT_MAGIC_1, $CRYPT_MAGIC_2) ;
18  
19 1 ▶die "Usage: encrypt file...\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 1 1
20 unless @ARGV ;
21  
22 # Loop throught each file in turn.
23 1 foreach $file (@ARGV)
24 {
25  
26 1 ▶ if (! -T $file)
Branch: 1 branch
BranchTrueFalseTotal
unless (-T $main::file) 0 1 1
27 {
28 0 ▶ print "Skipping directory $file\n" if -d $file ;
Branch: 1 branch
BranchTrueFalseTotal
if -d $main::file 0 0 0
29 0 ▶ print "Skipping non-text $file\n" if ! -d $file ;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $main::file 0 0 0
30 0 next ;
31 }
32  
33 1 ▶ open (F, "<", $file) or die "Cannot open $file: $!\n" ;
Branch: 1 branch
BranchTrueFalseTotal
open F, "<", $main::file or die "Cannot open $main::file: $!\n" 0 1 1
34 1 binmode F;
35 1 ▶ open (O, ">", ${file}.".pe") or die "Cannot open ${file}.pe: $!\n" ;
Branch: 1 branch
BranchTrueFalseTotal
open O, ">", $main::file . '.pe' or die "Cannot open $main::file.pe: $!\n" 0 1 1
36 1 binmode O;
37  
38 # Get the mode
39 1 $mode = (stat F)[2] ;
40  
41 # Check for "#!perl" line
42 1 $line = <F> ;
43  
44 1 ▶ if ( $line =~ /^#!/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($main::line =~ /^#!/) { } 0 1 1
45 0 { print O $line }
46 else
47 1 { seek F, 0, 0 }
48  
49 1 print O "use Filter::decrypt ;\n" ;
50 1 print O $Fingerprint ;
51  
52  
53 1 $block = '';
54 1 ▶ while ($size = read(F, $block, $BLOCKSIZE) )
Branch: 1 branch
BranchTrueFalseTotal
if ($main::size = read(F, $main::block, $main::BLOCKSIZE)) 64 1 65
55 {
56 64 print O ($block ^ substr($XOR, 0, length $block)) ;
57 }
58  
59 1 close F ;
60 1 close O ;
61  
62 1 ▶ unlink ($file)
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::file or die "Could not remove '$main::file': $!\n" 0 1 1
63 or die "Could not remove '$file': $!\n" ;
64  
65 1 ▶ rename ("${file}.pe", $file)
Branch: 1 branch
BranchTrueFalseTotal
rename "$main::file.pe", $main::file or die "Could not rename $main::file.pe to $main::file: $!\n" 0 1 1
66 or die "Could not rename $file.pe to $file: $!\n" ;
67  
68 1 ▶ chmod $mode, $file unless $^O eq 'MSWin32' ;
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "MSWin32" 1 0 1
69  
70 1 print "encrypted $file\n" ;
71 }
72  
« blib/lib/Filter/cpp.pm ↑ Summary blib/lib/Filter/Util/Exec.pm »