Skip to content

Instantly share code, notes, and snippets.

@jsarenik jsarenik/caesar.sh
Last active Aug 11, 2016

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Aug 11, 2016

$ 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
You can’t perform that action at this time.