index | submit | rank | book

rot13 – ROT13 encryption and decryption

ROT13 is an encryption algorithm where each roman letter is replaced by the thirteenth letter coming after it in the alphabet while wrapping around Z to A. The letter A is replaced by N, B is replaced by O, C is replaced by P, …, and Z is replaced by M.

ROT13 Encryption and Decryption represented in a circle

One can perform ROT13 encryption and decryption using the above circle by replacing the letter on the outer circle by the adjacent letter in the inner circle.

The ROT13 algorithm is a symmetrical encryption algorithm, the same process is used to encrypt and decrypt data. It is a weak encryption method.

Write a program that is able to encrypt and decrypt using the ROT13 cypher. While encrypting and decrypting, your program should keep the case of letters and leave other characters unchanged.

Input and output

Input will consist of several lines of text containing ASCII characters. Output should contain the encrypted/decrypted ROT13 text.

Each line of input will contain at most 99 characters. This is for information purposes only, you do not need to check that on your submitted program – just make sure it works within this bound.

Example input

Hello, World!
Guvf vf zl frperg zrffntr.

Example output

Uryyb, Jbeyq!
This is my secret message.

Scoring

Hints

Most programming languages provide a way to convert a character into its ASCII numeric value.

In C, the char type is already numeric: 'a'+1 is equal to 'b'.

In Python, you can use the function ord to convert a character into its numeric value and the function chr to convert numeric value back into the character.

In Haskell, you can use the function ord to convert a character into its numeric value and the function chr to convert numeric value back into the character. Both are available from the Data.Char module.

try first: index-string replace gcd

try next: caesar

index | submit | rank | book

Copyright © 2020-2023 Rudy Matela
All rights reserved