-
-
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]' |
can i change the root acoording to number from me ?
Thank you🤘🏼
The Caesar Cipher shifts plaintext three letters to the left to create ciphertext.
In this case, tr '[A-Z]' '[X-ZA-W]', tr translates all occurrences of 'A' to 'X', 'B' to 'Y', 'C' to 'Z', 'D' to 'A', etc.
[X-ZA-W] just means that your output starts with the letter X and continues through the letter Z, then continues with the letter A through the letter W. You could also use [XYZABCDEFGHIJKLMNOPQRSTUVW] instead but tr understands the hyphen '-' to mean 'through'.
Thank you so much. Really helped me in understanding.
so simple and elegant just like it was supposed to be, well done
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'
.
Thanks for sharing this.
However, you don't need a separate translate command for decoding. The
tr '[A-Za-z]' '[N-ZA-Mn-za-m]'
could encode as well as decode the text.