Debian Codegraph @

decrypt/decr

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 binmode F;
41
42 # skip the #! line
43 $a = <F> ;
44 if ($a =~ /^#!/)
45 {
46 $sharp_bang = $a ;
47 $a = <F> ;
48 }
49
50 # skip "use decrypt;" line
51 die "No use $module_name in $file\n"
52 unless $a =~ /use\s+$module_name\s*;/ ;
53
54 read(F, $f, length($Fingerprint)) || die "Cannot read from $file: $!\n" ;
55 (print "skipping file '$file': not encrypted\n"), next
56 unless $f eq $Fingerprint ;
57
58 print "decrypting $file to $file.pd\n" ;
59 open (O, ">", ${file}.".pd") || die "Cannot open ${file}.pd: $!\n" ;
60 binmode O;
61 print O $sharp_bang if $sharp_bang ;
62 while ($size = read(F, $block, $BLOCKSIZE) )
63 {
64 print O ($block ^ substr($XOR, 0, $size)) ;
65 }
66
67
68 close F ;
69 close O ;
70
71 }
72