Last active
August 11, 2016 12:18
-
-
Save jsarenik/9807e05d6c4287aa1aee6dbd26c158db to your computer and use it in GitHub Desktop.
Caesar cipher in POSIX shell using cut and tr
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/sh | |
# | |
# https://en.wikipedia.org/wiki/Caesar_cipher | |
KEY=${1:-3} | |
A=abcdefghijklmnopqrstuvwxyz | |
B=$(echo $A | cut -b${KEY}- | tr -d '\n'; echo $A | cut -b-$[KEY-1]) | |
AU=$(echo $A | tr '[a-z]' '[A-Z]') | |
BU=$(echo $B | tr '[a-z]' '[A-Z]') | |
tr "[${A}${AU}]" "[${B}${BU}]" |
Author
jsarenik
commented
Aug 11, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment