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
Solución js cifrado de cesar- Luz Espiritu #71
Open
LuzEspiritu
wants to merge
1
commit into
Laboratoria-learning:master
Choose a base branch
from
LuzEspiritu: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
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,84 @@ | ||
| # Cifrado César | ||
| # **Cifrado Cesar** | ||
|
|
||
| > Recuerda seguir siempre esta [guía de estilos](https://github.com/Laboratoria/js-style-guide/) | ||
| ## Objetivo | ||
|
|
||
| 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** | ||
| Realizar el cifrado y descifrado de una *palabra* por medio de este programa. | ||
|
|
||
| Por ejemplo: | ||
| Utilizamos el **Algoritmo de Cesar** para que letra por letra se pueda cifrar el parametro ingresado. | ||
|
|
||
| - Texto original: `ABCDEFGHIJKLMNOPQRSTUVWXYZ` | ||
| - Texto codificado: `HIJKLMNOPQRSTUVWXYZABCDEFG` | ||
|
|
||
| ## Entregables | ||
| + Texto original: ABCDEFGHIJKLMNOPQRSTUVWXYZ | ||
|
|
||
| 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` | ||
| + Texto codificado: HIJKLMNOPQRSTUVWXYZABCDEFG | ||
| _________________________________________________ | ||
|
|
||
| ## Tips | ||
| ### *PseudoCodigo:* | ||
|
|
||
| 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! :) | ||
| ~~~ | ||
| Algoritmo Cifrado de César | ||
|
|
||
| [](https://www.youtube.com/watch?v=zd8eVrXhs7Y) | ||
| INICIO | ||
|
|
||
| También te compartimos más información de lo que Michelle te ha explicado | ||
| en el video anterior: | ||
| Función cipher(message) | ||
| newString <- message.toUpperCase() | ||
| Para (j = 0; j < newString.length; j++) | ||
| Si newString[j] >= 65 y newString <= 90 Entonces | ||
| positionAlphabetAscii <- newString[j].charCodeAt() | ||
| newPositionEncript <- aplicamos formula de cifrado de cesar a positionAlphabetAscii | ||
| encriptWord += newPositionEncript | ||
| ~~~ | ||
|
|
||
| - [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/) | ||
| ~~~ | ||
| Si no Entonces | ||
| encriptWord <- alert('Solo se aceptan letras. Intentalo nuevamente!') | ||
| Fin Si | ||
| Fin Para | ||
|
|
||
| ## Consideraciones específicas | ||
| Retornar encriptWord | ||
|
|
||
| 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 | ||
| Fin Función | ||
| ~~~ | ||
|
|
||
| ## Criterios de evaluación | ||
| ~~~ | ||
| Función decipher(message) | ||
| newString <- message.toUpperCase() | ||
| Para (j = 0; j < newString.length; j++) | ||
| Si newString[j] >= 65 y newString <= 90 Entonces | ||
| positionAlphabetAscii <- newString[j].charCodeAt() | ||
| newPositionEncript <- aplicamos formula de decifrado de cesar a positionAlphabetAscii | ||
| encriptWord += newPositionEncript | ||
| ~~~ | ||
|
|
||
| Se tomarán en cuenta las siguientes consideraciones a la hora de evaluar tu solución: | ||
| ~~~ | ||
| Si no Entonces | ||
| encriptWord <- alert('Solo se aceptan letras. Intentalo nuevamente!') | ||
| Fin Si | ||
| Fin Para | ||
|
|
||
| 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 | ||
| Retornar encriptWord | ||
|
|
||
| Fin Función | ||
| ~~~ | ||
|
|
||
| ~~~ | ||
| Hacer message <- prompt('Ingrese una palabra') | ||
| Si message === null | ||
| alert('Regresa pronto :) ') | ||
| Si no si message.length === 0 Entonces | ||
| alert('Tu mensaje esta vacio intentalo nuevamente') | ||
| Si no menuOpc = '1.-Cifrar\n' + '2.-Decifrar' Entonces | ||
| opc <- prompt(menuOpc, 'Elige una opción:') | ||
| Si opc === '1' Entonces | ||
| Llamar Función cipher | ||
| Si no si opc === '2' Entonces | ||
| Llamar Función decipher | ||
| Si no Entonces | ||
| alert('Intentalo nuevamente') | ||
|
|
||
| Fin Si | ||
| Repetir Mientras (!message) | ||
| Fin | ||
| ~~~ | ||
| _________________________________________________ | ||
| #### Diagrama de Flujo: | ||
|
|
||
|  |
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,11 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Cifrado Cesar</title> | ||
|
|
||
| </head> | ||
| <body> | ||
| <script type="text/javascript" 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,65 @@ | ||
| // FUNCIÓN DE CIFRADO | ||
| function cipher(message) { | ||
| var newString = message.toUpperCase();// A | ||
| var newPositionEncript; | ||
| var positionAlphabetAscii; | ||
| var encripWord = ''; | ||
| for (var j = 0; j < newString.length; j++) { | ||
| if (newString[j].charCodeAt() >= 65 && newString[j].charCodeAt() <= 90) { | ||
| positionAlphabetAscii = newString[j].charCodeAt(); // 65 | ||
| // Posición de la letra en ASCII | ||
| newPositionEncript = ((positionAlphabetAscii - 65) + 33) % 26 + 65; // 72 | ||
| // Con fórmula para encontrar la nueva posición encriptada | ||
| encripWord = encripWord + String.fromCharCode(newPositionEncript); // H | ||
| // variable que concatena la nueva encriptación | ||
| } else { | ||
| encripWord = alert('Solo se aceptan letras. Inténtalo nuevamente!'); | ||
| break; | ||
| } | ||
| } | ||
| return encripWord; | ||
| } | ||
| // FUNCIÓN DE DESCIFRADO | ||
| function decipher(message) { | ||
| var newString = message.toUpperCase(); // H | ||
| var newPositionNoEncript; | ||
| var positionAlphabetAscii; | ||
| var noEncripWord = ''; | ||
|
|
||
| for (var j = 0; j < newString.length; j++) { | ||
| if (newString[j].charCodeAt() >= 65 && newString[j].charCodeAt() <= 90) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cambiar todos los numeros que representan codicos ascii por 'A'.charCodeAt(0) con sus letras respectivas. |
||
| positionAlphabetAscii = newString[j].charCodeAt(); // 72 | ||
| // Posición de la letra en ASCII | ||
| newPositionNoEncript = ((positionAlphabetAscii - 33 + 65) % 26) + 65; // 65 | ||
| // Con fórmula para encontrar la nueva posición no encriptada | ||
| noEncripWord += String.fromCharCode(newPositionNoEncript);// A | ||
| // variable que concatena la nueva encriptación | ||
| } else { | ||
| noEncripWord = alert('Solo se aceptan letras.Inténtalo nuevamente!'); | ||
| break; | ||
| } | ||
| } | ||
| return noEncripWord; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. decriptedWord* ? |
||
| } | ||
| do { | ||
| var message = ''; | ||
| var message = prompt('Ingresa una palabra:'); | ||
|
|
||
| if (message === null) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. puedes usar == para checar por null. |
||
| alert('Regrese pronto :) '); | ||
| break; | ||
| } else if (message.length === 0) { | ||
| alert('Tu mensaje está vacío, inténtalo nuevamente'); | ||
| } else { | ||
| var menuOpc = '1.- Cifrar\n ' + ' 2.- Descifrar'; | ||
| var opc = prompt(menuOpc, 'Elige una opción:'); | ||
| if (opc === '1') { | ||
| cipher(message); | ||
| } else if (opc === '2') { | ||
| decipher(message); | ||
| } else { | ||
| alert('Inténtalo nuevamente'); | ||
| message = ''; | ||
| } | ||
| } | ||
| } while (message.length === 0); | ||
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.
encriptedWord*