Created
August 1, 2016 21:59
-
-
Save AbdouSeck/577e8843e13c2973940860e41c2967a3 to your computer and use it in GitHub Desktop.
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
function rot13(encodedStr) { | |
var alphabet = "abcdefghijklmnopqrstuvwxyz".toUpperCase().split(""); | |
var codeArr = encodedStr.split(""); | |
var decodedArr = []; | |
decodedArr = codeArr.map(function(a) { | |
if(alphabet.indexOf(a)!==-1) { | |
if(alphabet.indexOf(a)<13) { | |
return alphabet[26+alphabet.indexOf(a)-13]; | |
} else { | |
return alphabet[alphabet.indexOf(a)-13]; | |
} | |
} else { | |
return a; | |
} | |
}); | |
return decodedArr.join(""); | |
} | |
console.log(rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python translation: