Question 1: A Perl solution
open my $fh, '<', '01-cipher'; my %map; while(<$fh>) { next unless m{\S}; next if /\Q+---+----+/; if(m/\| ([A-Z]) \| ([0-9A-F]{2}) \|/) { $map{$1} = chr(hex($2)); } else { s/(\S)/$map{$1} || $1/eg; print; } }
open my $fh, '<', '01-cipher'; my %map; while(<$fh>) { next unless m{\S}; next if /\Q+---+----+/; if(m/\| ([A-Z]) \| ([0-9A-F]{2}) \|/) { $map{$1} = chr(hex($2)); } else { s/(\S)/$map{$1} || $1/eg; print; } }