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/index.html b/index.html new file mode 100644 index 0000000..b212e40 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + Cifrado Cesar + + + + + + + \ No newline at end of file diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..96d5650 --- /dev/null +++ b/js/app.js @@ -0,0 +1,49 @@ +//Se crea la función para preguntar al usuario la frase a través de un prompt +function askPhrase() { + do { + var answer = prompt('Ingresar la frase a cifrar'); + } while ( answer === null || answer === ''); +} + +//Se crea la función cipher. + +function cipher(str) { + + var arr = []; // Se crea un array vacio para guardar los códigos de las letras en ASCII. + + for (var i = 0; i < str.length; i++) { + + if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) { //Usamos str.charCodeAt(i) para hallar su equivalente en ASCII + arr.push((str.charCodeAt(i) - 65 + 33) % 26 + 65); //Con arrr.push(), agregamos al arr la conversión de las letras + } else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 120) { // Se usa la fórmula brindada por Michelle que es la sgte: ((x-65+n)%26+65) + arr.push((str.charCodeAt(i) - 97 + 33) % 26 + 97); //((x-97+n)%26+97) + } else(str.charCodeAt(i) < 65){ + arr.push(str.charCodeAt[i]); //para los que no son letras mayúsculas ni minúsculas. + } + } + return arr; //retornar datos del array 'arr' +} +//cipher('ABC'); //(6) [72, undefined, 73, undefined, 74, undefined] lo q me sale en la consola + +//Se crea la función decipher + +function decipher() { + + arr2 = []; //Se crea un array vacio para almacenar los # ASCII en letras. + + for (var i = 0; i < arr.length; i++) { + + var x = arr.charCodeAt(i); //Se crea la variable x para reemplazar en las demás líneas de código. + + if (x >= 65 && x <= 90) { //Para letras mayúsculas + arr2.push(String.fromCharCode(x)); //Con String.fromCharCode(x), lo que hace es convertir los # ASCII en letras + } else if (x >= 97 && x <= 120) { //Para letras mayúsculas + arr2.push(String.fromCharCode(x)); //Con push() se almacena los datos obtenidos de String.fromCharCode en arr2 + } else(x < 65) //para los que no son letras mayúsculas ni minúsculas. + arr2.push(x); + } + } + return arr2; //retornar datos del array 'arr2' +} + +askPhrase(); //Llamando a la función askPhrase. \ No newline at end of file