Advertisement
Todorov_Stanimir

02. Activation Keys 1-st Decision

Jul 26th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function activationKeys(input) {
  2.  
  3.     let arrayKeys = input[0].split('&');
  4.     let output = [];
  5.     let pattern1 = /\b[\a-z\d\s]{16}\b/gi;
  6.     let pattern2 = /\b[\a-z\d\s]{25}\b/gi;
  7.     arrayKeys.forEach(key => {
  8.         if (key.length === 16 && key.match(pattern1)) {
  9.             let newKey = [];
  10.             for (i = 0; i < 16; i += 4) {
  11.                 newKey.push(key.substr(i, 4));
  12.             }
  13.             output.push(newKey.join('-'));
  14.         } else if (key.length === 25 && key.match(pattern2)) {
  15.             let newKey = [];
  16.             for (i = 0; i < 25; i += 5) {
  17.                 newKey.push(key.substr(i, 5));
  18.             }
  19.             output.push(newKey.join('-'));
  20.         }
  21.     });
  22.     for (let line = 0; line < output.length; line++) {
  23.         let currentKey = output[line].split('');
  24.         for (let index = 0; index < currentKey.length; index++) {
  25.             if (String(Number(currentKey[index]))!=='NaN') {
  26.                 currentKey[index] = 9 - Number(currentKey[index]);
  27.             } else {
  28.                 currentKey[index] = currentKey[index].toUpperCase();
  29.             }
  30.         }
  31.         currentKey = currentKey.join('');
  32.         output[line] = currentKey;
  33.     }
  34.     console.log(output.join(', '));
  35. }
  36. activationKeys(['t1kjZU764zIME6Dl9ryD0g1U8&-P4*(`Q>:x8\yE1{({X/Hoq!gR.&rg93bXgkmILW188m&KroGf1prUdxdA4ln&U3WH9kXPY0SncCfs']);
  37. activationKeys(['xPt8VYhUDalilWLvb6uMSGEEf&KWQ{R.@/HZCbbV++1o]V+oG@@fF^93&y6fT5EGFgZHqlFiS'])
  38.  
  39. // Result:
  40. // T8KJZ-U235Z-IME3D-L0RYD-9G8U1, RG06-BXGK-MILW-811M, KROG-F8PR-UDXD-A5LN, U6WH-0KXP-Y9SN-CCFS
  41. // XPT1V-YHUDA-LILWL-VB3UM-SGEEF, Y3FT-4EGF-GZHQ-LFIS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement