Add the following packages libalgorithm-diff-perl libspiffy-perl libtext-diff-perl...
[pkg-perl] / deb-src / libfilter-perl / libfilter-perl-1.34 / decrypt / decr
1 #!/usr/local/bin/perl
2
3 # This script will decrypt a Perl script that has been encrypted using the
4 # "encrypt" script. It cannot decrypt any other kind of encrypted Perl script.
5 #
6 # Usage is decr file...
7 #
8
9 use strict;
10 use warnings;
11
12 use vars qw($XOR $BLOCKSIZE $HEADERSIZE $CRYPT_MAGIC_1 $CRYPT_MAGIC_2
13             $size $mode $line $Fingerprint $file $block $sharp_bang $f
14            ) ;   
15 $XOR             = 'Perl' ;
16 $BLOCKSIZE       = length $XOR ;
17 $HEADERSIZE      = 2 ;
18 $CRYPT_MAGIC_1   = 0xff ;
19 $CRYPT_MAGIC_2   = 0x00 ;
20 my $Version         = 1 ;
21 my $module_name     = 'Filter::decrypt' ;
22
23 my $Fingerprint     = pack ("C*", $CRYPT_MAGIC_1, $CRYPT_MAGIC_2) ;
24
25 die "Usage: decrypt file...\n"
26   unless @ARGV ;
27
28
29 # Loop through each file in turn.
30 foreach $file (@ARGV)
31 {
32     if (! -f $file)
33     {
34         print "Skipping directory $file\n" if -d $file ;
35         #print "Skipping strange file $file\n" if ! -d $file ;
36         next ;
37     }
38
39     open (F, "<$file") || die "Cannot open $file: $!\n" ;
40
41     # skip the #! line
42     $a = <F> ;
43     if ($a =~ /^#!/)
44     {
45         $sharp_bang = $a ;
46         $a = <F> ;
47     }
48
49     # skip "use decrypt;" line
50     die "No use $module_name in $file\n"
51         unless $a =~ /use\s+$module_name\s*;/ ;
52
53     read(F, $f, length($Fingerprint)) || die "Cannot read from $file: $!\n" ;
54     (print "skipping file '$file': not encrypted\n"), next
55         unless $f eq $Fingerprint ;
56
57     print "decrypting $file to $file.pd\n" ;
58     open (O, ">${file}.pd") || die "Cannot open ${file}.pd: $!\n" ;
59     print O $sharp_bang if $sharp_bang ;
60     while ($size = read(F, $block, $BLOCKSIZE) )
61     {
62         print O ($block ^ substr($XOR, 0, $size)) ;
63     }
64
65
66     close F ;
67     close O ;
68
69 }
70