Created
November 23, 2017 17:34
-
-
Save JamesCalleja/f4d30ea6274254bbf8dd5abd5021cd16 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
/* | |
Wirten by James Calleja | |
32/11/2017 | |
*/ | |
function rot13(str) | |
{ | |
var strArray = str.split(""); | |
var result = []; | |
for (var i = 0; i < str.length; i++) | |
{ | |
if (strArray[i].match(/[a-zA-Z]/)) //if isAlpha() | |
{ | |
if (strArray[i].charCodeAt() -13 <= 64) | |
{ | |
result.push(String.fromCharCode(strArray[i].charCodeAt() - 13 + 26)); | |
} | |
else | |
{ | |
result.push(String.fromCharCode(strArray[i].charCodeAt() - 13)); | |
} | |
} | |
else | |
{ | |
result.push(String.fromCharCode(strArray[i].charCodeAt())); | |
} | |
} | |
return result.toString().replace(/,/g,""); | |
} | |
// Change the inputs below to test | |
rot13("SERR PBQR PNZC"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment