diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-07-16 15:53:41 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-07-16 15:53:41 -0400 |
commit | fe60ffdfde90b4bbbd0ba570cd8a9b4282f4b7ac (patch) | |
tree | 18e31ff579a94fadc7361460404a51d5604e7116 | |
parent | 4581c73b6b037fd86304703373e3d87420928be2 (diff) |
-rw-r--r-- | caesar.sh | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/caesar.sh b/caesar.sh new file mode 100644 index 0000000..186891d --- /dev/null +++ b/caesar.sh @@ -0,0 +1,25 @@ +number=13 + +while getopts n: opt; do + case $opt in + n) number=${OPTARG};; + ?) exit 1;; + esac +done + +shift $((OPTIND - 1)) + +if [ $# -ne 0 ]; then + printf 'usage: %s [-n number]\n' "$0" + printf '\t-n the number of characters to rotate (default 13)\n' + exit 1 +fi + +number=$((number % 26)) +A=$(printf '%d' 0$(printf '%o' \"A\")) +FROM=$(printf '%o' $((A + number))) +THRU=$(printf '%o' $((A + number - 1))) +TRUPPER=$(printf '%b-ZA-%b\n' "\0${FROM}" "\0${THRU}") +trlower=$(echo $TRUPPER | tr [[:upper:]] [[:lower:]]) + +exec tr "A-Za-z" "${TRUPPER}${trlower}" |