ROT-13

Introduction

ROT-13 is the name given to the special case of the Caesar Shift Cipher where the shift value is 13. This gives the following cipher alphabet,

PlainABCDEFGHIJKLMNOPQRSTUVWXYZ
CipherNOPQRSTUVWXYZABCDEFGHIJKLM

A message encrypted using ROT-13 can be decrypted by reapplying the cipher. The cipher is the inverse of itself. Encrypt your cipher text with ROT-13 and you get the plain text message back.

ROT-13 is not the most secure of ciphers and was rarely used by anyone wishing to keep information secure. It was used widely in Usenet groups for obscuring text (like people do with spoilers on game fora) and is often used as a less-than-generous comparison for encryption systems perceived to have weaknesses that can be exploited.

Programming The Cipher

This one is pretty easy, just the same approach as the Caesar Shift with a shift value of 13.

plain ← "The secret is out."
shift ← 13
upper ← UPPERCASE(plain)
cipherText ← ""
FOR letter ← 0 TO upper.LENGTH - 1
   tmpASC ← ASCII CODE OF upper[letter]
   IF tmpASC > = 65 AND tmpASC <= 90 THEN
      tmpASC ← tmpASC + shift
      IF tmpASC<65 THEN tmpASC ← tmpASC + 26
      IF tmpASC>90 THEN tmpASC ← tmpASC - 26
      cipherText ← cipherText + CHARACTER(tmpASC)
   ELSE
      cipherText ← cipherText + upper[letter]
   END IF
END FOR
OUTPUT cipherText

Challenges

The interesting thing about ROT-13 is that, when some words are encrypted, they form other words. The word 'tang' encrypts to 'gnat'. The words are the reverse of each other and, together, form a palindrome. ROT-13 throws up lots of quirks like that.

Search the WWW for some scrabble word lists and write a program that finds words that share this property. A more powerful approach might be to use an API for a dictionary. If the lists you find are organised by word length or separated by starting letter, that might speed up the search. Either way, you only need to get one successful execution to uncover some word pairs. Here are a few

GNATTANG
BARFONES
NAGANT
NOWHEREABJURER
NOONABBA
BALKONYX
CHAPUN
CRAGPENT
ENVYRAIL
EBBSROOF
FURSHE
NANAHA

An alternative would be to implement the spoiler obscuring technique in an HTML page using PHP, Javascript or jQuery to reformat any text marked up to be encrypted with ROT-13.