#!/usr/bin/perl
# Filename: base64.pl
# Encodes/Decodes Base-64 text
# Requires the MIME::Base64 module
# Written specifically for HPYN 2nd Ed.
# by FWL 01.07.02
# Use the MIME module for encoding/decoding Base-64 strings
use MIME::Base64;
# Simple input validation
sub validate() {
if (scalar(@ARGV) < 2) {
print “Error: You did not specify input correctly!\n”;
print “To encode data use ./base64.pl e \“String to
Encode\”\n”;
print “To decode data use ./base64.pl d \“String to
Decode\”\n”;
exit;
}
}
validate();
$intext=$ARGV[1];
if ($ARGV[0] eq “e”) { # encode text
$outtext=encode_base64($intext);
print “Encoded $intext to $outtext”;
} elsif ($ARGV[0] eq “d”) { # decode text
$outtext=decode_base64($intext);
print “Decoded $intext to $outtext”;
} else { # No encode/decode information given!
print “To encode or decode? That is the question.”;
exit;
А вот пример отчета работы программы.
$ ./base64.pl e “Secret Password”
Encoded Secret Password to U2VjcmV0IFBhc3N3b3Jk
$ ./base64.pl d “U2VjcmV0IFBhc3N3b3Jk”
Decoded U2VjcmV0IFBhc3N3b3Jk to Secret Password