What do you think about a script that has two options; encrypt and view encrypted file? I created the script below to view my password file (normal text file) encrypted with Crypt::RC4 while on the road. I simply go to the terminal and type "./passwords.pl view <passwordfile> <password>" to see my passwords, in case i forgot them while away from home.

i know some operating systems store command history effectively caching my password as well, but i will change that in the future so that the script itself asks the password to use.

#!/usr/bin/perl -w use strict; use Crypt::RC4; print "usage: $0 [ crypt | view ] <filename> <password>\n" and exit un +less validateInput(@ARGV); my ($option, $file, $password) = @ARGV; my ($plaintext, $crypted, $decrypted); $plaintext = openFile($file); if ($option eq 'view') { $decrypted = RC4($password, $plaintext); print "$decrypted\n"; } elsif ($option eq 'crypt') { my $outputname = "$file" . '.enc'; $crypted = RC4($password, $plaintext); open FH, ">$outputname" or print "error: $!\n" and exit; print FH "$crypted"; close FH; print "$file encrypted with the given password\nnew filename $output +name\n"; } sub openFile { my $filename = shift; my $data; open FH, "<$filename" or print "error: $!\n" and exit; while (<FH>) { $data .= $_; } close FH; return $data; } sub validateInput { return undef unless @_ == 3; return undef unless ($_[0] =~ /view|crypt/); return undef unless (-e $_[1]); 1; }

In reply to Small encryption script by mellin

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.