Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. function rot13(str) { // LBH QVQ VG!
  2.  
  3. var decoded = ""; // a string variable which concatenates the decoded strings
  4. for (var i = 0; i < str.length; i++){
  5. if(str.charCodeAt(i) >= 65 && str.charCodeAt(i) <=77) {//convert letters A-M into its ascii code
  6. decoded += String.fromCharCode(str.charCodeAt(i) + 13);// add those letters to decode add 13 to make it N-Z
  7. } else if(str.charCodeAt(i) >= 78 && str.charCodeAt(i) <=90) {
  8. decoded += String.fromCharCode(str.charCodeAt(i) - 13);//similarly in the second if we are repeating this N-Z converting them to A-M
  9. }
  10.  
  11. else {
  12. decoded += str[i]; //we are taking care of the characters which are not A-Z
  13. }
  14. }
  15. return decoded;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement