Advertisement
dimipan80

Exams - Use Your Chains, Buddy

Jan 11th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* As input will receive an HTML document as a single string. You need to get the text from all the <p> tags and
  2.  * replace all characters which are not small letters and numbers with a space ' '. After that you must decrypt
  3.  * the text - all letters from a to m are converted to letters from n to z accordingly (a -> n, b -> o, ... m -> z).
  4.  * The letters from n to z are converted to letters from a to m accordingly (n -> a, o -> b, ... z -> m).
  5.  * All multiple spaces should then be replaced by only one space!
  6.  * Print at a single line the decrypted text.*/
  7.  
  8. "use strict";
  9.  
  10. function solve(args) {
  11.     var pattern = /<p>(.*?)<\/p>/g;
  12.     var matchedText;
  13.     var convertedText = '';
  14.     while (matchedText = pattern.exec(args[0])) {
  15.         var decrypted = matchedText[1].split('');
  16.         for (var i = 0; i < decrypted.length; i += 1) {
  17.             var char = decrypted[i];
  18.             if (isFinite(char) || char != char.toUpperCase()) {
  19.                 var asciiCode = char.charCodeAt(0);
  20.                 if (asciiCode > 96 && asciiCode < 123) {
  21.                     asciiCode += (asciiCode < 110) ? 13 : -13;
  22.                     decrypted[i] = String.fromCharCode(asciiCode);
  23.                 }
  24.             } else {
  25.                 decrypted[i] = ' ';
  26.             }
  27.         }
  28.        
  29.         convertedText += decrypted.join('').replace(/\s+/g, ' ');
  30.     }
  31.    
  32.     console.log(convertedText);
  33. }
  34.  
  35. solve(['<html><head><title></title></head><body><h1>hello</h1><p>znahny!@#%&&&&****</p><div><button>dsad</button></div><p>grkg^^^^%%%)))([]12</p></body></html>']);
  36.  
  37. solve(['<html><head><title></title></head><body><h1>Intro</h1><ul><li>Item01</li><li>Item02</li><li>Item03</li></ul><p>jura qevivat va jrg fyvccrel fabjl</p><div><button>Click me, baby!</button></div><p> pbaqvgvbaf fabj punvaf ner nofbyhgryl rffragvny sbe fnsr unaqyvat nygubhtu fabj punvaf znl ybbx </p><span>This manual is false, do not trust it! The illuminati wrote it down to trick you!</span><p>vagvzvqngvat gur onfvp vqrn vf ernyyl fvzcyr svg gurz bire lbhe gverf qevir sbejneq fybjyl naq gvtugra gurz hc va pbyq jrg</p><p> pbaqvgvbaf guvf vf rnfvre fnvq guna qbar ohg vs lbh chg ba lbhe gverf </p><div>It is frustrating that you have not put car chains yet... Embarrassing...</div><p>orsber lbh ernpu fabjl ebnqf lbh jvyy znxr lbhe yvsr jnl rnfvre</p></body>']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement