4

There's a text affected by ROT13, called rot.txt. ROT13 (rotate by 13 places) replaces a letter with the letter 13 letters after it in the alphabet. How do I write the command to view the actual text?

I tried:

cat rot.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m'

but no success

  • Very unusual question. In your text file what about punctuation characters like ", ', ., ,, ? and !, etc. Are they shifted 13 by 13 ASCII decimals lower too? – WinEunuuchs2Unix Oct 20 '18 at 0:05
4

Here is a way with an example

echo "hello world" | tr "$(echo -n {A..Z} {a..z} | tr -d ' ')" "$(echo -n {N..Z} {A..M} {n..z} {a..m} | tr -d ' ')"

Output:

uryyb jbeyq

Make it a function:

function rot13() {    
    cat | tr "$(echo -n {A..Z} {a..z} | tr -d ' ')" "$(echo -n {N..Z} {A..M} {n..z} {a..m} | tr -d ' ')" 
}

Usage:

➜ echo "hello world" | rot13 
uryyb jbeyq
  • i need to decode a full text, not just 2 words. how do i decode .txt file? thank you for your time answering – Jena Alissa Oct 19 '18 at 1:53
  • @JenaAlissa, I updated it, so you should use cat rot.txt | rot13 – smac89 Oct 19 '18 at 1:56
1

The easiest way to decrypt is to use the same program used to encrypt the test; ROT13:

An offset of 13 allows the encryption to be reversible. The encryption and decryption method are identical. Applying 2 consecutive encryptions (2 shifts of 13) heads to find the original text.

The link also mentions that numbers can be encrypted by shifting ASCII 5 positions and punctuation characters can be encrypted by shifting ASCII 47 positions.

1

You can also achieve the same output by using the following piece of command:

tr '[a-z][A-Z]' '[n-za-m][N-ZA-M]'

or

tr '[a-zA-Z]' '[n-za-mN-ZA-M]'

Personally, I find this syntax a lot easier.

0

Just download the (now ancient, like some of us) rot13 command used in Unix back when there were wooden ships and iron men. You can find it here: https://sourceforge.net/projects/rot13/files/rot13/1.2.1/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.