Created
November 15, 2023 03:20
-
-
Save SethVandebrooke/ddf3dbc160283773aceece75910e5dfc to your computer and use it in GitHub Desktop.
Solve Caesar Cyphers
This file contains hidden or 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 CaesarSolver(str) { | |
let alphabet = 'abcdefghijklmnopqrstuvwxyz'; | |
str = str.toLowerCase(); | |
let words = str.split(/\s+/); | |
let permutations = []; | |
for (let j = 0; j < alphabet.length; j++) { | |
let list = []; | |
for (let i = 0; i < words.length; i++) { | |
let word = ""; | |
let letters = words[i].split(''); | |
for (let k = 0; k < letters.length; k++) { | |
word += alphabet[(alphabet.indexOf(letters[k]) + j)%alphabet.length]; | |
} | |
list.push(word); | |
} | |
permutations.push(list.join(' ')); | |
} | |
return permutations; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment