-
-
Save IQAndreas/030b8e91a8d9a407caa6 to your computer and use it in GitHub Desktop.
# Caesar cipher encoding | |
echo "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" | tr '[A-Z]' '[X-ZA-W]' | |
# output: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD | |
# Caesar cipher decoding | |
echo "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD" | tr '[X-ZA-W]' '[A-Z]' | |
# output: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG | |
# Can also be adjusted to ROT13 instead | |
echo "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" | tr '[A-Z]' '[N-ZA-M]' | |
# output: GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT | |
echo "GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT" | tr '[N-ZA-M]' '[A-Z]' | |
# output: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG | |
# Case-sensitive version of ROT13 | |
tr '[A-Za-z]' '[N-ZA-Mn-za-m]' |
when I use the brackets it doesn't work so I just put "tr a-z x-za-w" from a video I saw on youtube, but my real question is why do I need to use ZA between n-(ZA)-m or between any substitution? what does it mean since it looks like tr pulls the substitution from the first syntax why not just "tr a-z n-m"
when I use the brackets it doesn't work so I just put "tr a-z x-za-w" from a video I saw on youtube, but my real question is why do I need to use ZA between n-(ZA)-m or between any substitution? what does it mean since it looks like tr pulls the substitution from the first syntax why not just "tr a-z n-m"
az
are respectively the upper and lower bounds of character ranges. For more information, you may like to do some light reading on regex syntax.
I came here from a google-search. Thanks for sharing this. However, the brackets are superfluous and the invocation can thus be
tr 'A-Za-z' 'X-ZA-Wx-za-w'
.