using rot13 and tr command for having an encrypted email address

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

Ruby(1.9+)

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

Python

$ echo "test" | python -c 'import sys; print sys.stdin.read().encode("rot13")'

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

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

usage:

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)


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.

Tags:

Shell