How to use 'rot13 javascript' in JavaScript

Every line of 'rot13 javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
14function rot13(str) {
15 let response = [];
16 let strLength = str.length;
17
18 for (let i = 0; i < strLength; i++) {
19 const char = str.charCodeAt(i);
20
21 if (char < 65 || (char > 90 && char < 97) || char > 122) {
22 response.push(str.charAt(i));
23 } else if ((char > 77 && char <= 90) || (char > 109 && char <= 122)) {
24 response.push(String.fromCharCode(str.charCodeAt(i) - 13));
25 } else {
26 response.push(String.fromCharCode(str.charCodeAt(i) + 13));
27 }
28
29 }
30 return response.join("");
31}
95function rot13(string) {
96 return string.replace(/[a-zA-Z]/g, function (c) {
97 return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);
98 })
99}

Related snippets