Bacon cipher: Difference between revisions

→‎{{header|Perl}}: added decoding
(added MiniScript example)
(→‎{{header|Perl}}: added decoding)
Line 1,374:
 
=={{header|Perl}}==
{{incomplete|perl|No decrypt routine. }}
{{trans|Perl 6}}
<lang perl>myuse $secret = <<'END'strict;
use warnings;
use utf8;
binmode(STDOUT, ':utf8');
 
my $secret = <<'END';
This task is to implement a program for encryption and decryption
of plaintext using the simple alphabet of the Baconian cipher or
Line 1,402 ⟶ 1,406:
END
 
my @enc = ("<feff>\N{U+FEFF}", "<200b>\N{U+200B}"); # zero-width spaces
my %dec;
$dec{$enc[0]} = 0;
Line 1,418 ⟶ 1,422:
}
 
sub reveal {
my($steganography) = @_;
my $message;
(my $cleaned = $steganography) =~ s/\w|[,?:.!\-&*()*"']| |\n//g;
for my $coded_char (split /(.{7})/, $cleaned) {
next if length $coded_char == 0;
my $bits = '';
$bits .= $dec{$_} for split //, $coded_char;
$message .= chr eval('0b'.$bits);
}
$message;
}
my @hidden = map { encode($_) } split '', $secret;
 
my $steganography = hide($text, @hidden);
printmy $decoded = reveal "$steganography\n"</lang>;
 
print "$steganography\n"
print "$decoded\n"</lang>
{{out}}
<pre style="height:35ex">Steganograpic message hidden in text:
Line 1,439 ⟶ 1,457:
Bacon cipher, but I think it falls within the spirit of the task,
if not the exact definition.
 
Hidden message revealed:
This task is to implement a program for encryption and decryption
of plaintext using the simple alphabet of the Baconian cipher or
some other kind of representation of this alphabet (make anything
signify anything). This example will work with anything in the
ASCII range... even code! $r%_-^&*(){}+~ #=`/\';*1234567890"'
</pre>
 
2,392

edits