<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/afs/athena/contrib/perl/perl

@packettype =
    (
     undef,				#  0
     "public-key encrypted",
     "signature",
     undef,
     undef,
     "secret-key certificate",		#  5
     "public-key certificate",
     undef,
     "compressed data",
     "conventional-key encrypted",
     undef,				# 10
     "literal data",
     "keyring trust",
     "user id"
     );

sub dec_num {
    read(F,$buf,$_[0]) || die "read num: $!\n";
    @plbytes = unpack("C*",$buf);
    $num = 0;
    for (@plbytes) {
	$num = ($num&lt;&lt;8)+$_;
    }
    $num;
}

sub dec_psf {
    $ctb = &amp;dec_num(1);

    if (($head=(($ctb &amp; 0xc0)&gt;&gt;6)) != 0x2) {
	die sprintf("bad ctb header: %02x\n",$head);
    }

    if (! ($pt = @packettype[$ptb=(($ctb &amp; 0x3c)&gt;&gt;2)])) {
	die sprintf("bad packet type: %02x\n",$pt);
    }

    $pll = $ctb &amp; 0x03;

    if ($pll == 0) {
	$plen = &amp;dec_num(1);
    } elsif ($pll == 1) {
	$plen = &amp;dec_num(2);
    } elsif ($pll == 2) {
	$plen = &amp;dec_num(4);
    } elsif ($pll == 3) {
	$plen = -1;
    }

    return($pt,$plen);
}

sub dec_bytestr {
    read(F,$buf,$_[0]) || die "read literal: $!\n";
}

sub dec_string {
    $strlen = &amp;dec_num(1);
    read(F,$str,$strlen) || die "read str: $!\n";
}

sub dec_time {
    &amp;dec_num(4);
}

sub dec_literal {
    read(F,$mode,1) || die "read literal: $!\n";
    $filename = &amp;dec_string();
    $time = &amp;dec_time;
}

sub dec_packet {
    ($pt, $plen) = &amp;dec_psf();
    print $pt," packet, len=$plen\n";
    &amp;dec_bytestr($plen);
}

while($file = shift(@ARGV)) {
    open(F,$file) || die "open $f: $!\n";

    while(!eof(F)) {
        &amp;dec_packet();
    }
}
</pre></body></html>