ROT13

ROT13 is a simple letter substitution cipher that replaces a letter with the 13th letter after it in the Latin alphabet.
ROT13 is a special case of the Caesar cipher which was developed in ancient Rome, used by Julius Caesar in the 1st century BC.[1] An early entry on the Timeline of cryptography.
ROT13 can be referred by "Rotate13", "rotate by 13 places", hyphenated "ROT-13" or sometimes by its autonym "EBG13".
Description
Applying ROT13 to a piece of text requires examining its alphabetic characters and replacing each one by the letter 13 places further along in the alphabet, wrapping back to the beginning if necessary.[2]
When encoding a message, A becomes N, B becomes O, and so on up to M, which becomes Z. Then the sequence continues at the beginning of the alphabet: N becomes A, O becomes B, and so on to Z, which becomes M. When decoding a message, the same substitution rules are applied, but this time on the ROT13 encrypted text. Other characters, such as numbers, symbols, punctuation or whitespace, are left unchanged.
Because there are 26 letters in the Latin alphabet and 26 = 2 × 13, the ROT13 function is its own inverse:[2]
- for any basic Latin-alphabet text .
In other words, two successive applications of ROT13 restore the original text (in
The transformation can be done using a lookup table, such as the following:
Input | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz |
Output | NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm |
For example, in the following joke, the punchline has been obscured by ROT13:
- Why did the chicken cross the road?
- Gb trg gb gur bgure fvqr!
Transforming the entire text via ROT13 form, the answer to the joke is revealed:
- Jul qvq gur puvpxra pebff gur ebnq?
- To get to the other side!
A second application of ROT13 would restore the original.
Usage
ROT13 is not intended to be used in modern times. At the time of conception in an era of
.In the early 1980s, people supposedly used ROT13 in their messages on Usenet newsgroup servers[3] They did this to hide potentially offensive jokes, or to obscure an answer to a puzzle or other
]. ROT13 has been the subject of many jokes.The 1989 International Obfuscated C Code Contest (IOCCC) included an entry by Brian Westley. Westley's computer program can be encoded in ROT13 or reversed and still compiles correctly. Its operation, when executed, is either to perform ROT13 encoding on, or to reverse its input.[5]
In December 1999, it was found that Netscape Communicator used ROT13 as part of an insecure scheme to store email passwords.[6]
In 2001, Russian programmer
Net culture
Because of its utter unsuitability for real secrecy, ROT13 has become a catchphrase to refer to any conspicuously weak encryption scheme; a critic might claim that "56-bit DES is little better than ROT13 these days". In a play on real terms like "double DES" several terms cropped up with humorous intent:
- Double ROT13: applying ROT13 to an already ROT13-encrypted text restores the original plaintext.
- ROT26: equivalent to no encryption at all.
- 2ROT13 was included in a spoof academic paper entitled "On the 2ROT13 Encryption Algorithm".[10]
- triple-ROT13: used jokingly in analogy with 3DES, it is equivalent to regular ROT13.
ROT13 jokes were popular on many
The newsgroup alt.folklore.urban coined a word—furrfu—that was the ROT13 encoding of the frequently encoded utterance "
Using a search engine on public social networks, yields results for ROT13 in jokes to this day.[citation needed][when?]
Letter games
abcdefghijklmnopqrstuvwxyz NOPQRSTUVWXYZABCDEFGHIJKLM | |
aha ↔ nun | ant ↔ nag |
balk ↔ onyx | bar ↔ one |
barf ↔ ones | be ↔ or |
bin ↔ ova | ebbs ↔ roof |
envy ↔ rail | er ↔ re |
errs ↔ reef | flap ↔ sync |
fur ↔ she | gel ↔ try |
gnat ↔ tang | irk ↔ vex |
clerk ↔ pyrex | purely ↔ cheryl |
PNG ↔ cat | SHA ↔ fun |
furby ↔ sheol | terra ↔ green |
what ↔ Jung | URL ↔ hey |
purpura ↔ Chechen | shone ↔ FUBAR |
Ares ↔ Nerf | abjurer ↔ nowhere |
ROT13 provides an opportunity for letter games. Some words will, when transformed with ROT13, produce another word. Examples of 7-letter pairs in the
and tang is an example of words that are both ROT13 reciprocals and reversals.Variants and combinations
ROT5 is a practice similar to ROT13 that applies to numeric digits (0 to 9). ROT13 and ROT5 can be used together in the same message, sometimes called ROT18 (18 = 13 + 5) or ROT13.5.
ROT47 is a derivative of ROT13 which, in addition to scrambling the basic letters, treats numbers and common symbols. Instead of using the sequence A–Z as the alphabet, ROT47 uses a larger set of characters from the common character encoding known as ASCII. Specifically, the 7-bit printable characters, excluding space, from decimal 33 '!' through 126 '~', 94 in total, taken in the order of the numerical values of their ASCII codes, are rotated by 47 positions, without special consideration of case. For example, the character A is mapped to p, while a is mapped to 2.
The use of a larger alphabet produces a more thorough obfuscation than that of ROT13; for example, a telephone number such as +1-415-839-6885 is not obvious at first sight from the scrambled result Z'\c`d\gbh\eggd. On the other hand, because ROT47 introduces numbers and symbols into the mix without discrimination, it is more immediately obvious that the text has been encoded.
Example:
- The Quick Brown Fox Jumps Over The Lazy Dog.
enciphers to
- %96 "F:4< qC@H? u@I yF>AD ~G6C %96 {2KJ s@8]
The
Implementation
tr
The ROT13 and ROT47 are fairly easy to implement using the Unix terminal application tr; to encrypt the string "Pack My Box With Five Dozen Liquor Jugs" in ROT13:
$ # Map upper case A-Z to N-ZA-M and lower case a-z to n-za-m
$ tr 'A-Za-z' 'N-ZA-Mn-za-m' <<< "Pack My Box With Five Dozen Liquor Jugs"
Cnpx Zl Obk Jvgu Svir Qbmra Yvdhbe Whtf
and the string "The Quick Brown Fox Jumps Over The Lazy Dog" for ROT47:
$ echo "The Quick Brown Fox Jumps Over The Lazy Dog" | tr '\!-~' 'P-~\!-O'
%96 "F:4< qC@H? u@I yF>AD ~G6C %96 {2KJ s@8
Emacs and Vim
In Emacs, one can ROT13 the buffer or a selection with the commands:[14] M-x toggle-rot13-mode, M-x rot13-other-window, or M-x rot13-region.
In the Vim text editor, one can ROT13 a buffer with the command:[15] ggg?G.
Python
The module codecs provides 'rot13' text transform.[16]
>>> import codecs
>>> print(codecs.encode("The Quick Brown Fox Jumps Over The Lazy Dog", "rot13"))
Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt
Without importing any libraries, it can be done by creating a translation table manually:[a]
>>> def gen_rot13_table(func=lambda x: x):
... for c in (ord('A'), ord('a')):
... for i in range(26):
... yield func(i+c), func((i+13) % 26 + c)
>>> table = dict(gen_rot13_table(chr))
>>> table
{'A': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'E': 'R', 'F': 'S', 'G': 'T', 'H': 'U', 'I': 'V', 'J': 'W', 'K': 'X', 'L': 'Y', 'M': 'Z', 'N': 'A', 'O': 'B', 'P': 'C', 'Q': 'D', 'R': 'E', 'S': 'F', 'T': 'G', 'U': 'H', 'V': 'I', 'W': 'J', 'X': 'K', 'Y': 'L', 'Z': 'M', 'a': 'n', 'b': 'o', 'c': 'p', 'd': 'q', 'e': 'r', 'f': 's', 'g': 't', 'h': 'u', 'i': 'v', 'j': 'w', 'k': 'x', 'l': 'y', 'm': 'z', 'n': 'a', 'o': 'b', 'p': 'c', 'q': 'd', 'r': 'e', 's': 'f', 't': 'g', 'u': 'h', 'v': 'i', 'w': 'j', 'x': 'k', 'y': 'l', 'z': 'm'}
>>>
>>> s = "Quartz glyph job vext cwm porshrop finks?!"
>>> print("".join(table.get(c, c) for c in s))
Dhnegm tylcu wbo irkg pjz cbefuebc svaxf?!
For Python 3, you can use the method str.translate()
(with str.maketrans()
):
>>> x, y = zip(*gen_rot13_table(chr))
>>> ''.join(x)
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
>>> ''.join(y)
'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
>>> table = str.maketrans(''.join(x), ''.join(y))
>>> table
{65: 78, 66: 79, 67: 80, 68: 81, 69: 82, 70: 83, 71: 84, 72: 85, 73: 86, 74: 87, 75: 88, 76: 89, 77: 90, 78: 65, 79: 66, 80: 67, 81: 68, 82: 69, 83: 70, 84: 71, 85: 72, 86: 73, 87: 74, 88: 75, 89: 76, 90: 77, 97: 110, 98: 111, 99: 112, 100: 113, 101: 114, 102: 115, 103: 116, 104: 117, 105: 118, 106: 119, 107: 120, 108: 121, 109: 122, 110: 97, 111: 98, 112: 99, 113: 100, 114: 101, 115: 102, 116: 103, 117: 104, 118: 105, 119: 106, 120: 107, 121: 108, 122: 109}
>>>
>>> print(s.translate(table))
Dhnegm tylcu wbo irkg pjz cbefuebc svaxf?!
See also
References
- ^ This source code is a slight variation in Zen of Python[17]
- ISBN 0-684-83130-9.
- ^ ISBN 0-471-11709-9.
- ^ a b Raymond, Eric S., ed. (29 December 2003). "ROT13". The Jargon File, 4.4.7. Archived from the original on 13 January 2012. Retrieved 19 September 2007.
- ^ Hambridge, Sally (1 October 1995). "RFC 1855 - Netiquette Guidelines". Internet Engineering Task Force. Archived from the original on 2 January 2025. Retrieved 2 January 2025.
- IOCCC. Archivedfrom the original on 9 June 2012. Retrieved 13 August 2007.
- CiteSeerX 10.1.1.15.9271.
- ZDNet News. Archivedfrom the original on 17 October 2014. Retrieved 3 February 2011.
- ^ "ROT13 is used in Windows". 24 July 2006. Archived from the original on 20 December 2016. Retrieved 15 December 2016.
- ^ Simanek, Donald E. (2012). "Perpetual Futility: A short history of the search for perpetual motion". The Museum of Unworkable Devices. Archived from the original on 10 October 2020. Retrieved 28 October 2020.
- ^ "On the 2ROT13 Encryption Algorithm" (PDF). Prüfziffernberechnung in der Praxis. 25 September 2004. Archived (PDF) from the original on 15 April 2012. Retrieved 20 September 2007.
- Foldoc. 25 October 1995. Archivedfrom the original on 14 July 2014. Retrieved 3 October 2016.
- ^ De Mulder, Tom. "ROT13 Words". Furrfu!. Archived from the original on 2 April 2012. Retrieved 19 September 2007.
- ^ "5.13 Obfuscating Data". The GNU C Library Reference Manual. Free Software Foundation. 3 December 2006. Archived from the original on 2 August 2019. Retrieved 2 August 2019.
- ^ "Rmail Rot13 – GNU Emacs Manual" Archived 24 March 2016 at the Wayback Machine. www.gnu.org.
- ^ "Best of VIM Tips, gVIM's Key Features zzapper". rayninfo.co.uk. 3 March 2016. Archived from the original on 3 March 2016.
- ^ "codecs – Codec registry and base classes – Python 3.9.6 documentation". ww6.python.org. 2 November 2023. Archived from the original on 6 October 2020. Retrieved 7 October 2020.
- ^ this.py on GitHub
External links
- Online converter for ROT13, ROT5, ROT18, ROT47, Atbash and Caesar cipher.
- ROT13 to Text on PureTables.com