There were multiple errors in your code (below a cleaned-up version which will work, though some more improvements could be made). The most common one was the lack of predeclaring variables while running under use strict.
A few more notes:
- When debugging warnings/errors under Perl it is helpful to just go at it one error at a time. For example, in this case find out why you're getting the warning Global symbol "%opts" requires explicit package name (answer: because you need to declare it before use when running under "use strict"), fix that, run the script again and fix the next error that shows up. This method is best because subsequent warnings/errors can be offshoots of the first one and may be fixed with the first change despite looking entirely unrelated.
- Congratulations on using "use strict"! This is a good idea
and in this case it would eventually have led you to discover that you misspelled $ciphertext as $chipertext twice.(Update: no it wouldn't, since you consistently spelled it the same/wrong way all the time, thanks serf.) Keep on doing that (using strict, not misspelling variable names ;-)
- If you feel overwhelmed by the error messages you're getting, take a step back and don't "use diagnostics". diagnostics can be very helpful and is verbose where normal errors are terse, but it can also be a bit too verbose and often it is more helpful to see only what the error is instead of what it may signify. I'm definitely not recommending you should eschew diagnostics altogether, but you should use both approaches when debugging.
use warnings; can also help you identify problems in your code.Update: Doh!You'd already specified "-w". Thanks to wfsp for pointing that out.
Lastly, just a question out of curiosity, why are you using Skipjack?
#! /usr/bin/perl -w
use diagnostics;
use strict;
use Getopt::Std;
use Crypt::CBC;
my %opts;
getopt( 'kio', \%opts );
my $cipher = Crypt::CBC->new({
key => $opts{"k"},
cipher => 'Skipjack',
});
my $INFILE = $opts{"i"};
my $OUTFILE = $opts{"o"};
open my $in, "<", $INFILE or die "can't open $INFILE: $!";
open my $out, ">", $OUTFILE or die "can't open $OUTFILE: $!";
local $/=undef;
my $plaintext = (<$in>);
my $ciphertext = $cipher->encrypt($plaintext);
print {$out} $ciphertext;
close $out;
close $in;
There are ten types of people: those that understand binary and those that don't.