Created
August 19, 2018 01:55
-
-
Save cefaijustin/c847e516e155206f1ec8c6dc032a01f6 to your computer and use it in GitHub Desktop.
Caesar Cipher Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rot13(name) { | |
if (name.length === 0) return "Submission cannot be empty."; | |
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; | |
let res = []; | |
name = name.toLowerCase().split(""); | |
for (let i = 0; i < name.length; i++) { | |
for (let j = 0; j < alphabet.length; j++) { | |
if (name[i] === alphabet[j]) { | |
if (alphabet[j + 13] === undefined) { | |
res.push(alphabet[j - 13]); | |
} else res.push(alphabet[j + 13]); | |
} | |
} | |
} | |
return res.join(""); | |
} | |
console.log(rot13("HELLO")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment