CIS 428 Introduction to Cryptography

Barbara Nostrand, Ph.D.

Electrical Engineering and Computer Science

Laboratory 1 - Getting Started with ROT13


ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple Substitution cipher 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".  (Horrocks, Bruce (2003) UCSM Cabal Circular #207-a. ) ROT13 is a variation of the Caesar cipher,  developed in ancient Rome.

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 no real cryptographic security and is not normally used for such. It is often cited as a canonical example of weak encryption. ROT13 has inspired a variety of letter and word games on-line, and is frequently mentioned in newsgroup conversations.

The cipher is also sometimes known as EBG13 or EBG-13 because "EBG13" is "ROT13" in ROT13.

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


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.  A becomes N, B becomes O, and so on up to M, which becomes Z, then the sequence reverses: 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.  (Schneier,  Bruce (1996).  Applied Cryptography. )

ROT13(ROT13(x)) = ROT26(x) = x for any 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:


For example, in the following joke, the punchline has been obscured by ROT13:

How can you tell an extrovert from an
introvert at NSA? Va gur ryringbef,
gur rkgebireg ybbxf ng gur BGURE thl'f fubrf. 

Transforming the entire text via ROT13 form, the answer to the joke is revealed:

Ubj pna lbh gryy na rkgebireg sebz na
vagebireg ng AFN? In the elevators,
the extrovert looks at the OTHER guy's shoes.

A second application of ROT13 would restore the original.


ROT13 was in use in the net.jokes newsgroup by the early 1980s.  It is used to hide potentially offensive jokes,  or to obscure an answer to a puzzle or other spoiler.  A shift of thirteen was chosen over other values,  such as three as in the original Caesar cipher,  because thirteen is the value which arranges that encoding and decoding are equivalent,  thereby allowing the convenience of a single command for both.  ROT13 is typically supported as a built-in feature to newsreading software. 

ROT13 is equivalent to an encryption algorithm known as a Caesar cipher,  attributed to Julius Caesar in the 1st Century BC.  (Kahn,  David (1996) The Codebreakers:  The Story of Secret Writing. ) 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.  (Schneier,  Bruce (1996) Applied Cryptography. ) Because of its utter unsuitability for real secrecy,  ROT13 has become a catchphrase to refer to any conspicuously weak encryption scheme.  In December 1999,  it was found that Netscape Communicator used ROT-13 as part of an insecure scheme to store email passwords.  (Hollebeek,  Tim;  Viega,  John.  (2001) Bad Cryptography in the Netscape Browser:  A Case Study) Windows XP uses ROT13 on some of its registry keys.  (Ferri,  Vic (2007) The Count Keys in the Windows Registry. )

Letter games and net culture

ahanun antnag
balkonyx barone
barfones beor
binova ebbsroof
envyrail erre
errsreef flapsync

ROT13 provides an opportunity for letter games.  Some words will,  when transformed with ROT13,  produce another word.  The longest example in the English language is the pair of 7-letter words abjurer and nowhere;  there is also the 7-letter pair chechen and purpura.  Other examples of words like these are shown in the table.  (De Mulder,  Tom.  ROT13 Words.)

The 1989 International Obfuscated C Code Contest (IOCCC) included an entry by Brian Westley.  Westley's computer program can be ROT13'd or reversed and still compiles correctly.  Its operation,  when executed,  is either to perform ROT13 encoding on,  or to reverse its input.  (Westley, Brian (1989). westley.c.  IOCCC.)

Software Engineering

Your task is to construct a rotation cipher system which: 

There are two possible methods for accomplishing this task.  One involves a translation table.  The other uses modular arithmetic to compute the shift. 

Last modified: 2008 JAN 20