Hey I’m writing a program that uses an @INC hook to decrypt the real perl source from blowfish. I’m having a quite annoying problem that doesn’t show up using warnings or any of my standard tricks… Basically when I get to creating the new cipher object the loop skips to the next object in @INC without an error or anything…. I dont know what to do!
#!/usr/bin/perl -w
use strict;
use Crypt::CBC;
use File::Spec;
sub load_crypt {
my ($self, $filename) = @_;
print "Key?\n: ";
chomp(my $key = <STDIN>);
for my $prefix (@INC) {
my $buffer = undef;
my $cipher = Crypt::CBC->new( -key => $key, -cipher => 'Blowfish');
my $derp = undef;
$cipher ->start('decrypting');
open my $fh, '<', File::Spec->($prefix, "$filename.nc") or next;
while (read($fh,$buffer,1024)) {
$derp .= $cipher->crypt($buffer);
}
$derp .= $cipher->finish;
return ($fh, $derp);
}
}
BEGIN {
unshift @INC, \&load_crypt;
}
require 'gold.pl';
Also if I put the actual key in the initializing method it still fails
You’ve got a bunch of problems here. First of all, you’re using File::Spec wrong. Second, you’re returning a filehandle that’s already at end of file, and a string that isn’t a valid return value. (Also, I’d put the key prompt outside of the hook.)