ROT-13 is a simple way of encrypting a document. Encryption is the process if taking a document, translating it so that in its encrypted form it is not readable, but can be decrypted so that it returns back to its original readable form.

ROT-13 is the US government's idea of personal encryption. Some powerful members of government wish that this was the only form of encryption available to its citizens. Fortunately, others have more realistic views.

Encrypting and decrypting ROT-13 is easy. It is short for "Rotate 13 letters". If you know the alphabet (US centric, sorry, I realize) then you can easily make a ROT-13 chart:

abcdefghijklm
nopqrstuvwxyz

Now say you want to decrypt the phrase "Uryyb jbeyq!". Take the first letter, 'U'. It's on the second row of the handy chart, and it's the 22nd letter of the alphabet. The letter right above 'U' is 'H', which is the 8th letter of the alphabet. 22 - 8 = 13, so turn the 'U' into an 'H' and move on to the next letter.

'r' coresponds with 'e' in the chart, and to doublecheck, 'r' is the 18th letter, and 'e' is the 5th, and 18 - 5 = 13. This is a good way to scramble a message so that it takes longer to read, but it's not exactly cryptography.

root mode = R = rotary debugger

rot13 /rot ther'teen/ n.,v.

[Usenet: from `rotate alphabet 13 places'] The simple Caesar-cypher encryption that replaces each English letter with the one 13 places forward or back along the alphabet, so that "The butler did it!" becomes "Gur ohgyre qvq vg!" Most Usenet news reading and posting programs include a rot13 feature. It is used to enclose the text in a sealed wrapper that the reader must choose to open -- e.g., for posting things that might offend some readers, or spoilers. A major advantage of rot13 over rot(N) for other N is that it is self-inverse, so the same code can be used for encoding and decoding. See also spoiler space, which has partly displaced rot13 since non-Unix-based newsreaders became common.

--The Jargon File version 4.3.1, ed. ESR, autonoded by rescdsk.

the catbox commanded me to do this. i'm not even sorry.

ROT13 is, by today's standards, a weak form of encryption - easy to spot, especially to the trained mind, and known algorithm with the same key used every time. In fact, as has been helpfully pointed out above, it doesn't take much coding knowledge at all to crack ROT13. So, in the early 21st century, what's it actually good for?

  • Children's puzzles. A pretty straightforward notion - encipher a quote with ROT13 and let kids work out what the quote is, with or without the decryption key. Of course, you could also use ROT13 for any puzzle - just be prepared for your puzzle to be solved by a lot of people, very fast (mind you, that might be what your aim is).
  • Word games. What English words can be encoded using ROT13 such that a new English word is spat out? What about non-English words? What about English words that translate into non-English words? What about other languages that use the Latin alphabet? And what about using other alphabets - the Greek or Cyrillic alphabets? (I... may have spent a lot of hours in my childhood working some of these out.)
  • Hints or answers to puzzles. Geocaching in particular uses ROT13 to obscure hints for finding geocaches and solving their associated puzzles. Geocaching apps in particular love this since encryption and decryption of ROT13 is very easy and doesn't rely on any proprietary algorithm or API. For those who would rather not have hints, the encrypted hint is obscured enough that people don't accidentally sneak peeks at it. Of course, the puzzle world is not limited to geocaching...
  • Concealing spoilers in fiction. Thanks to the advent of the Internet, discussion about the latest episodes of Game Of Thrones will pop up before people have a chance to watch them. How to hide said spoilers? ROT13. Easy to decrypt, and easy to respond with your own encrypted message. Those who have not seen the show will not accidentally see any spoilers.
  • Hiding punchlines of jokes. For much the same reason as above.
  • Introductions to cryptology. Caesar-shift ciphers in general are weak, but their importance to the development of modern cryptology and cryptanalysis cannot be underestimated - especially when it comes to breaking the Caesar cipher (and, for that matter, other monoalphabetic substitution ciphers like Atbash). I personally like teaching crypto in the form of "here's cipher A, here's how to break it, here's how to address the weaknesses of cipher A with a stronger cipher B" - ROT13 tends to be one of the earliest ciphers I mention.
  • Censorship. Well... more like self-censorship, particularly in terms of swears or obscene content that may be NSFW or not kid-friendly. Thank shpx we have a tool to help hide this stuff from innocent eyes.

Okay, okay. Apart from children's puzzles, word games, puzzle hints, spoiler-concealing, hiding punchlines, crypto 101, and keeping things safe for work what has ROT13 ever done for us? ...Oh, coding practise for first-year comp-sci students? Shut up.

Wait. What d'you mean, Game Of Thrones is over?

For those of you too lazy to figure out what trak3r wrote, here is that writeup after going through ROT13:

ROT13 is a super lame encryption technique that consists of shifting each letter of the alphabet thirteen places. (uvag: guvf nccneragyl-tneoyrq fragrapr vf EBG13 rapbqrq)

For those people who don't have access to tr but have access to perl and the command line, here is a short little Perl program:

while(<>) {                   #for each line of data ...
    tr/a-zA-Z/n-za-mN-ZA-M/;  #... perform ROT-13 ...
    print;                    #... and display the translated line
}

dafydd, being a real Perl programmer, determined how to make the program a one-liner:

    tr/a-zA-Z/n-za-mN-ZA-M/ and print while <>

If you can't even do that, but have access to the site Everything 2 (probably a safe bet), JayBonci wrote E2 Rot13 Encoder, which lets E2 do all the work..

Just because I had most of this from my Caesar shift cipher node.

Plain    a b c d e f g h i j k l m n o p q r s t u v w x y z
ROT13    N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
Or this might be simpler:
a b c d e f g h i j k l m
| | | | | | | | | | | | |
n o p q r s t u v w x y z

Here are two ways to solve your ROT-13 needs.
Use the following bookmarklet:

javascript:P9 = prompt( 'Text...', '' );

if ( P9 ) {
    S2b = '';

    for ( J7 = 0; J7 < P9.length; J7++ ) {
        C6 = P9.charCodeAt( J7 );

        if ( Math.abs( 16 - Math.abs( C6 - 93.5 ) ) <= 13 ) {
            W8b = ( C6 < 91 ) ? 65 : 97;
            S2b += String.fromCharCode(((C6 - W8b + 13) % 26 ) + W8b);
        } else {
            S2b += P9.charAt( J7 );
        }
    }

    alert( S2b );
} else {
    void ( null );
}


or use the magical perl y/a-zA-Z/n-za-mN-ZA-M/

Just another interesting fact is that the longest English words that form another word when put through rot13 are 'abjurer' and 'nowhere'.

/*  Rot-13 encoder/decoder in C
 *
 *  This wretched little monstrosity is in the public domain.
 *  A much better solution is to use sed or tr. If you're on 
 *  Windows, go to the GNUish Project and download sed.
 *
 *  As with any simple character translation thing, a 
 *  lookup table would be more efficient, but... come on!
 *
 *  wharfinger  11/5/00
 */

#include <stdio.h>
#include <ctype.h>

int r13( int c );

int main()
{
    int c;

    while ( ( c = getchar() ) != EOF )
        putchar( r13( c ) );

    return 0;
}


int r13( int c )
{
    /*  Okay, it's a nested ternary. I know.
        This should probably be a macro, but macros this complex 
        get on my nerves.  
        'm' is the thirteenth letter of the alphabet.
        I mean, like, in case you didn't know or something.
    */
    return ( isalpha( c ) )
                ? ( ( tolower( c ) > 'm' ) ? ( c - 13 ) : ( c + 13 ) )
                : c;
}

Update 2/26/02: DelFick /msg'ed me with his version that works for IE and Mozilla (confirmed). Cross browser capability automatically makes it better than mine and daglo's. Here's an easy-to-copy-&-paste version:
javascript: if(document.all)sel=document.selection.createRange().text; else{sel=getSelection().toString(); }if(!sel)sel=prompt('Enter the text to ROT13',''); alpha="abcdefghijklmnopqrstuvwxyz"; alpha+=alpha+alpha.toUpperCase()+alpha.toUpperCase(); for(i=0,result=""; i<sel.length; result+=(alpha.indexOf(sel.charAt(i))<0)? sel.charAt(i++): alpha.charAt(alpha.indexOf(sel.charAt(i++))+13)); void(alert(result));
The code looks like this:
javascript:
if(document.all)
  sel=document.selection.createRange().text;
else {
  sel=getSelection().toString();
}
if(!sel)sel=prompt('Enter the text to ROT13','');
alpha="abcdefghijklmnopqrstuvwxyz";
alpha+=alpha+alpha.toUpperCase()+alpha.toUpperCase();
for(i=0,result=""; i < sel.length;
  result+=(alpha.indexOf(sel.charAt(i)) < 0)?
  sel.charAt(i++):
  alpha.charAt(alpha.indexOf(sel.charAt(i++))+13)
);
void(alert(result));
Changing the last line to void(prompt('result:', result)); makes the bookmarklet into a rot-13 writer also, where you can easily copy the rot-13 encoded text.
Here is my version of a Mozilla rot-13 decoder bookmarklet in one line for easy copy-and-pasting:

javascript:p=document.getSelection();if(!p)p=prompt('Text:',''); q=''; for(i=0;i<p.length;i++) {c=p.charCodeAt(i); q+=String.fromCharCode (c+((c<65)^(c<91)^(c<97)^(c<123)? (c-1)%32<13? 13:-13:0))}alert(q)

Paste this as the location of a bookmark, and you've got a rot13 decoding button. For the curious, an easier-to-read version of the same thing:
javascript:
p=document.getSelection();
if(!p)p=prompt('Text...','');
q='';
for(i=0; i<p.length; i++){
  c=p.charCodeAt(i);
  q+=String.fromCharCode(
    c+((c<65)^(c<91)^(c<97)^(c<123)? // *1
    (c-1)%32<13?13:-13:0)            // *2
  );
}
alert(q)

// *1 - true iff c represents an alphabet
// *2 - decide btwn move forward and loop around
Added functionality: works on selected text, a la Netscape Everything Search Button-style. Select a rot13 encoded text, and press the decoder button. If nothing is selected, a dialog box pops up asking you for text.

Test it here!
Guvf znl abg pbzr va unaql...

Log in or register to write something here or to contact authors.