Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created November 30, 2011 12:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aanoaa/1408846 to your computer and use it in GitHub Desktop.
Save aanoaa/1408846 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Pod::Usage;
use Getopt::Long;
use File::Slurp 'slurp';
my %options;
GetOptions(\%options, "--show", "--help");
run(\%options, @ARGV);
sub run {
my ($opts, @args) = @_;
pod2usage(0) if $opts->{help};
my @files;
if (@args == 0) {
@files = (join '', <STDIN>);
} else {
for my $arg (@args) {
push @files, slurp $arg;
}
}
for my $file (@files) {
if ($opts->{show}) {
print show($file), "\n";
} else {
print hide($file), "\n";
}
}
}
sub hide {
my $text = shift;
$text = unpack "b*", $text;
$text =~ tr/01/ \t/;
$text;
}
sub show {
my $text = shift;
$text =~ tr/ \t/01/;
$text = pack "b*", $text;
$text;
}
__END__
=head1 NAME
s3cr3t - 'hide' and 'unhide' text files
=head1 SYNOPSIS
s3cr3t OPTION file1 [file2 ...]
-s, --show Show hidden text(reverse hide mode)
-h, --help Display the help information
$ s3cr3t --help
$ s3cr3t a.txt > a.hidden
$ s3cr3t a.hidden
$ cat a.txt | s3cr3t
=head1 DESCRIPTION
No more description.
=head1 LICENSE
same as Perl.
=head1 AUTHOR
Hyungsuk Hong
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment