Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Skipjack Encryption

by serf (Chaplain)
on Jan 21, 2006 at 11:28 UTC ( [id://524648]=note: print w/replies, xml ) Need Help??


in reply to Skipjack Encryption

That's not "an" error message, that's a whole string of error messages. The best thing you can do is take them one at a time, figure out what is causing them and fix them - they're there to help you :o)

This warning that Perl gave you said exactly what I thought to tell you first:

(F) You've said "use strict vars", which indicates that all variables must either be lexically scoped (using "my"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::").
So you need to add my where appropriate.

Next thing, when you are accessing the %opts hash by keyname you use $opts{"i"} not %opts{"i"}

That's also not a valid way of using open or read. (read the linked pages to find out how - the perldoc pages have good example code which you can copy)

You will find that the manual page for Crypt::CBC gives you example code of how to read in a file and process it with that module - all you needed to do was take that code and add the functionality for writing it to a file and you'd have had a working program.

Try something like this:

#!/usr/bin/perl # # skipjack.pl - Skipjack encrypt a file. # use strict; use warnings; use diagnostics; use Getopt::Std; use Crypt::CBC; my %opts; getopt( 'kio', \%opts ); my ( $key, $infile, $outfile ) = ( $opts{"k"}, $opts{"i"}, $opts{"o"}); die "Usage: $0 -k KEY -i INFILE -o OUTFILE\n" unless($key && $infile && $outfile); my $cipher = Crypt::CBC->new( -key => $key, -cipher => 'Skipjack', ); $cipher->start('encrypting'); open (INFILE, $infile) || die "Can't read '$infile': $!\n"; open (OUTFILE, ">$outfile") || die "Can't write to '$outfile': $!\n"; while (read(INFILE,my $plaintext,1024)) { print OUTFILE $cipher->crypt($plaintext); } print OUTFILE $cipher->finish; close OUTFILE; close INFILE;
Read the manual pages for the functions you want to use carefully, and also try writing your codes in little chunks at a time and testing each chunk before you add the next bit - e.g. you've used Getopt::Std here to define the variables, but your script still wasn't working.

The script would have been simpler for you to read and debug if you had started off by hard-coding those variables into the script and forgetting about Getopt until the main functionality of the script was working.

I have the feeling you threw so much in at once that the torrent of error messages you got back would have phased you - and that's why you came asking for help rather than reading through what it was telling you and figuring out for yourself.

Please, before you ask more questions, have a good read through perldoc on the function you are trying to use, try it's examples in stand-alone code snippets till you're comfortable with how it works, and if you're still not getting what you're looking for - try googling for more pieces of code where people have used that.

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://524648]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found