using rot13 and tr command for having an encrypted email address


Shell Problem Overview

I have read many tutorials on the internet about the usage of the 'tr' command. However, I am not able to understand how to encrypt an email address with a shell script shift the characters using rot13. Can any one give a link or an example?

Shell Solutions

Solution 1 - Shell

Not sure exactly how you want to use this, but here's a basic example to get you started:

echo '[email protected]' | tr 'A-Za-z' 'N-ZA-Mn-za-m'

To make it easier, you can alias the tr command in your .bashrc file thusly:

alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'"

Now you can just call:

echo '[email protected]' | rot13

Solution 2 - Shell

A perfect task for tr, indeed. This should do what you want:

tr 'A-Za-z' 'N-ZA-Mn-za-m'

Each character in the first set will be replaced with the corresponding character in the second set. E.g. A replaced with N, B replaced with O, etc.. And then the same for the lower case letters. All other characters will be passed through unchanged.

Note the lack of [ and ] where you normally might expect them. This is because tr treats square brackets literally, not as range expressions. So, for example, tr -d '[A-Z]' will delete capital letters and square brackets. If you wanted to keep your brackets, use tr -d 'A-Z':

$ echo "foo BAR [baz]" | tr -d '[A-Z]'
foo  baz
$ echo "foo BAR [baz]" | tr -d 'A-Z'
foo  [baz]

Same for character classes. E.g. tr -d '[[:lower:]]' is probably an error, and should be tr -d '[:lower:]'.

However, in lucky situations like this one, you can get away with including the brackets anyway! For example, tr "[a-z]" "[A-Z]" accidentally works because the square brackets in the first set are replaced by identical square brackets from the second set, but really this is a bad habit to get into. Use tr "a-z" "A-Z" instead.

Solution 3 - Shell


$ ruby -ne 'print $ "A-Za-z", "N-ZA-Mn-za-m") ' file


$ echo "test" | python -c 'import sys; print"rot13")'

Solution 4 - Shell

to simultaneously do ROT13 (for letters) and ROT5 (for numbers):

tr 'A-Za-z0-9' 'N-ZA-Mn-za-m5-90-4'


echo test | tr 'A-Za-z0-9' 'N-ZA-Mn-za-m5-90-4'

alias definition for your ~/.bashrc in case you need it more often:

alias rot="tr 'A-Za-z0-9' 'N-ZA-Mn-za-m5-90-4'"

(accurately rot135 or rot18)

Solution 5 - Shell

# Reciprocal Transformation(s)

# rot13
tr 'A-Za-z' 'N-ZA-Mn-za-m' <<< '[email protected]'

# rot13.5 (rot18)
tr 'A-Za-z0-9' 'N-ZA-Mn-za-m5-90-4' <<< '[email protected]'

# rot47
tr '\!-~' 'P-~\!-O' <<< '[email protected]'

# rot13 -- SED anyone
echo '[email protected]' | sed y/NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/

Shell Script

# Purpose: Rotate 13 characters (a reciprocal transformation)

# ./ 'A String to look Ciphered'
tr 'A-Za-z' 'N-ZA-Mn-za-m' <<< "$1"

exit $?

Solution 6 - Shell


    tr 'A-Za-z' 'N-ZA-Mn-za-m'

make the file executable by running: 
    sudo chmod +100 file_name
To ouput the answer run:


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRegistered UserView Question on Stackoverflow
Solution 1 - ShellsamullenView Answer on Stackoverflow
Solution 2 - ShellCharlie RossView Answer on Stackoverflow
Solution 3 - ShellkurumiView Answer on Stackoverflow
Solution 4 - ShellsjasView Answer on Stackoverflow
Solution 5 - ShellJimmyLandStudiosView Answer on Stackoverflow
Solution 6 - ShellEmmanuel ChaloView Answer on Stackoverflow