Skip to content

Instantly share code, notes, and snippets.

@LucianBuzzo
Created March 15, 2023 13:25
Show Gist options
  • Select an option

  • Save LucianBuzzo/44192bcad8702d3a760b61483976d020 to your computer and use it in GitHub Desktop.

Select an option

Save LucianBuzzo/44192bcad8702d3a760b61483976d020 to your computer and use it in GitHub Desktop.
Recursive Caesar Cipher
const recursiveCaesarCipher = (shift, text) => {
const inner = (shift, [ letter, ...rest]) => {
const index = alphabet.indexOf(letter);
const newIndex = (index + shift) % alphabet.length;
return [
index >= 0 ? alphabet[newIndex] : letter,
...rest.length ? inner(shift, rest) : []
]
}
return inner(shift, [ ...text ]).join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment