#! /usr/bin/perl
#     convert ny's node address
#                                             Tomo.M(2006/06/06)

use W_node;

die "usage: $0 string\n" unless ($ARGV[0]);

if ($ARGV[0] =~ /^\@/ && $ARGV[1] =~ /[.:]/) {
    print check($ARGV[0], $ARGV[1]), "\n";
} elsif ($ARGV[0] =~ /^\@/) {
    print to_addr($ARGV[0]), "\n";
} else {
    print to_hash($ARGV[0]), "\n";
}
exit;

sub check {
    # test
    my ($hash, $addr) = @_;
    my ($key, $cksum);

    chomp($hash); chomp($addr);
    $hash =~ s/^\@(..)//;
    $cksum = hex($1);

    $str = pack('H*', $hash);
    my @v1 = unpack("C*", $addr);
    my @v2 = unpack("C*", $str);
    my $i = 0;
    foreach (@v1) {
        printf "$_, $v2[$i], %02x\n", ($_ ^ $v2[$i]);
        $i++;
    }
    print "\n";
}
