Last active
August 29, 2015 14:04
-
-
Save possatti/00db98a35748ae666238 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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