1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-07-18 02:20:12 +02:00
programming-challenges/challenges/caesar-cipher
2023-08-21 23:11:08 +02:00
..
solutions fix(solutions): memory issues thanks to -fsanitize=address flag with gcc 2023-08-10 11:13:06 +02:00
test feat(challenges): add caesar-cipher 2021-06-25 13:45:14 +02:00
README.md feat(challenges): add single-number 2023-08-21 23:11:08 +02:00

caesar-cipher

Created by @theoludwig on 25 June 2021.

Instructions

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of -3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.

Example of the alphabet with a shift of +3 (shift to the right)

Alphabet original   : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Alphabet rotated +3 : DEFGHIJKLMNOPQRSTUVWXYZABC

Create a function that will return the sentence after shifting the alphabet.

  • If it is a positive number then we shift the alphabet to the right
  • If it is a negative number then we shift the alphabet to the left

Example of Inputs

'ANTHONY' # a character string (all capital letters)
'-2' # an integer, the shift in the alphabet

Source

Wikipedia - Caesar cipher

Examples

See the test folder for examples of input/output.