#!/usr/bin/perl

$IP="";
$ALPHA="";
@JOIN=("K","L","M");

if ($#ARGV <= "0") { help(); }
while (@ARGV) {
	$_ = shift @ARGV;
	if ($_ eq "-e") { 
		$IP = shift @ARGV;
		IPtoALPHA();
		exit;
	}
	elsif ($_ eq "-d") {
		$ALPHA = shift @ARGV;
		ALPHAtoIP();
		exit;
	}
	else { help(); }
}

sub IPtoALPHA {
	print "$IP\n";
	@IPSPLIT = split(/\./,$IP,4);
	my $num = 0;
	foreach (@IPSPLIT) {
		$_ =~ tr/0-9/A-J/;
		$_ = join "", $_, @JOIN[$num];
		$num = $num + 1;
	}
	$ALPHA = join "", @IPSPLIT;
	print "$ALPHA\n";
}

sub ALPHAtoIP {
	print "$ALPHA\n";
	foreach (@JOIN) {
		$ALPHA =~ s/$_/\./;
	}
	$ALPHA =~ tr/A-J/0-9/;
	print "$ALPHA\n";
}

sub help{
	print "$0 -e ipaddr\n \tconvert IPADDR to APLHABET\n",
		"$0 -d alphabet\n \tconvert ALPHABET to IPADDR\n";
	exit;
}
