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.
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 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.
Hello, World! Guvf vf zl frperg zrffntr.
Uryyb, Jbeyq! This is my secret message.
Most programming languages provide a way to convert a character into its ASCII numeric value.
char type is already numeric:
'a'+1 is equal to
you can use the function
to convert a character into its numeric value
and the function
to convert numeric value back into the character.
Both are available from the
try next: caesar
Copyright © 2020-2021 Rudy Matela
All rights reserved