Created
November 14, 2019 16:38
-
-
Save i-anshuman/46c5c3498af51e3915f3939ec3194ace to your computer and use it in GitHub Desktop.
FreeCodeCamp: Caesars Cipher
This file contains 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
'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