Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rot13(str) { // LBH QVQ VG!
- var decoded = ""; // a string variable which concatenates the decoded strings
- for (var i = 0; i < str.length; i++){
- if(str.charCodeAt(i) >= 65 && str.charCodeAt(i) <=77) {//convert letters A-M into its ascii code
- decoded += String.fromCharCode(str.charCodeAt(i) + 13);// add those letters to decode add 13 to make it N-Z
- } else if(str.charCodeAt(i) >= 78 && str.charCodeAt(i) <=90) {
- decoded += String.fromCharCode(str.charCodeAt(i) - 13);//similarly in the second if we are repeating this N-Z converting them to A-M
- }
- else {
- decoded += str[i]; //we are taking care of the characters which are not A-Z
- }
- }
- return decoded;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement