ROT13 encoder/decoder
- Not to be confused with ROT-13.
A ROT13 encoder/decoder is a program that applies the ROT13 cipher to its input text. ROT13 is a simple Caesar cipher that is its own inverse. It has no serious use in cryptography, but it's a popular problem and a simple way to hide messages that are meant for others to read at their own discretion (for example, puzzle solutions and plot spoilers).
A ROT13 encoder/decoder reads in data, and changes letters A, B, C, D ... W, X, Y, Z (as well the ones in lowercase) to N, O, P, Q ... J, K, L, M. The name "ROT13" comes from this behaviour: each letter is being rotated half-way around the Roman alphabet, that is, 13 positions.
For example, if we give a ROT13 program the following data
Hello world! ;)
it should print out
Uryyb jbeyq! ;)
Every character that is not in the Roman alphabet, i.e. which does not have a decimal ASCII value in the ranges 65-90 or 97-122, remains the same, like the ;)
in the above example.
As ROT13 is its own inverse, there is no need to write separate encoder and decoder programs - a single encoder/decode program does both jobs. For example, giving a ROT13 program the data
Uryyb jbeyq! ;)
should return it back to the form it was in the beginning, that is
Hello world! ;)
External resources
- The ROT13 Page (from the Wayback Machine; retrieved on 15 June 2013) contained ROT13 implementations in many languages.