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 Cesar - Andrea Chumioque #68
Open
AndreaChumioque
wants to merge
3
commits into
Laboratoria-learning:master
Choose a base branch
from
AndreaChumioque: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 | ||
} | ||
} |
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,12 @@ | ||
<!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>Document</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,88 @@ | ||
// Creando funcion Cifrado Cesar | ||
function cipher(msg, x) { | ||
// Creando variables | ||
var origCode = 0; | ||
var newCode = 0; | ||
var newLetter = ''; | ||
var cipherMsg = ''; | ||
|
||
// Recorriendo el string de izquierda a derecha | ||
for (var i = 0; i < msg.length; i++) { | ||
// Encontramos el código de cada caracter con el método charCodeAt | ||
origCode = msg.charCodeAt(i); | ||
// Si el caracter es una letra mayúscula o minúscula (entre los códigos 65 y 90 o 97 y 122), | ||
// realiza el cifrado, de lo contrario agrega el caracter original al nuevo string | ||
if (origCode >= 'A'.charCodeAt(0) && origCode <= 'Z'.charCodeAt(0)) { | ||
newCode = (origCode - 'A'.charCodeAt(0) + x) % 26 + 'A'.charCodeAt(0); | ||
newLetter = String.fromCharCode(newCode); | ||
cipherMsg += newLetter; | ||
} else if (origCode >= 'a'.charCodeAt(0) && origCode <= 'z'.charCodeAt(0)) { | ||
newCode = (origCode - 'a'.charCodeAt(0) + x) % 26 + 'a'.charCodeAt(0); | ||
newLetter = String.fromCharCode(newCode); | ||
cipherMsg += newLetter; | ||
} else { | ||
cipherMsg += String.fromCharCode(origCode); | ||
} | ||
} | ||
// Retornando mensaje cifrado | ||
return alert('Mensaje cifrado:\n' + cipherMsg); | ||
} | ||
|
||
// Creando función para descrifrar | ||
function decipher(msg, x) { | ||
// Creando variables | ||
var newCode = 0; | ||
var origCode = 0; | ||
var origLetter = ''; | ||
var decipherMsg = ''; | ||
|
||
// Recorriendo el string de izquierda a derecha | ||
for (var i = 0; i < msg.length; i++) { | ||
// Encontramos el código de cada caracter mediante el método charCodeAt | ||
newCode = msg.charCodeAt(i); | ||
// Si el caracter es una letra mayúscula o minúscula (entre los códigos 65 y 90 o 97 y 122), | ||
// realiza el cifrado, de lo contrario agrega el caracter original al nuevo string | ||
if (newCode >= 'A'.charCodeAt(0) && newCode <= 'Z'.charCodeAt(0)) { | ||
if ((newCode - x % 26) < 'A'.charCodeAt(0)) { | ||
origCode = 'Z'.charCodeAt(0) - (x % 26) + (newCode - 'A'.charCodeAt(0)) + 1; | ||
} else { | ||
origCode = (newCode - x % 26); | ||
} | ||
origLetter = String.fromCharCode(origCode); | ||
decipherMsg += origLetter; | ||
} else if (newCode >= 'a'.charCodeAt(0) && newCode <= 'z'.charCodeAt(0)) { | ||
if ((newCode - x % 26) < 'a'.charCodeAt(0)) { | ||
origCode = 'z'.charCodeAt(0) - (x % 26) + (newCode - 'a'.charCodeAt(0)) + 1; | ||
} else { | ||
origCode = (newCode - x % 26); | ||
} | ||
origLetter = String.fromCharCode(origCode); | ||
decipherMsg += origLetter; | ||
} else { | ||
decipherMsg += String.fromCharCode(newCode); | ||
} | ||
} | ||
// Retornando mensaje descifrado | ||
return alert('Mensaje descifrado:\n' + decipherMsg); | ||
} | ||
|
||
// Menú de opciones para cifrar o descifrar mensajes | ||
do { | ||
var menu = '1.Cifrar mensaje\n2.Descifrar mensaje\n3.Salir'; | ||
var option = prompt('Ingrese una opción:\n' + menu); | ||
// Si la opción es 1 | ||
if (option === '1') { | ||
var msg = prompt('Ingrese mensaje a cifrar:'); | ||
// Llamar función cipher | ||
if (msg !== '') { | ||
cipher(msg, 33); | ||
} | ||
// Si la opción es 2 | ||
} else if (option === '2') { | ||
var msg = prompt('Ingrese mensaje a descifrar:'); | ||
// Llamar función decipher | ||
if (msg !== '') { | ||
decipher(msg, 33); | ||
} | ||
} | ||
} while (option !== '3'); |
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.
Segun las especificaciones, el usuario no debe poder ingresar numeros. Trate de poner numeros en mi mensaje y si pude. Favor de actualizar el code para que no pueda ingresar numeros en el mensaje
Creo que no es necesario pasar el variable x.
Solo llamas esta function una vez y le das un valor de 33.