Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2016 19:43
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;
Copy link

dsoares commented Dec 7, 2020

@ATmel91 care to explain?

Copy link

smartxd3 commented Feb 6, 2022

rot13 its mean Obfuscate string by adding 13 alphabet ..
idk how to explain it but its something like this :
exp : Rot2 => "a" will be "c" in the string
"Smart" will be "Uocv" someting like this :D

Copy link

dsoares commented Feb 7, 2022

Hi @smartxd3 I know what rotN means.
My question was for @ATmel91 after his comments on December 2020:

how to confuse people: rot12
Because although it wouldn't really be a better way to encrypt messages, it would still confuse people when rot13 doesn't work because that will most likely be their first guess

that i didn't understand. I don't know why they don't appear here anymore.

Copy link

zex-git commented Feb 5, 2023

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