This repository was archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Cifrado Cesár - Laura Jiménez #78
Open
LauraJimenezH
wants to merge
4
commits into
Laboratoria-learning:master
Choose a base branch
from
LauraJimenezH:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,110 @@ | ||
| # Cifrado César | ||
| # PRODUCTO FINAL - CIFRADO CÉSAR | ||
|
|
||
| > Recuerda seguir siempre esta [guía de estilos](https://github.com/Laboratoria/js-style-guide/) | ||
| #### Consideraciones Específicas: | ||
|
|
||
| Crea una web que pida, por medio de un `prompt()`, una frase al usuario y | ||
| devuelva el mismo mensaje encriptado según el | ||
| [algoritmo de Cifrado César](https://en.wikipedia.org/wiki/Caesar_cipher) | ||
| con el parámetro de desplazamiento de **33 espacios hacia la derecha** | ||
| 1. Tu programa debe ser capaz de cifrar y descifrar tanto letras mayúsculas como minúsculas. La fórmula para descifrar es: (x - n) % 26 | ||
| 2. Tu código debe estar compuesto por 2 funciones con los siguientes nombres: cipher y decipher | ||
| 3. El usuario no debe poder ingresar un campo vacío o que contenga números | ||
|
|
||
| Por ejemplo: | ||
| ### PSEUDOCODIGO: | ||
|
|
||
| - Texto original: `ABCDEFGHIJKLMNOPQRSTUVWXYZ` | ||
| - Texto codificado: `HIJKLMNOPQRSTUVWXYZABCDEFG` | ||
|
|
||
| ## Entregables | ||
| Creamos función Cipher: | ||
| ~~~ | ||
| Funcion Cipher(phrase){ | ||
|
|
||
| Definir output,texto,i | ||
|
|
||
| Para cada producto debes entregar **un repositorio de GitHub** que | ||
| contenga: | ||
| 1. Archivo `README.md` que explique el **pseudocódigo** de tu solución y su | ||
| **diagrama de flujo** | ||
| 2. Archivo `app.js` con el **código** de tu solución | ||
| 3. Archivo `index.html` vinculado con tu `app.js` | ||
| output = ''(vacio) | ||
| texto = phrase(convertido en mayusculas) | ||
|
|
||
| ## Tips | ||
| Para( i = 0 , i < longitud de la variable texto , i = i + 1){ | ||
|
|
||
| A continuación un video de Michelle que te lleva a través de la fórmula | ||
| matemática del Cifrado César y un par de cosas más que debes saber para | ||
| resolver este reto. ¡Escúchala con detenimiento y sigue sus consejos! :) | ||
| output = output + String.fromCharCode(Devuelve una cadena desde un numero ASCII)((((texto.charCodeAt[ i ](Devuelve numero ASCII de la variable texto1 en su indice i )-65)+33)%26)+65) | ||
| } | ||
|
|
||
| [](https://www.youtube.com/watch?v=zd8eVrXhs7Y) | ||
| retorne variable output | ||
| } | ||
| ~~~ | ||
| Ahora creamos una funcion Decipher a la cual no le cambiamos las variables porque son distintas funciones: | ||
| ~~~ | ||
| Funcion Decipher(phrase){ | ||
|
|
||
| Definimos como variable a output,texto,i | ||
|
|
||
| También te compartimos más información de lo que Michelle te ha explicado | ||
| en el video anterior: | ||
| output = ''(vacio) | ||
| texto = phrase(convertido en mayusculas) | ||
|
|
||
| - [Aprende más sobre `charCodeAt()`](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/String/charCodeAt) | ||
| - [Aprende más sobre `String.fromCharCode()`](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/String/fromCharCode) | ||
| - [Aprende más sobre `ASCII`](http://conceptodefinicion.de/ascii/) | ||
| Para( i = 0 , i<longitud de la variable texto , j = j + 1){ | ||
|
|
||
| ## Consideraciones específicas | ||
| output = output + String.fromCharCode(Devuelve una cadena desde un numero ASCII)((((texto.charCodeAt[ i ](Devuelve numero ASCII de la variable texto en su indice i )+65)-33)%26)+65) | ||
| } | ||
|
|
||
| 1. Tu programa debe ser capaz de cifrar y descifrar tanto letras | ||
| mayúsculas como minúsculas. La fórmula para descifrar es: `(x - n) % 26` | ||
| 2. Tu código debe estar compuesto por 2 funciones con los siguientes | ||
| nombres: `cipher` y `decipher` | ||
| 3. El usuario no debe poder ingresar un campo vacío o que contenga números | ||
| retorne variable output | ||
| } | ||
| ~~~ | ||
| Ahora que ya tenemos las funciones creadas pasaremos a preguntar al usuario, validar y llamar a las funciones: | ||
| ~~~ | ||
| Definimos como variable a order,k,value,spaces | ||
|
|
||
| order = prompt('Ingresa una frase')(Pide al usuario) | ||
|
|
||
| Si(order es distinto de ""(vacio))Entonces{ | ||
|
|
||
| Para (j = 0 , j < longitud de la variable order,j = j + 1){ | ||
| Si(order en la posicion [ j ] es igual a " " (campo en blanco) )Entonces{ | ||
|
|
||
| spaces = true | ||
| break; (sale del bucle) | ||
|
|
||
| }Sino{ | ||
|
|
||
| spaces = false | ||
| } | ||
| } | ||
|
|
||
| Si (spaces = true) Entonces{ | ||
|
|
||
| Alerta ('No ingrese campos en blanco') | ||
|
|
||
| }Sino{ | ||
|
|
||
| Para (k = 0 , k < longitud de la variable order,k = k + 1){ | ||
| Si(order convertido a ASCII mayor 64 y menor a 91 )Entonces{ | ||
|
|
||
| value = true | ||
|
|
||
| }Sino{ | ||
|
|
||
| value = false | ||
| Alerta ('Ingrese solo letras') | ||
| } | ||
| } | ||
|
|
||
| Si (value = true) Entonces{ | ||
|
|
||
| Escribir en documento ('Cifrado ->' + (LLamamos a la funcion Cipher) Cipher(order)) | ||
| Escribir en documento ('<p> Decifrado ->' + (LLamamos a la funcion Decipher) Decipher(order)) | ||
|
|
||
| } | ||
| } | ||
|
|
||
| }Sino{ | ||
|
|
||
| Alerta('Ingrese una frase') | ||
| } | ||
| ~~~ | ||
|
|
||
| ### DIAGRAMA DE FLUJO | ||
|
|
||
| Funcion Cipher: | ||
|
|
||
|  | ||
|
|
||
| Funcion Decipher: | ||
|
|
||
|  | ||
|
|
||
| ## Criterios de evaluación | ||
| Validando y llamando a las funciones: | ||
|
|
||
| Se tomarán en cuenta las siguientes consideraciones a la hora de evaluar tu solución: | ||
|  | ||
|
|
||
| 1. Nombramiento de variables | ||
| 2. Indentación | ||
| 3. Validación de input: el usuario no debe poder ingresar un campo vacío o de tipo que no corresponda | ||
| 4. Estructura de tus archivos | ||
| 5. Archivo `README.md` correctamente redactado | ||
| 6. Uso de comentarios para hacer tu código más legible | ||
| 7. Que el programa cumpla con el propósito requerido |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>Cifrado César</title> | ||
| </head> | ||
| <body> | ||
| <h1>Cifrado César</h1> | ||
| <script src="js/app.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // Creamos las funciones de CIPHER y DECIPHER: | ||
| function cipher(phrase) { | ||
| var output = ''; | ||
|
|
||
| // Bucle que recorra la variable phrase: | ||
| for (var i = 0; i < phrase.length; i++) { | ||
| // Convierte a ascii | ||
| var ascii = phrase.charCodeAt(i); | ||
|
|
||
| // Condición y covierte nuevamente en letra | ||
| if (ascii > 64 && ascii < 91) // fórmula para mayúsculas | ||
| output += String.fromCharCode(((ascii - 65) + 33) % 26 + 65); | ||
| else if (ascii > 96 && ascii < 123) // fórmula para minúsculas | ||
| output += String.fromCharCode(((ascii - 97) + 33) % 26 + 97); | ||
| } | ||
|
|
||
| // Cuando se llame la función, retornará la variable output: | ||
| return output; | ||
| } | ||
|
|
||
| function decipher(phrase) { | ||
| var output = ''; | ||
|
|
||
| // Bucle que recorra la variable phrase: | ||
| for (var i = 0; i < phrase.length; i++) { | ||
| // Convierte a ascii | ||
| var ascii = phrase.charCodeAt(i); | ||
|
|
||
| // Condición y covierte nuevamente en letra | ||
| if (ascii > 64 && ascii < 91) // formula para mayusculas | ||
| output += String.fromCharCode((((ascii - 65) - 33) + 26 * 2) % 26 + 65); | ||
| else if (ascii > 96 && ascii < 123) // para minusculas | ||
| output += String.fromCharCode((((ascii - 97) - 33) + 26 * 2) % 26 + 97); | ||
| } | ||
|
|
||
| // Cuando se llame la función, retornará la variable output: | ||
| return output; | ||
| } | ||
|
|
||
| // Por medio de 'prompt' le pedimos al usuario que ingrese un frase: | ||
| var phrase = prompt('INGRESE UNA FRASE: '); | ||
|
|
||
| // Condicional para que no puedan dejar el prompt vacio: | ||
| if (phrase !== '') { | ||
| // Bucle que recorra la variable phrase: | ||
| for (var j = 0; j < phrase.length; j++) { | ||
| // Condicional para que no ingresen campos vacios: | ||
| if (phrase[j] === ' ') { | ||
| spaces = true; | ||
| break; // Para que cuando spaces sea true, salga del bucle. | ||
| } else { | ||
| spaces = false; | ||
| } | ||
| } | ||
|
|
||
| // Mensaje si ha ingresado espacios: | ||
| if (spaces === true) { | ||
| alert('No ingrese campos en blanco'); | ||
| } else { | ||
| // Bucle que recorra la variable phrase: | ||
| for (var re = 0; re < phrase.length; re++) { | ||
| // Condicional para que no se pueda ingresar numeros: | ||
| if (phrase.charCodeAt(re) >= 65 && phrase.charCodeAt(re) <= 90 || phrase.charCodeAt(re) > 96 && phrase.charCodeAt(re) < 123) { | ||
| var stringContainsOnlyLetters = true; | ||
| } else { | ||
| var stringContainsOnlyLetters = false; | ||
| break; // Para que cuando stringContainsOnlyLetters sea true, salga del bucle. | ||
| } | ||
| } | ||
|
|
||
| // Condicional si ha ingresado solo letras sin numeros: | ||
| if (stringContainsOnlyLetters) { | ||
| // Preguntamos y llamamos a las funciones: | ||
| do { | ||
| var answer = prompt('INGRESE UNA OPCIÓN: \n \n 1. Cifrar \n 2. Descifrar \n 3. Salir'); | ||
|
|
||
| // Condicional si no ha ingresado nada | ||
| if (answer !== '') { | ||
| if (answer === '1') { | ||
| document.write('Cifrado -> ' + cipher(phrase)); | ||
| } else if (answer === '2') { | ||
| document.write('<p> Descifrado -> ' + decipher(phrase)); | ||
| } else if (answer === '3') { | ||
| document.write('**** ADIÓS ****'); | ||
| } else { | ||
| alert('Ingrese una opción válida'); | ||
| } | ||
| } | ||
| } while (answer === '' || (answer !== '1' && answer !== '2' && answer !== '3')); | ||
| } | ||
|
|
||
| // Mensaje si ha ingresado numeros: | ||
| if (!stringContainsOnlyLetters) { | ||
| alert('Ingrese solo letras'); | ||
| } | ||
| } | ||
|
|
||
| // Mensaje si no ingreso nada en el prompt: | ||
| } else { | ||
| alert('Ingrese una frase'); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=== trueno es necesario. Puedes escribir solo:if (spaces)