Last active
January 25, 2019 16:06
-
-
Save 75th/5778694 to your computer and use it in GitHub Desktop.
Revisions
-
75th revised this gist
Sep 17, 2013 . 1 changed file with 5 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -59,15 +59,12 @@ function rot() { local funcname="rot${realbase}" # If the base was converted above, send the actual 0-25 base to stderr if (($origbase != $realbase)) then echo "(ROT-${realbase})" 1>&2 fi echo "$string" | tr 'A-Za-z' "${!funcname}" -
75th revised this gist
Jul 13, 2013 . 1 changed file with 16 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,15 @@ #! /bin/bash # Usage: rot [base] string # # Base is assumed to be 13 if not specified. # # Bases not in 0-25 are taken modulo 26; negatives are increased by # 26es until they're positive. Thus, any integer should work # as expected. function rot() { local pattern='^-?[0-9]+$' if [[ $1 =~ $pattern ]]; # Is first argument an integer? @@ -23,7 +25,7 @@ function rot() { while (($base < 0)) do base=$(($base + 26)) # Modulo ought to work this way done local realbase=$(($base % 26)) @@ -57,10 +59,15 @@ function rot() { local funcname="rot${realbase}" # I had the idea to clarify for the user what the actual 0-25 ROT base # was if they omit the base or use one outside that range. But then # that's no good for piping into other things. Maybe I'll add a flag # for this later or something, but for now it's just commented out. # if (($origbase != $realbase)) # then # echo "(ROT-${realbase})" # fi echo "$string" | tr 'A-Za-z' "${!funcname}" -
75th revised this gist
Jul 13, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ # as expected function rot() { local pattern='^-?[0-9]+$' if [[ $1 =~ $pattern ]]; # Is first argument an integer? then -
75th created this gist
Jun 14, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ #! /bin/bash # Usage: rot [base] string # Base is assumed to be 13 if not specified. # Bases not in 0-25 are taken modulo 26; any integer should work # as expected function rot() { local pattern='^-{0,1}[0-9]+$' if [[ $1 =~ $pattern ]]; # Is first argument an integer? then local base="$1" local string="$2" local origbase="$1" # Save original base for later clarification else local base="13" local string="$1" local origbase="null" fi while (($base < 0)) do base=$(($base + 26)) # Poor man's modulo for negative numbers done local realbase=$(($base % 26)) local rot0='A-Za-z' local rot1='B-ZAb-za' local rot2='C-ZA-Bc-za-b' local rot3='D-ZA-Cd-za-c' local rot4='E-ZA-De-za-d' local rot5='F-ZA-Ef-za-e' local rot6='G-ZA-Fg-za-f' local rot7='H-ZA-Gh-za-g' local rot8='I-ZA-Hi-za-h' local rot9='J-ZA-Ij-za-i' local rot10='K-ZA-Jk-za-j' local rot11='L-ZA-Kl-za-k' local rot12='M-ZA-Lm-za-l' local rot13='N-ZA-Mn-za-m' local rot14='O-ZA-No-za-n' local rot15='P-ZA-Op-za-o' local rot16='Q-ZA-Pq-za-p' local rot17='R-ZA-Qr-za-q' local rot18='S-ZA-Rs-za-r' local rot19='T-ZA-St-za-s' local rot20='U-ZA-Tu-za-t' local rot21='V-ZA-Uv-za-u' local rot22='W-ZA-Vw-za-v' local rot23='X-ZA-Wx-za-w' local rot24='Y-ZA-Xy-za-x' local rot25='ZA-Yza-y' local funcname="rot${realbase}" if (($origbase != $realbase)) then echo "(ROT-${realbase})" fi echo "$string" | tr 'A-Za-z' "${!funcname}" } rot "$1" "$2"