Skip to content

Instantly share code, notes, and snippets.

@IrhaAli
Created December 6, 2022 17:55
Show Gist options
  • Save IrhaAli/d39709c144bcd0aa368dbca40f2b2ee7 to your computer and use it in GitHub Desktop.
Save IrhaAli/d39709c144bcd0aa368dbca40f2b2ee7 to your computer and use it in GitHub Desktop.
Caesar Cipher
const encrypt = function(plaintext, key) {
let alphabets = [...Array(26)].map((_, i) => String.fromCharCode(i + 97));
return plaintext.split("").map(letter => (letter !== " ") ? alphabets[(alphabets.indexOf(letter) + key + 26) % 26] : " ").join("");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment