Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Skipjack Encryption

by serf (Chaplain)
on Jan 21, 2006 at 11:28 UTC ( #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 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.

Comment on Re: Skipjack Encryption
Select or Download Code
Reaped: Re^2: Skipjack Encryption
by NodeReaper (Curate) on Jan 21, 2006 at 22:26 UTC
      Hi brittojs,

      There is a possibility that it was by mistake, but here all you did was reply to my post, copy my code verbatim from the [download] link, and then paste it into the reply box (at which point you knew what you were doing well enough to add code tags around it - which makes it look like it was intentional and not an accident) then preview it and submit it.

      By copying and pasting the code verbatim, minus the comments, (not making any changes) you managed to pick up a few (somewhat fickle) XP (in this case 9 in 12 hours) thanks to people who didn't read what they were voting on.

      You also did the same thing with ikegami's code in Reaped: Re^2: how to crypt and decrypt password from 4 to 15 characters in length

      I appreciate that these two nodes constitute the only positive XP that you have at the moment, but it was "aquired", not earned.

      If these two nodes *were* posted by mistake could you please update the nodes and remove our code.

      I'm an open source advocate, and am 100% for code re-use but taking other people's code and passing it off as your own without giving credit is plagerism.

      .oO(should we be putting copyright messages in the code we post on PM?)

      In the off-chance that you just intended to add minor improvements to our code snippets (which I'm all for!) could you please go back and update your posts to do so.

      There's no need to re-post our code in full (if it works). If you're only making a minor change and not re-writing most of the program then just post the modified code blocks you've improved by themselves (with some comments), otherwise it's hard for people to see what is different.

      I downloaded my and your posts here and ran diff on the two files to find the code was unchanged - because I certainly didn't suspect at first (like the other monks who ++ed it) that it was my code I was reading in your post!

      Thank you.

        should we be putting copyright messages in the code we post on PM?

        Under most jurisdictions all original code you post (here or anywhere else) is already under your copyright unless you explicitly put it into the public domain (I think only xdg does that in his .sig but may be wrong there). I don't see an explicit copyright statement changing that in any way (IANAL though).

        There are ten types of people: those that understand binary and those that don't.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2015-07-06 19:18 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (81 votes), past polls