CSCI 116

Project #9: ROT13

 

ROT13 was a technique used in the early days of file sharing and newsgroups that allowed potentially offensive material to be shared without offending anyone who didn’t want to be offended, or to prevent showing “spoilers” to someone who didn’t want to see them.  The text of the potentially offensive item or spoiler would be shifted 13 characters in the alphabet (with ‘z’ wrapping around to ‘a’) and the resulting text would be sent.  So for instance, an ‘a’ would become an ‘n’, the word ‘did’ would become ‘qvq’, ‘Hello’ would become ‘Uryyb’, etc.  If someone wanted to see the original text, they would shift the text 13 characters again, and the original text would reappear.  You are to write a program to read in a line of text and to perform ROT13 on it.  You are to print out the resulting text.  Your program should loop until the user enters a single ‘0’ (zero) as the text, at which point it should exit.  Note that case should be preserved (as in ‘Hello’, above).

 

Here is a sample output:

 

Z:\Spring 2015\CSCI 116>ROT13

Enter a string to translate:  Your Mother wears army boots.

Lbhe Zbgure jrnef nezl obbgf.

Enter a string to translate (‘0’ to exit):  The butler did it.

Gur ohgyre qvq vg.

Enter a string to translate (‘0’ to exit):  Guvf jvyy or bhe frperg.

This will be our secret.

Enter a string to translate (‘0’ to exit):  0

Press any key to continue...

 

Z:\Spring 2015\CSCI 116>

 

Here are some more examples for you to try:

 

If you took away an elephants trunk how would it smell?

Gehax be ab gehax vg jbhyq fgvyy fzryy cerggl onq!

 

What weighs 5,000 lbs and wears glass slippers?

Pvaqreryrcunag.

 

How do you make instant elephant?

Bcra gur cnpxntr, nqq jngre, naq eha!

 

What time is it when ten elephants are chasing you?

Gra nsgre bar!

 

What game do elephants like to play most?

Fdhnfu.

 

Why do elephants wear red toenail polish?

Bbcf, fbeel, ab cbyvfu wbxrf nyybjrq.

 

Why do elephants paint their toenails red?

Fb gurl pna uvqr va n fgenjoreel cngpu.

 

Why do elephants hide in strawberry patches?

Fb gurl pna whzc bhg naq fgbzc ba crbcyr.

 

Why do elephants stomp on people?

Gung vf ubj gurl cynl fdhnfu.

 

Why did the elephant cross the road?

Gb fdhnfu gur puvpxra ba gur bgure fvqr!

 

(taken from http://www.azkidsnet.com/elephant.htm)