Perl quickie!


Junjun, this Perl quickie is for you! Enjoy!

#!/usr/bin/perl
# tr.pl: Implements encryption and decryption using the lame 1-letter forward
# substitution technique.
#
# Copyrights (C) 2005 Ayaz Ahmed Khan
#
# usage: perl tr.pl -e "plain-text"
# perl tr.pl "cipher"
#

## __CODE STARTS __
sub decrypt {
$_ = shift;
$_ =~ tr/a-zA-Z/b-zaB-ZA/;

print "$_ \n";
}

sub encrypt {
$_ = shift;
$_ =~ tr/a-zA-Z/za-yZA-Y/;

print "$_ \n";
}

sub usage {
print qq{Copyrights (C) 2005 Ayaz Ahmed Khan.
This is free software with ABSOLUTELY NO WARRANTY.

usage: $0 [OPTIONS] "PLAIN-TEXT/CIPHER"
-e Enable encryption mode.
-h Display help menu.

};
exit 0;
}

sub main {
if ($ARGV[0] eq "-h") {
usage;
}
elsif ($ARGV[0] eq "-e" || $ARGV[0] eq "-E") {
$_ = shift @ARGV;
decrypt @ARGV;
}
else {
encrypt @ARGV;
}
}

usage unless defined @ARGV;
main;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s