http://www.perlmonks.org?node_id=245659

my first japh for a while. deconstructions welcome...
#!/usr/bin/perl -w use strict; my$c=sub{$^A=~s~.~~g;formline"@<",($_[!eof 0]);$^A;};my$q="08215E2 580 B1258071258091 0 4 2 0 0 22580C21240282580DE25 816F0C20F02580CA2580 5 1 1A000A 258015258 1342581AF 0C2064 1A41F4 0D611625 81 3C 25 80 C6 258 0D6 0C 2 1E B1F 11A0 2 580421F40A0";my$g=sub{$_=shift;$_=hex('ff')-hex ;sprintf('%02x',$_)};my@data;for$a( 0..15 ){for$b( 0..15 ){push@data ,sprintf'%x%x',$a,$b}}$a=1;my@data2=map{$a=!$a;$a?$_:&$g($_)}@data;$"= "";my$data="@data2"; my $d = sub{m=(.)=while$_=shift;$1};my$f=sub{ (wantarray)?&{pop@_}(pop@_):&{shift@_}(shift@_)};$q=~s[[^\S]]{}g;print chr hex((hex$1<501)?&$f(substr($data,hex$1,2),$d).&$d(substr($data,hex $2,7)):&$f(substr($data,hex$2,4),$c))while$q=~m/(\S{3})(\S\S {2} )/xg;

Replies are listed 'Best First'.
Re: indirection
by diotalevi (Canon) on Mar 25, 2003 at 16:24 UTC

    Each pair in @japh (I reformatted $q into @japh for convenience) encodes two or three pieces of information. Each number is split as a nibble and a byte. If the nibble in the first number is non-zero then the byte from the second number is an offset into $data to find a two byte hex encoded character. If the nibble was zero then each byte specifies an index into $data to retrieve the two nibbles of the two byte hex encoded character. The first number's byte is the most significant nibble in that value.

    The de-obfuscated source

    #!/usr/bin/perl -w use strict; my $c = sub {substr shift(), 0, 2 }; my $d = sub {substr shift(), 0, 1 }; my $f = sub { $_[1] ->( $_[0] ) }; my $data = join '', map sprintf( '%02x', $_ & 1 ? $_ : 255 - $_ ), 0 .. 255; my @japh = ( [qw[082 15E]], [qw[258 0B1]], [qw[258 071]], [qw[258 091]], [qw[042 002]], [qw[258 0C2]], [qw[124 028]], [qw[258 0DE]], [qw[258 16F]], [qw[0C2 0F0]], [qw[258 0CA]], [qw[258 051]], [qw[1A0 00A]], [qw[258 015]], [qw[258 134]], [qw[258 1AF]], [qw[0C2 064]], [qw[1A4 1F4]], [qw[0D6 116]], [qw[258 13C]], [qw[258 0C6]], [qw[258 0D6]], [qw[0C2 1EB]], [qw[1F1 1A0]], [qw[258 042]], [qw[1F4 0A0]]); while (my $chr = shift @japh) { my ($l, $r) = map hex(), @$chr; print chr hex ($l >= 501 ? substr($data, $r, 2) : substr($data, $l, 1) . substr($data, $r, 1) ); }
      Beautifully done :)