#!/usr/bin/perl
###########################################################################
# Small tool to encode/decode base64 Strings from commandline             #
# Copyright (C) 2006 Benedikt Hallinger <b.hallinger@skyforcesystems.de>  #
#                                                                         #
# This program is free software; you can redistribute it and/or modify    #
# it under the terms of the GNU General Public License as published by    #
# the Free Software Foundation, version 2 of the License.                 #
#                                                                         #
# This program is distributed in the hope that it will be useful,         #
# but WITHOUT ANY WARRANTY; without even the implied warranty of          #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           #
# GNU General Public License for more details.                            #
#                                                                         #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             #
###########################################################################

use strict;
use MIME::Base64;

if(@ARGV[0] eq '-h' || ! @ARGV[0]){
        print "Decode/encode strings from/to base64 using commandline as input (happy piping!)\n";
        print "Usage: some_other_program | $0 -d\n";
	print "   or: some_other_program | $0 -e\n";
        print "   or: $0 -h\n";
	exit(1);
}


if(@ARGV[0] eq '-d'){
	while(defined(my $input = <STDIN>)) { print decode_base64($input) }
}elsif(@ARGV[0] eq '-e'){
	while(defined(my $input = <STDIN>)) { print encode_base64($input) }
}else{
	print "Parameter @ARGV[0] not understood. See $0 -h for more informaton.\n";
}
