Rot13

Published on 20 November 2018 (Updated: 22 January 2024)

Welcome to the Rot13 page! Here, you'll find a description of the project as well as a list of sample programs written in various languages.

This article was written by:

Description

ROT13 is a letter substitution cipher where every letter is replaced by the letter 13 letters after it alphabetically and wrapping from Z to A if necessary:

ABCDEFGHIJKLMNOPQRSTUVWXYZ -> NOPQRSTUVWXYZABCDEFGHIJKLM

As a result, encrypted strings can be decrypted using the same algorithm:

NOPQRSTUVWXYZABCDEFGHIJKLM -> ABCDEFGHIJKLMNOPQRSTUVWXYZ

Requirements

Write a sample program that takes a string of text as input. It should then encrypt the inputted text using ROT13 and output the result to the console.

$ ./rot13.lang "the quick brown fox jumped over the lazy dog"
gur dhvpx oebja sbk whzcrq bire gur ynml qbt

The solution should handle both lower case and capital letters

$ ./rot13.lang "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG"
GUR DHVPX OEBJA SBK WHZCRQ BIRE GUR YNML QBT

Any characters/symbols besides a-z and A-Z should be ignored.

$ ./rot13.lang "The quick brown fox jumped. Was it over the lazy dog?"
Gur dhvpx oebja sbk whzcrq. Jnf vg bire gur ynml qbt?

In addition, there should be some error handling for situations where the user doesn't supply any input.

Testing

Every project in the Sample Programs repo should be tested. In this section, we specify the set of tests specific to Rot13. In order to keep things simple, we split up the testing as follows:

Rot13 Valid Tests

Description Input Output
Sample Input Lower Case "the quick brown fox jumped over the lazy dog" "gur dhvpx oebja sbk whzcrq bire gur ynml qbt"
Sample Input Upper Case "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG" "GUR DHVPX OEBJA SBK WHZCRQ BIRE GUR YNML QBT"
Sample Input Punctuation "The quick brown fox jumped. Was it over the lazy dog?" "Gur dhvpx oebja sbk whzcrq. Jnf vg bire gur ynml qbt?"

Rot13 Invalid Tests

Description Input
No Input  
Empty Input ""

All of these tests should output the following:

Usage: please provide a string to encrypt

Articles