ROT13 ('rotate by 13 places', sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is a special case of the Caesar cipher, developed in ancient Rome.

Because there are 26 letters (2×13) in the basic Latin alphabet, ROT13 is its own inverse; that is, to undo ROT13, the same algorithm is applied, so the same action can be used for encoding and decoding. The algorithm provides virtually no cryptographic security, and is often cited as a canonical example of weak encryption.[1]

ROT13 is used in online forums as a means of hiding spoilers, punchlines, puzzle solutions, and offensive materials from the casual glance. ROT13 has been described as the 'Usenet equivalent of a magazine printing the answer to a quiz upside down'.[2] ROT13 has inspired a variety of letter and word games on-line, and is frequently mentioned in newsgroup conversation.


function rot13(s)
    return (s ? s : this).split('').map(function(_)
        if (!_.match(/[A-Za-z]/)) return _;
        c = Math.floor(_.charCodeAt(0) / 97);
        k = (_.toLowerCase().charCodeAt(0) - 83) % 26 || 26;
        return String.fromCharCode(k + ((c == 0) ? 64 : 96));

var s = 'My String'; var enc = rot13(s); var s = rot13(enc); alert(enc+' '+s); /*Zl Fgevat My String*/
/*PHP*/ echo $decrypted = str_rot13('Zl Fgevat'); //My String echo $encrypted = str_rot13('My String'); //Zl Fgevat