"Implement a caesar cipher that takes in a string and the shift factor and then outputs the modified string."
"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."
- It splits the string into individual characters
- It ignores all characters that aren't letters
- Each character is converted into its integer ordinal
- It then uses logic to determine how to shift the ordinal integer
- If the shift pushes the integer over the alphabet's wrap point, it will wrap back around to the beginning or end of the alphabet
- The ordinal is then converted back to a letter using its new, shifted ordinal.
A Success!
I was able to remember a much easier way to accomplish the Caesar Cipher. The challenging part of this exercise is not shifting the letter to another letter. The hardest part is getting the letters to wrap around the end and beginning of the alphabet. For example, "Z" plus a shift of 1 should return "A", and "A" plus a shift of -1 should return "Z".
Instead of using many if statements, I was able to use an equation to wrap around the beginning and end of the alphabet. This wouldn't have been possible without the modulo operator. I was able to craft the majority of the equation by myself.