diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..fbb5dc3 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,29 @@ +{ + "parserOptions": { + "ecmaVersion": 6 + }, + "rules": { + "keyword-spacing": 1, + "space-before-function-paren": [1, "never"], + "eqeqeq": 1, + "space-infix-ops": 1, + "comma-spacing": 1, + "brace-style": 1, + "no-multiple-empty-lines": 1, + "camelcase": 1, + "func-call-spacing": 1, + "key-spacing": 1, + "semi": 1, + "no-floating-decimal": 1, + "no-multi-spaces": 1, + "object-property-newline": 1, + "padded-blocks": [1, "never"], + "space-before-blocks": 1, + "space-in-parens": 1, + "spaced-comment": 1, + "quotes": [1, "single"], + "id-length": [1, { "exceptions": ["i", "j", "x"] }], + "indent": [1, 2], + "no-array-constructor": 1 + } +} diff --git a/ASSETS/DOCS/diagramadeFlujo.jpg b/ASSETS/DOCS/diagramadeFlujo.jpg new file mode 100644 index 0000000..b056fee Binary files /dev/null and b/ASSETS/DOCS/diagramadeFlujo.jpg differ diff --git a/JS/app.js b/JS/app.js new file mode 100644 index 0000000..f4e0c79 --- /dev/null +++ b/JS/app.js @@ -0,0 +1,64 @@ +let phrase = prompt('Write here'); +let phraseArr = phrase.split(''); +// console.log(Array.isArray(phraseArr)); // ["abc"] + +const cipher = word => { + // debugger; + // Verificando si es una palabra y diferente de vacia además de que no tenga espacios. + if (Number.isNaN(parseInt(word)) && word !== '') { + let strCipher = ''; + let positionOfLetter; + // En lugar de for se usará filter para recorrer la frase palabra por palabra + let positionPhraseLetter = phraseArr.filter((position) => { // Iteración de las palabras de phrase + positionOfLetter = phraseArr.indexOf(position); + // console.log(positionOfLetter); // retorna su posición + // // regresa el codigo en número ascii + let letter = word.charCodeAt(positionOfLetter); + // console.log(letter); // retorna su codigo ascii + // para mayúsculas + if (letter >= 65 && letter <= 90) { + let num = (letter - 65 + 33) % 26 + 65; + console.log(num); + strCipher += String.fromCharCode(num); + console.log(strCipher); + // para minúsculas + } else if (letter >= 97 && letter <= 122) { + // usando fórmula + let num2 = (letter - 97 + 33) % 26 + 97; + // num a string + strCipher += String.fromCharCode(num2); + console.log(strCipher); + } + }); + console.log(positionOfLetter); + return alert(`Your cipher number is ${strCipher}`); + } else { + alert('Write Again, please.'); + } +}; +cipher(phrase); + + +const decipher = word => { + if (Number.isNaN(parseInt(word)) && word !== '') { + let strDecipher = ''; + let positionOfLetter; + let positionPhraseLetter = phraseArr.filter((position) => { + positionOfLetter = phraseArr.indexOf(position); + let letter = word.charCodeAt(positionOfLetter); + if (65 <= letter && letter <= 90) { + // añadir la formula y almaceno en num + let num = (letter - 65 + 26) % 26 + 65; + strDecipher += String.fromCharCode(num); + } else if (97 <= letter && letter <= 122) { + let num2 = (letter - 97 + 26) % 26 + 97; + strDecipher += String.fromCharCode(num2); + } + }); + return alert(`Your decipher number is ${strDecipher}`); + } + // else { + // alert('Write Again, please.'); + // } +}; +decipher(phrase); \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..9b293ee --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + +
+ +Write a word, and we show you the same word coded and decoded.
+ + + \ No newline at end of file