beyondgrader.com Logo
DemoBrowseAboutTeamLogin

Rot 13 Encryption

Geoffrey Challen // 2020.9.0

Encryption is an ancient practice of trying to conceal information by scrambling it. Modern encryption techniques are incredibly strong and mathematically sound. But in the past, simpler and more primitive methods were used.

Let's implement a form of encryption known as a Caesar Cipher, sometimes also known as Rot-13 encryption. (Rot for rotation, and 13 for one amount that you might rotate.) Here is how it works. Given a String and an amount to rotate, we replace each character in the String with a new character determined by rotating the original character through a given rotation String. For example, given the rotation String "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ", "ABC" rotated 3 would be "DEF", and rotated -1 would be " AB". (Note the space at the end of the rotation String.)

Declare and implement a function called encrypt that, given a String and an int amount, returns the passed String "encrypted" by rotating it the given amount. ("Encrypted" is in scare quotes because this is not by any means a strong method of encryption!) Use the rotation String provided above. If the passed String is null you should return null. Note that rotation may be negative, which will require some additional care.

String encrypt(String input, int rotation) {
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
return input;
}