ROT13

From Wikipedia, the free encyclopedia

ROT13 replaces each letter by its partner 13 characters further along the alphabet. For example, HELLO becomes URYYB (or, conversely, URYYB becomes HELLO again).

ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it in the alphabet. ROT13 is a special case of the Caesar cipher which was 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 inspired a variety of letter and word games online, and is frequently mentioned in newsgroup conversations.

Description[]

Applying ROT13 to a piece of text merely 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] 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. Only those letters which occur in the English alphabet are affected; numbers, symbols, whitespace, and all other characters are left unchanged. Because there are 26 letters in the English alphabet and 26 = 2 × 13, the ROT13 function is its own inverse:[2]

for any basic Latin-alphabet text x.

In other words, two successive applications of ROT13 restore the original text (in mathematics, this is sometimes called an involution; in cryptography, a reciprocal cipher).

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 a special case of the encryption algorithm known as a Caesar cipher, used by Julius Caesar in the 1st century BC.[3]

Johann Ernst Elias Bessler, an 18th century clockmaker and constructor of perpetual motion machines, pointed out that ROT13 encodes his surname as Orffyre. He used its latinised form, Orffyreus, as his pseudonym.[4]

ROT13 was in use in the net.jokes newsgroup by the early 1980s.[a] It is used to hide potentially offensive jokes, or to obscure an answer to a puzzle or other spoiler.[2][7][unreliable source?] A shift of thirteen was chosen over other values, such as three as in the original Caesar cipher, because thirteen is the value for which encoding and decoding are equivalent, thereby allowing the convenience of a single command for both.[7] ROT13 is typically supported as a built-in feature to newsreading software.[7] Email addresses are also sometimes encoded with ROT13 to hide them from less sophisticated spam bots.[8][dubious ] It is also used to circumvent email screening and spam filtering. By obscuring an email's content, the screening algorithm is unable to identify the email as, for instance, a security risk, and allows it into the recipient's in-box.

In encrypted, normal, English-language text of any significant size, ROT13 is recognizable from some letter/word patterns. The words "n", "V" (capitalized only), and "gur" (ROT13 for "a", "I", and "the"), and words ending in "yl" ("ly") are examples.

ROT13 is not intended to be used where secrecy is of any concern—the use of a constant shift means that the encryption effectively has no key, and decryption requires no more knowledge than the fact that ROT13 is in use. Even without this knowledge, the algorithm is easily broken through frequency analysis.[2] 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". Also, in a play on real terms like "double DES", the terms "double ROT13", "ROT26", or "2ROT13" crop up with humorous intent (due to the fact that, since applying ROT13 to an already ROT13-encrypted text restores the original plaintext, ROT26 is equivalent to no encryption at all), including a spoof academic paper entitled "On the 2ROT13 Encryption Algorithm".[9] By extension, triple-ROT13 (used in joking analogy with 3DES) is equivalent to regular ROT13.

In December 1999, it was found that Netscape Communicator used ROT13 as part of an insecure scheme to store email passwords.[10] In 2001, Russian programmer Dimitry Sklyarov demonstrated that an eBook vendor, New Paradigm Research Group (NPRG), used ROT13 to encrypt their documents; it has been speculated that NPRG may have mistaken the ROT13 toy example—provided with the Adobe eBook software development kit—for a serious encryption scheme.[11] Windows XP uses ROT13 on some of its registry keys.[12] ROT13 is also used in the Unix fortune program to conceal potentially offensive dicta.

Letter games and net culture[]

abcdefghijklmnopqrstuvwxyz
NOPQRSTUVWXYZABCDEFGHIJKLM
ahanun antnag
balkonyx barone
barfones beor
binova ebbsroof
envyrail erre
errsreef flapsync
furshe geltry
gnattang irkvex
clerkpyrex purelycheryl
PNGcat SHAfun
furbysheol terragreen
whatJung URLhey
purpuraChechen shoneFUBAR
AresNerf abjurernowhere

ROT13 provides an opportunity for . Some words will, when transformed with ROT13, produce another word. Examples of 7-letter pairs in the English language are abjurer and nowhere, and Chechen and purpura. Other examples of words like these are shown in the table.[13] The pair gnat and tang is an example of words that are both ROT13 reciprocals and reversals.

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.[14]

The newsgroup alt.folklore.urban coined a word—furrfu—that was the ROT13 encoding of the frequently encoded utterance "sheesh". "Furrfu" evolved in mid-1992 as a response to postings repeating urban myths on alt.folklore.urban, after some posters complained that "Sheesh!" as a response to newcomers was being overused.[15]

Variants[]

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 enciphered.

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 GNU C library, a set of standard routines available for use in computer programming, contains a functionmemfrob()[16]—which has a similar purpose to ROT13, although it is intended for use with arbitrary binary data. The function operates by combining each byte with the binary pattern 00101010 (42) using the exclusive or (XOR) operation. This effects a simple XOR cipher. Like ROT13, XOR (and therefore memfrob()) is self-reciprocal, and provides a similar, virtually absent, level of security.

Implementation[]

tr[]

The ROT13 and ROT47 are fairly easy to implement using the Unix terminal application tr; to encrypt the string "The Quick Brown Fox Jumps Over The Lazy Dog" 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' <<< "The Quick Brown Fox Jumps Over The Lazy Dog"
Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt

and the same string 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 following commands:[17]

M-x toggle-rot13-mode
M-x rot13-other-window
M-x rot13-region

and in the Vim text editor, one can ROT13 a buffer with the command:[18]

ggg?G

Python[]

In Python, the module this is implemented using ROT13:[19]

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

>>> with open(this.__file__) as f:
...     print(f.read())
s = """Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""

d = {}
for c in (65, 97):
    for i in range(26):
        d[chr(i+c)] = chr((i+13) % 26 + c)

print("".join([d.get(c, c) for c in s]))

The module codecs provides 'rot13' text transform.[20]

>>> import codecs
>>> print(codecs.encode(this.s, 'rot13'))
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Ruby[]

Inputting an array of single string characters it returns the encoded message as an array of characters(strings).This version uses ruby 2.5.5p157.

def rot13(secret_messages)
  alpha = 'abcdefghijklmnopqrstuvwxyz'.split('')
  nstrr = []
  secret_messages.map {|word|
      alpha.each_with_index {|c,i|
        if word == c
          nstrr << alpha[(i+13)%26].to_s
        end
      }
      #after every word
        if word == " "
          nstrr << " ".to_s
        end
  }
  return nstrr
end
puts ['h','e','l','l','o',' ','w','o','r','l','d']
puts " "
puts rot13(['h','e','l','l','o',' ','w','o','r','l','d'])
#uryyb jbeyq

See also[]

References[]

  1. ^ Early uses of ROT13 found in the Google USENET archive date back to 8 October 1982, posted to the net.jokes newsgroup.[5][6]
  1. ^ Christopher Swenson (17 March 2008). Modern Cryptanalysis: Techniques for Advanced Code Breaking. John Wiley & Sons. p. 5. ISBN 9780470135938.
  2. ^ a b c d Schneier, Bruce (1996). Applied Cryptography (Second ed.). John Wiley & Sons. pp. 11. ISBN 0-471-11709-9.
  3. ^ Kahn, David. The Codebreakers: The Story of Secret Writing. New York: Macmillan. ISBN 0-684-83130-9.
  4. ^ Simanek, Donald E. (2012). "Perpetual Futility: A short history of the search for perpetual motion". The Museum of Unworkable Devices.
  5. ^ desoto!gog (8 October 1982). "very mildly obscence joke, shift=13". Newsgroupnet.jokes.
  6. ^ utcsrgv!dave (8 October 1982). "encrypted jokes". Newsgroupnet.jokes.
  7. ^ a b c Raymond, Eric S. (ed.) (29 December 2003). "ROT13". The Jargon File, 4.4.7. Retrieved 19 September 2007.CS1 maint: extra text: authors list (link)
  8. ^ Ferner, Matt (9 December 2010). "How to Hide Email Addresses From Spam Bots". PracticalEcommerce. Retrieved 12 June 2014.
  9. ^ "On the 2ROT13 Encryption Algorithm" (PDF). Prüfziffernberechnung in der Praxis. 25 September 2004. Retrieved 20 September 2007.
  10. ^ Hollebeek, Tim; Viega, John. "Bad Cryptography in the Netscape Browser: A Case Study". Reliable Software Technologies. CiteSeerX 10.1.1.15.9271. Cite journal requires |journal= (help)
  11. ^ Perens, Bruce (1 September 2001). "Dimitry Sklyarov: Enemy or friend?". ZDNet News. Retrieved 3 February 2011.
  12. ^ "ROT13 is used in Windows". 24 July 2006. Retrieved 15 December 2016.
  13. ^ De Mulder, Tom. "ROT13 Words". Furrfu!. Retrieved 19 September 2007.
  14. ^ Westley, Brian (1989). "westley.c". IOCCC. Retrieved 13 August 2007.
  15. ^ "Furrfu". Foldoc. 25 October 1995. Retrieved 3 October 2016.
  16. ^ "5.13 Obfuscating Data". The GNU C Library Reference Manual. Free Software Foundation. 3 December 2006. Retrieved 2 August 2019.
  17. ^ "Rmail Rot13 – GNU Emacs Manual". www.gnu.org.
  18. ^ "Best of VIM Tips, gVIM's Key Features zzapper". rayninfo.co.uk. 3 March 2016. Archived from the original on 3 March 2016.
  19. ^ "cpython/this.py at main · python/cpython". GitHub. 13 November 2021.
  20. ^ "codecs — Codec registry and base classes — Python 3.9.6 documentation". docs.python.org.

External links[]

Retrieved from ""