Alter logic. Translate control characters if more than one and check for word characters in end string. This allow for spaces as we used to do

master
Zach Thompson 2016-03-20 12:15:00 -06:00
parent f7af5bbcd8
commit 0a602ad68f
1 changed files with 11 additions and 10 deletions

View File

@ -89,26 +89,23 @@ handle matches => sub {
my $q = $_; # orginal query
my $bin_string = shift @_; # captured binary string
my $str;
if($bin_string eq $zaahirs_hideout){
$str = q{Congratulations, you've discovered Zaahir's hideout!};
goto DONE;
}
my $want_ascii = $q =~ /\bascii\b/;
my @bins = $bin_string =~ /([01]+|\s+)/g;
my $str;
for my $b (@bins){
if($b =~ /^[01]+$/){
return if length($b) % 8;
# Overflow/non-portable warnings expected
my $i = oct("0b$b");
if($bin_string eq $zaahirs_hideout){
$str = q{Congratulations, you've discovered Zaahir's hideout!};
if((exists $ctrl_chars{$i}) && (@bins == 1)){
$str = "Control character: $ctrl_chars{$i}";
last;
}
elsif(exists $ctrl_chars{$i}){
if(@bins == 1){
$str = "Control character: $ctrl_chars{$i}";
last;
}
else{ return } # only allow a single binary to unicode char
}
# Assume ascii if out of range or explicitly requested.
# This will work for characters all in the same string
# but will not print the right non-ascii characters *if*
@ -122,6 +119,10 @@ handle matches => sub {
}
}
DONE:
return unless $str =~ /\w+/;
return "Binary '$bin_string' converted to " . $want_ascii ? 'ascii' : 'unicode' . " is '$str'",
structured_answer => {
id => 'bin2unicode',