Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rot13(str) {
- var arr = [];
- var newStr = "";
- str = str.replace(/[^a-zA-Z0-9 !?.]+/g, "").toUpperCase();
- alert(str);
- for (var i = 0; i < str.length; i++) {
- if (str[i] >="A" && str[i] <="M" ) {
- arr.push(str.charCodeAt(i) + 13);
- }
- else if (str[i] >="N" && str[i] <="Z") {
- arr.push(str.charCodeAt(i) - 13);
- } else {
- arr.push(str.charCodeAt(i));
- }
- }
- for (var j = 0; j < arr.length; j++) {
- newStr += String.fromCharCode(arr[j]);
- }
- return newStr;
- }
- // Change the inputs below to test
- rot13("SERR PBQR PNZC");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement