Skip to content

Instantly share code, notes, and snippets.

@i-anshuman
Created November 14, 2019 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i-anshuman/46c5c3498af51e3915f3939ec3194ace to your computer and use it in GitHub Desktop.
Save i-anshuman/46c5c3498af51e3915f3939ec3194ace to your computer and use it in GitHub Desktop.
FreeCodeCamp: Caesars Cipher
'use strict';
const rot13 = (str) => {
const decrypted = [...str].map(c => {
let charCode = c.charCodeAt(0);
if (charCode >= 65 && charCode < 78) {
charCode += 13;
}
else if (charCode >= 78 && charCode <= 90) {
charCode -= 13;
}
return charCode;
});
return String.fromCharCode(...decrypted);
}
console.log(rot13("SERR PBQR PNZC. LBH QVQ VG!"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment