Created
January 27, 2016 19:43
-
-
Save dsoares/c65f1bacac0acd46fd9f to your computer and use it in GitHub Desktop.
ROT13 in Javascript
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(str) { // LBH QVQ VG! | |
var re = new RegExp("[a-z]", "i"); | |
var min = 'A'.charCodeAt(0); | |
var max = 'Z'.charCodeAt(0); | |
var factor = 13; | |
var result = ""; | |
str = str.toUpperCase(); | |
for (var i=0; i<str.length; i++) { | |
result += (re.test(str[i]) ? | |
String.fromCharCode((str.charCodeAt(i) - min + factor) % (max-min+1) + min) : str[i]); | |
} | |
return result; | |
} |
too bad I haven't learned regex yet
thanks nice
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @smartxd3 I know what rotN means.
My question was for @ATmel91 after his comments on December 2020:
that i didn't understand. I don't know why they don't appear here anymore.