kanabrian has asked for the wisdom of the Perl Monks concerning the following question:

I need a code to encrypt and decrypt file. It need not to be complicated. If anyone has written it, please post.

Replies are listed 'Best First'.
Re: encryption
by vek (Prior) on Dec 11, 2002 at 22:49 UTC
    Take MZSanford's advice kanabrian, the CPAN is your friend. Use it, often. It's amazing what you'll find (and learn) by doing a little research before coming here.

    Now that I've got that off my chest, I personally use Crypt::GPG so that I can take advantage of the rather spiffy GnuPG.

    -- vek --
Re: encryption
by zentara (Cardinal) on Dec 12, 2002 at 14:28 UTC
    Here's about as simple as you get, except for rot-13.
    #!/usr/bin/perl use Crypt::RC4; $passphrase = "rumpelstiltskin"; open (FH,"< /etc/passwd") or die $!; while(<FH>){ $file .= $_ } close FH; $plaintext= $file; $encrypted = RC4( $passphrase, $plaintext ); $decrypt = RC4( $passphrase, $encrypted ); print "$plaintext\n$encrypted\n$decrypt\n";
Re: encryption
by MZSanford (Curate) on Dec 11, 2002 at 21:59 UTC
    Check the Crypt:: namespace on CPAN. Also, as friendly advice, i downvoted you because this question shows no work on your part.
    from the frivolous to the serious
      i downvoted you because this question shows no work on your part.

      A few thoughts:

      • It is presumptuous to assume that everyone knows about CPAN.
      • Even if he did know about CPAN, he could have run into other problems (search was down, etc.) or he was just looking for opinions on the Crypt::* modules, which brings us to our next point.
      • When reading a post, remember english isn't everyone's first language. Just because a post seems poorly worded to you doesn't mean the poster was lazy.
      • I like short, to the point questions. Five paragraphs of irrelevant background information just distracts from the actual question.

      As for the original question: see derby's Getting Started with GnuPG and GPG and The GNU Privacy Handbook.

        • Point taken. i did provide a link.
        • Were the question "How do i use Crypt::Blah", i would have had no problem.
        • I don't care if things are mis-spelled, or in poor grammer ... whatever your first language. I do not downvote for that.
        • I like short, but i also like to know i am not doing someone homework.

        I see alot of people in the CB wondering why they got downvoted for this or that, and i thought it was friendly to let people know, so they don't wonder. <sarcasm> I see i was mistaken ... i will downvote as an Anonymous Coward from here on out. <sarcasm>


        from the frivolous to the serious