Created
November 16, 2016 06:26
-
-
Save ldante86/bbb0f3e69aa61a90710d52a9928487cb to your computer and use it in GitHub Desktop.
rotate string
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
#!/bin/bash - | |
# | |
# SCRIPT: rot | |
# AUTHOR: Luciano D. Cecere | |
# | |
######################################################################## | |
# | |
# rot - rotate the alphabet and encode a string | |
# Copyright (C) 2014 Luciano D. Cecere <ldante86@aol.com> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
######################################################################### | |
PROGNAME="${0##*/}" | |
_rot() | |
{ | |
while read input | |
do | |
case $1 in | |
0 ) echo "$input" ;; # no rotation | |
1 ) tr 'A-Za-z' 'B-ZA-Ab-za-a' <<< "$input" ;; | |
2 ) tr 'A-Za-z' 'C-ZA-Bc-za-b' <<< "$input" ;; | |
3 ) tr 'A-Za-z' 'D-ZA-Cd-za-c' <<< "$input" ;; | |
4 ) tr 'A-Za-z' 'E-ZA-De-za-d' <<< "$input" ;; | |
5 ) tr 'A-Za-z' 'F-ZA-Ef-za-e' <<< "$input" ;; | |
6 ) tr 'A-Za-z' 'G-ZA-Fg-za-f' <<< "$input" ;; | |
7 ) tr 'A-Za-z' 'H-ZA-Gh-za-g' <<< "$input" ;; | |
8 ) tr 'A-Za-z' 'I-ZA-Hi-za-h' <<< "$input" ;; | |
9 ) tr 'A-Za-z' 'J-ZA-Ij-za-i' <<< "$input" ;; | |
10) tr 'A-Za-z' 'K-ZA-Jk-za-j' <<< "$input" ;; | |
11) tr 'A-Za-z' 'L-ZA-Kl-za-k' <<< "$input" ;; | |
12) tr 'A-Za-z' 'M-ZA-Lm-za-l' <<< "$input" ;; | |
13) tr 'A-Za-z' 'N-ZA-Mn-za-m' <<< "$input" ;; # rot13 | |
14) tr 'A-Za-z' 'O-ZA-No-za-n' <<< "$input" ;; | |
15) tr 'A-Za-z' 'P-ZA-Op-za-o' <<< "$input" ;; | |
16) tr 'A-Za-z' 'Q-ZA-Pq-za-p' <<< "$input" ;; | |
17) tr 'A-Za-z' 'R-ZA-Qr-za-s' <<< "$input" ;; | |
18) tr 'A-Za-z' 'S-ZA-Rs-za-r' <<< "$input" ;; | |
19) tr 'A-Za-z' 'T-ZA-St-za-s' <<< "$input" ;; | |
20) tr 'A-Za-z' 'U-ZA-Tu-za-t' <<< "$input" ;; | |
21) tr 'A-Za-z' 'V-ZA-Uv-za-u' <<< "$input" ;; | |
22) tr 'A-Za-z' 'W-ZA-Vw-za-v' <<< "$input" ;; | |
23) tr 'A-Za-z' 'X-ZA-Wx-za-w' <<< "$input" ;; | |
24) tr 'A-Za-z' 'Y-ZA-Xy-za-x' <<< "$input" ;; | |
25) tr 'A-Za-z' 'Z-ZA-Yz-za-y' <<< "$input" ;; | |
* ) _help ;; | |
esac | |
done | |
} | |
_help() | |
{ | |
echo $PROGNAME - encode a string by rotation | |
echo Usage: $PROGAME [0-25] | |
echo Default rotation is 13 \(rot13\) | |
exit 0 | |
} | |
_rot ${1:-13} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment