Hackerrank – Caesar Cipher

Problem Statement
A description of the problem can be found on Hackerrank.

Solution
Create a function for encrypting which takes a cipher shift as parameter as well. Check if incoming character is letter. If is lower case encrypt it using ascii number:
to_char[ascii_of_char - asci_of_a + shift) % 26 + ascii_of_a].
Similar if letter is uppercase.

I created solution in:

All solutions are also available on my GitHub.

Java

JavaScript

Scala

Ruby

Leave a Reply

Your email address will not be published. Required fields are marked *