Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. function rot13(str) {
  2. var arr = [];
  3. var newStr = "";
  4. str = str.replace(/[^a-zA-Z0-9 !?.]+/g, "").toUpperCase();
  5. alert(str);
  6. for (var i = 0; i < str.length; i++) {
  7. if (str[i] >="A" && str[i] <="M" ) {
  8. arr.push(str.charCodeAt(i) + 13);
  9. }
  10. else if (str[i] >="N" && str[i] <="Z") {
  11. arr.push(str.charCodeAt(i) - 13);
  12. } else {
  13. arr.push(str.charCodeAt(i));
  14. }
  15. }
  16.  
  17.  
  18. for (var j = 0; j < arr.length; j++) {
  19. newStr += String.fromCharCode(arr[j]);
  20. }
  21. return newStr;
  22.  
  23. }
  24.  
  25.  
  26. // Change the inputs below to test
  27. rot13("SERR PBQR PNZC");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement