SHARE
TWEET

Untitled

a guest Jan 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rot13(str) {
  2.   var newString = '';
  3.   var newCharCode;
  4.   var newChar;
  5.  
  6.   for (let i = 0; i < str.length; i++) {
  7.     newCharCode = charTransform(str[i]);
  8.     newChar = String.fromCharCode(newCharCode);
  9.     newString += newChar;
  10.   }
  11.  
  12.   return newString;
  13. }
  14.  
  15. function charTransform(char) {
  16.   var transformKey = 13;
  17.  
  18.   var capitalMax = 90;
  19.   var capitalMin = 65
  20.   var lowerCaseMax = 122;
  21.   var lowerCaseMin = 97;
  22.  
  23.   var charCode = char.charCodeAt(0);
  24.  
  25.   if (char.match(/[A-Z]/)) {
  26.     charCode += transformKey;
  27.  
  28.     if (charCode > capitalMax) {
  29.       charCode = capitalMin + (charCode - capitalMax) - 1;
  30.     }
  31.   }
  32.  
  33.   if (char.match(/[a-z]/)) {
  34.     charCode += transformKey;
  35.  
  36.     if (charCode > lowerCaseMax) {
  37.       charCode = lowerCaseMin + (charCode - lowerCaseMax) - 1;
  38.     }
  39.   }
  40.  
  41.   return charCode;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top