+sub vc_casefix { # partial reverse-engeenered implementation of case mapping
+ my ( $vc, $k, $rest ) = @_;
+
+ $vc .= " " x (4 - length($vc));
+
+ my @m = map { ord($_) } split(//, $vc);
+
+ my $mask = ( $m[3] & 0b00001111 ) << 4 | ( $m[2] & 0b00001111 );
+
+ my $sel = 0b10000000;
+ my $fixed;
+ my @chars = split(//, $k);
+ foreach my $c ( @chars ) {
+ die "key [$k]" unless defined $c;
+ $fixed .= $mask & $sel ? uc($c) : lc($c);
+ $sel >>= 1;
+ }
+
+ if ( substr($vc,0,1) eq 'x' ) {
+ $fixed = ucfirst $fixed;
+ }
+
+ if ( $rest && length($fixed) < 8 ) {
+# warn "# padding $fixed|$rest";
+ $fixed .= " " x ( 8 - length($fixed) );
+ }
+
+ return $fixed . $rest;
+}
+