Skip to content

Instantly share code, notes, and snippets.

@SethVandebrooke
Created November 15, 2023 03:20
Show Gist options
  • Save SethVandebrooke/ddf3dbc160283773aceece75910e5dfc to your computer and use it in GitHub Desktop.
Save SethVandebrooke/ddf3dbc160283773aceece75910e5dfc to your computer and use it in GitHub Desktop.
Solve Caesar Cyphers
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