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.


In reply to Re: Skipjack Encryption by serf
in thread Skipjack Encryption by shadowoflinux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.