#!/afs/athena/contrib/perl/p
#
$st = 256;
undef($/);
$line = (<>);
@chars = split(//, $line);
foreach $k (@chars){
    $bits .= unpack('B8', $k);
}

for $printthis (split(/(.........)/, $bits)){
    if($printthis){
#	print("Nine bits: $printthis\n");
	$val = unpack('C', pack('B*', $printthis));
	$val = 2*$val + substr($printthis, 8);
	push(@in, $val);
#	print("$val\n");
    }
}

foreach $v (@in){
    $vc = pack('c', $v);
    if(defined($dict{$v})){
	print("Recognized: \"$dict{$v}\"\n");
	$w = $w.$dict{$v};
    }
    else{
	print $w;
	if($w){
	    print("$st is really --$w$vc--\n");
	    $dict{$st}=$w.$vc;
	    $st++;
	}
	$w=$vc;
    }
}

__END__


foreach $k (@chars){
    if(defined($dict{$w.$k})){
#	print("$w$k found in dictionary.  Restting w to $w$k\n");
	$w = $w.$k;
    }
    else{
#	print("$w$k not in dictionary.  Printing -$dict{$w}-\n");
#	print("Adding table entry as $st and setting w=$k;\n");
#	if($dict{$w}){$output .=$dict{$w};}
#	else{$output.=$w;}
	if($dict{$w} eq ''){push(@out, ord($w)) if $w;}
	else{push(@out, $dict{$w});}
	if($w){
	    $dict{$w.$k}=$st;
#	    print(";$dict{$w.$k}==$w$k\n");
	    $st++;
	}
	$w=$k;
    }
}
#print("Translating\n");
foreach $sym (@out){
#    print $sym."\n";
    $bitst = unpack('B16', pack('n', $sym));
    $bits .= substr($bitst, 6);
}
#print("Bits is complete\n");
$bits=$bits.'00000000';
#print(substr($bits, 0, 22));
for $printthis (split(/(........)/, $bits)){
#    print("\nTrying $printthis:");
    print pack('B8', $printthis) if $printthis;
}
__END__





