Skip to content

Instantly share code, notes, and snippets.

@dsoares
Created Jan 27, 2016
Embed
What would you like to do?
ROT13 in Javascript
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;
}
@dsoares

This comment has been minimized.

Copy link
Owner Author

@dsoares dsoares commented Dec 7, 2020

@ATmel91 care to explain?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment