Skip to content

Instantly share code, notes, and snippets.

@jsarenik
Last active August 11, 2016 12:18
Show Gist options
  • Save jsarenik/9807e05d6c4287aa1aee6dbd26c158db to your computer and use it in GitHub Desktop.
Save jsarenik/9807e05d6c4287aa1aee6dbd26c158db to your computer and use it in GitHub Desktop.
Caesar cipher in POSIX shell using cut and tr
#!/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}]"
@jsarenik
Copy link
Author

$ sh caesar.sh 7
AHOJ toggl.com
GNUP zummr.ius

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment