From c879ff1f6a712eae124bd86d3a41cf0c76160e91 Mon Sep 17 00:00:00 2001 From: Marco Cruz Date: Mon, 18 Nov 2024 16:27:10 -0600 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Add=20challenge-02=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../02-detectando-acceso-no-deseado/README.md | 26 + 2024/02-detectando-acceso-no-deseado/log.txt | 497 ++++++++++++++++++ .../solution.js | 51 ++ .../solution.test.js | 53 ++ 4 files changed, 627 insertions(+) create mode 100644 2024/02-detectando-acceso-no-deseado/README.md create mode 100644 2024/02-detectando-acceso-no-deseado/log.txt create mode 100644 2024/02-detectando-acceso-no-deseado/solution.js create mode 100644 2024/02-detectando-acceso-no-deseado/solution.test.js diff --git a/2024/02-detectando-acceso-no-deseado/README.md b/2024/02-detectando-acceso-no-deseado/README.md new file mode 100644 index 0000000..49c3beb --- /dev/null +++ b/2024/02-detectando-acceso-no-deseado/README.md @@ -0,0 +1,26 @@ +# Desafío 2: Detectando acceso no deseado + +Creo que ΩMEGA está intentando entrar en el sistema. Por ahora, es un bebé y **está siguiendo patrones muy sencillos** que podemos detectar pero está intentando crear contraseñas de administrador para acceder a la terminal. + +¿Cómo podemos detectar estos intentos de acceso? Está siguiendo estos patrones: + +- Sólo usa letras minúsculas y dígitos. +- Nunca usa dígitos después de una letra (Una vez aparecen letras, la contraseña debe continuar solo con letras) +- Si usa dígitos, siempre los usa de forma igual o creciente (si sale un 3, ya no usará después un número menor) +- Si usa letras, siempre las usa en orden alfabético igual o creciente (si sale una "b" ya no podrá usar una "a", por ejemplo) + +Algunos ejemplos para que lo entiendas perfectamente: + +```txt +1234 -> true +abc -> true +aabbcc -> true (repite pero siempre ascendente) +112233 -> true (repite pero siempre ascendente) +a123 -> false (un número después de una letra) +123abc -> true +dbce -> false (una "d" y después una "b") +``` + +Accede a este log.txt con una lista de intentos y con un programa cuenta cuántos han sido inválidos y cuántos válidos. Envía la respuesta usando el comando **submit.** + +Por ejemplo, si hay 10 intentos válidos y 5 inválidos envía el comando `submit 10true5false` diff --git a/2024/02-detectando-acceso-no-deseado/log.txt b/2024/02-detectando-acceso-no-deseado/log.txt new file mode 100644 index 0000000..382059e --- /dev/null +++ b/2024/02-detectando-acceso-no-deseado/log.txt @@ -0,0 +1,497 @@ +03345678 +ijpx +se35 +rmkvy +0469giz +0014559 +aadffgt +yb408 +rejwg +077cfv +0378 +fjjjq +skta1912 +a7d2vo +4588hnr +0469 +hhhknsty +rjqf2915 +c1am +378af +2569 +bbdjstu +svf7241 +bmkqzd +129eox +126999 +abbggrt +lhv9725 +ktjv +2467hhq +023789 +chmwz +gh58 +qrgmf +2889dfls +011235 +crrrs +rv042 +2r8pzw +2468kqw +01146777 +fghu +uzw378 +yrh1fg0 +0158rxz +2346789 +dllnorr +mr84 +97fk7wq +0479fgs +fmnu +vcn191 +8iqfp3tj +2268lwz +23366799 +bhhitwy +hn30 +k5cw +1367bdkw +223679 +hjkm +efc472 +nzxmz +0034aghv +012567 +bbfglrrs +iey5099 +f64b3 +357dm +0112369 +acnotz +op52 +ygow8gr +45cl +1122466 +fintx +qvo3239 +qdixk0h +06fy +01446678 +klnty +at33 +2u95xkh6 +115tty +23355779 +aeginqtx +mnl939 +nail +45ak +04569 +bclnqqwz +tsyz0761 +qrpv5a9a +059hks +01457 +cfilqvxx +mjap6288 +a19lsnz +156dn +1679 +hjjlouy +csb697 +9c68 +0023aexx +134456 +aggtuz +dyqe7601 +moyl +0068guvy +01578 +glqssuy +qw665 +nqno +08hv +33335889 +qqsuz +pp28 +np8zevb +78jv +3469 +aailmps +cnfs2459 +2cwhs036 +389iwy +5677 +gghjn +bg02 +z5iysbm +457gi +1188899 +lnrruy +woz173 +kqasj +1257dnr +0134 +ghkr +ew129 +caykz +3557cdru +013489 +cgixz +ol481 +ejiaydio +5699ddt +3346 +absvy +zh824 +imeh658 +09jv +12268 +addhsz +toze0819 +337f +024hht +1113 +cequ +ysg0699 +31qxo1l1 +235blz +33667 +ghmnqq +rx100 +5piyd +07bp +2599 +dikmvw +gp460 +cq4w4pk +2479cgm +0223599 +gkosz +pxc633 +qha82 +4678apt +1222359 +llmnpx +tka881 +13au7rzt +08ft +044788 +bcekltvw +uwwe3624 +6s3y5r +16bl +25789 +aboppqzz +op695 +3h7nf +337bx +01123589 +llmqsy +jym741 +3r68bdk +2788kmpt +226669 +afnorxyz +va88 +0tu7l +448pz +013799 +stuz +vtq1615 +rzjjl +0128imnx +3789 +bdjmpt +bny6434 +46j3 +19fx +0234 +efiimpq +he063 +galeealv +046jo +015577 +ktuy +ox21 +xdpwvi +2246elnt +2566 +ghjmmoz +aps226 +nw87e +039cy +14588 +abdiity +gza610 +a6gi +589dgx +bnooqzz +tii616 +lw3q +347mps +024556 +affgqty +ww128 +68ktou +0367eoru +457899 +ejloosyz +wia8680 +5yy98f +57ht +57888 +hhjlouwy +yw388 +nc32o8 +0256mwz +0444899 +fffjv +ayu672 +m2iq63 +3489jluv +01357788 +chlrwz +euby8162 +x1jb +779ac +013467 +nsxz +tf99 +tgr8i +2234gkmy +37888 +aaehqtww +aaz773 +2rdfd40 +0356hjtw +123678 +dhjxzz +jvs8920 +rejt +0338bdes +2248 +deerwz +glr6248 +oo6l +26qu +0335 +ahttxy +wr410 +36mu +247ghl +00335 +bfgku +qc00 +epugx +016hjt +34578 +abcfnv +zqgs4949 +smfei +0266cen +23359 +ajkoswyy +rhrm2663 +9wm4 +246fsy +2334 +lstz +nu835 +o1btvc +0045egiq +12279 +agppv +tpa049 +1ppx +1389dhox +00556899 +agmppx +ucv091 +g8fmx9cc +499gk +01144778 +himw +tkw1469 +hl1rpwf +68dh +1578999 +oouvxz +brd074 +jcnk7ph +5557krsv +1457 +jors +hkt601 +x9kjlpj +88ov +1344577 +chjquvxz +pkd8881 +knk9 +46qu +000668 +cdemrsv +nge4032 +jniteqgs +3389ioot +1357788 +ehmmp +pkv473 +p46ktk +15hj +02233 +fjkkt +wzla0079 +i3c9r7n +0347bgr +0124445 +bnqrssw +fen6894 +7gj3 +4467aix +34458 +adfqtvvx +bci6836 +mvzh +0166fiks +02338899 +ijlnootx +mj76 +3ek7oarr +4677ansu +35567 +bdgjjrrz +mzcn0818 +y6grtw3p +1357gmp +144479 +bfmp +loo946 +xhp4a +1444clsy +0345558 +bhikuvy +yp57 +ryg3dnk7 +6889jlx +00015689 +ghlnuuv +ktky4928 +f9de +002cq +5888 +fnprvwy +vszk1907 +r94cu +014gn +45688 +cfikkkty +mvw517 +v6yy +124cei +015778 +bgqrwz +tuu595 +m0idt2l +2447gisy +0047 +bhmoqss +beo9166 +1k1v6 +0268fhlt +33447999 +cfhr +xdx8595 +l59vv62b +139flv +3578 +bhkmqrtw +jng386 +9zif01d +1466ikox +1344478 +akmm +ccm5112 +lv7cjv +048mx +023799 +hikox +kekz0942 +7hwrzw9r +069am +223355 +efhhpz +kgm693 +q25a6qo +124mnv +233478 +bdfhlsu +nga491 +4bnf +1245nwyz +033379 +hikknpuw +swm0799 +f3fkd +346bp +2444468 +elpq +jp49 +uz7chq +0129ffhx +003369 +huvwyy +bn749 +lf7mv2e +1449pqy +2468 +fgkqruuua +qkh720 +ocamx +0145ghnv +clmoowxy +do00 +1snxwb +0199pwz +03578 +dffmsvx +qd524 +otrscz +66mw +01234 +iijlqt +xw67 +bewv +058npz +3568 +beiilst +rdu268 +qro1fujj +79an +3334778 +ijnpqvx +udms5941 +kn5g +0003ltx +2446678 +acgptu +rrr583 +uyeweze +1347ghkp +1137 +fjjnovz +ici7617 +l241ju9 +1678osx +03688 +bbbfmmy +lqe001 +yl3bit +2268aot +12377789 +efhpww +gff6718 +y6269zk +0349inno \ No newline at end of file diff --git a/2024/02-detectando-acceso-no-deseado/solution.js b/2024/02-detectando-acceso-no-deseado/solution.js new file mode 100644 index 0000000..2c50474 --- /dev/null +++ b/2024/02-detectando-acceso-no-deseado/solution.js @@ -0,0 +1,51 @@ +/* eslint-disable no-restricted-syntax */ +const fs = require('fs'); + +function isValidPassword(password) { + let hasLetters = false; + let lastDigit = -1; + let lastChar = ''; + + for (const char of password) { + if (/\d/.test(char)) { + if (hasLetters) return false; + const digit = Number(char); + if (digit < lastDigit) return false; + lastDigit = digit; + } else if (/[a-z]/.test(char)) { + hasLetters = true; + if (char < lastChar) return false; + lastChar = char; + } else { + return false; + } + } + + return true; +} + +function countValidInvalidPasswords(filePath) { + const data = fs.readFileSync(filePath, 'utf8'); + const passwords = data + .split('\n') + .map((pwd) => pwd.trim()) + .filter(Boolean); + + let validCount = 0; + let invalidCount = 0; + + passwords.forEach((password) => { + if (isValidPassword(password)) { + validCount++; + } else { + invalidCount++; + } + }); + + return `submit ${validCount}true${invalidCount}false`; +} + +module.exports = { + isValidPassword, + countValidInvalidPasswords, +}; diff --git a/2024/02-detectando-acceso-no-deseado/solution.test.js b/2024/02-detectando-acceso-no-deseado/solution.test.js new file mode 100644 index 0000000..e13f238 --- /dev/null +++ b/2024/02-detectando-acceso-no-deseado/solution.test.js @@ -0,0 +1,53 @@ +const { isValidPassword, countValidInvalidPasswords } = require('./solution'); + +describe('2024 | 02-detectando-acceso-no-deseado', () => { + describe('isValidPassword', () => { + const TEST_CASES = [ + { + input: '1234', + output: true, + }, + { + input: 'abc', + output: true, + }, + { + input: 'aabbcc', + output: true, + }, + { + input: '112233', + output: true, + }, + { + input: 'a123', + output: false, + }, + { + input: '123abc', + output: true, + }, + { + input: 'dbce', + output: false, + }, + ]; + + it.each(TEST_CASES)('$input should return $output', ({ input, output }) => { + expect(isValidPassword(input)).toBe(output); + }); + }); + + describe('countValidInvalidPasswords', () => { + const TEST_CASES = [ + { + input: './2024/02-detectando-acceso-no-deseado/log.txt', + output: 'submit 299true198false', + }, + ]; + + it.each(TEST_CASES)('should return $output', ({ input, output }) => { + expect(countValidInvalidPasswords(input)).toBe(output); + }); + }); +}); From c66f7e8bec9145e12a9caeb8215ca1e11c17f64a Mon Sep 17 00:00:00 2001 From: Marco Cruz Date: Mon, 18 Nov 2024 16:27:49 -0600 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20Update=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d8e11f0..32cbdd0 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ npm run test 'year'/'folder-name'/solution.test.js | # | Challenge |Status | My Solution | | :-: | ----------------------------------------------------------------- |:----: | :------------------------------------------------------------------------------------------------------: | | 01 | [!Consigue acceso a la terminal!](https://codember.dev) | ✅ | [here](./2024/01-consigue-acceso-a-la-terminal/solution.js) | +| 02 | [Detectando acceso no deseado](https://codember.dev) | ✅ | [here](./2024/02-detectando-acceso-no-deseado/solution.js) | ## 🎯 2023 Challenges