Skip to content

Instantly share code, notes, and snippets.

@possatti
Last active August 29, 2015 14:04
Show Gist options
  • Save possatti/00db98a35748ae666238 to your computer and use it in GitHub Desktop.
Save possatti/00db98a35748ae666238 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
## Example from http://langref.org/all-languages/strings/reversing-a-string/simple-substitution-cipher
sub rot13 {
my $str = shift;
$str =~ tr/A-Za-z/N-ZA-Mn-za-m/;
return $str;
}
sub rot47 {
my $str = shift;
$str =~ tr/!-~/P-~!-O/;
return $str;
}
# Original string.
$original = 'Hello World #123';
# Cypher the string.
$weird = rot47($original);
print "$weird\n";
# Decypher the string back again;
$normalized = rot47($weird);
print "$normalized\n";
## It is possible to do some cool transformation in the terminal using
## the technique. Example:
# $ echo 'w6==@ (@C=5 R`ab' | perl -pe 'tr/P-~!-O/!-~/'
# Hello World #123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment