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 - Manuela Flores #81
Open
ManuelaFlores
wants to merge
1
commit into
Laboratoria-learning:master
Choose a base branch
from
ManuelaFlores: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 | ||
} | ||
} |
Binary file not shown.
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,12 @@ | ||
<!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,78 @@ | ||
// cifra cadenas de texto | ||
// string:cadena de texto a cifrar | ||
function cipher(string) { | ||
// comprobando que el dato ingresado sea una cadena de texto | ||
if (typeof string !== 'string') { | ||
return alert('Debe ingresar una cadena de texto'); | ||
} else { | ||
// convirtiendo la cadena de texto a mayúsculas | ||
string = string.toUpperCase(); | ||
// newPosition:almacenará las posiciones en el código ASCII de la cadena de texto | ||
var newPosition = []; | ||
// ciclo que itera en las posiciones de la cadena de texto | ||
for (var i = 0; i < string.length; i++) { | ||
// agregando la posicion en el codigo ASCII a newPosition | ||
newPosition.push((string.charCodeAt(i) - 65 + 33) % 26 + 65); | ||
} | ||
// newString:almacenará el nuevo string encriptado | ||
var newString = ''; | ||
// iterando en las posiciones de newLetters: | ||
for (var j = 0; j < newPosition.length; j++) { | ||
// concatenando a newString las letras encriptadas | ||
newString += String.fromCharCode(newPosition[j]); | ||
} | ||
// retornando cadena de texto encriptada | ||
return alert('Sufrase crifrada es ' + newString); | ||
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. Es importante que la función devuelta una cadena. Si quieres usar un alert, usarlo antes del return: alert('Su frase cifrada es ' + newString); |
||
} | ||
} | ||
|
||
// descifra cadenas de texto | ||
// string:cadena de texto a descifrar | ||
function decipher(string) { | ||
// verificando que el dato ingresado sea un string | ||
if (typeof string !== 'string') { | ||
return alert('Debe ingresar una cadena de texto'); | ||
} else { | ||
// convirtiendo la cadena de texto a mayúsculas | ||
string = string.toUpperCase(); | ||
// newPosition:almacenará las posiciones en el código ASCII de la cadena de texto | ||
var newPosition = []; | ||
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. Es posible combinar estos dos loops en uno:
|
||
// ciclo que itera en las posiciones de la cadena de texto | ||
for (var i = 0; i < string.length; i++) { | ||
// agregando las posiciones de las letras del string en codigo ASCII a newPosition | ||
newPosition.push((string.charCodeAt(i) - 13 - 33) % 26 + 65); | ||
} | ||
// almacenará las letras encriptadas | ||
var newString = ''; | ||
// iterando en las posiciones de newPosition | ||
for (var j = 0; j < newPosition.length; j++) { | ||
// concantenando las letras encriptadas a newString | ||
newString += String.fromCharCode(newPosition[j]); | ||
} | ||
return alert('Su frase descifrada es ' + newString); | ||
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. Es importante que la función devuelta una cadena. Si quieres usar un alert, usarlo antes del
|
||
} | ||
} | ||
|
||
// mostrando opciones al usuario: | ||
do { | ||
var menu = 'CIFRADO CESAR \n1.Cifrar \n2.Descifrar\n'; | ||
var option = parseInt(prompt(menu, 0)); | ||
// si opcion 1 :cifrar | ||
// si opcion 2:Descifrar | ||
// si no : Escoga una opcion del menu | ||
if (option === 1) { | ||
// pidiendo frase a cifrar y validando que sea string | ||
do { | ||
var string = prompt('Escriba la frase que desea cifrar'); | ||
} while (!string || !isNaN(string)); | ||
cipher(string); | ||
} else if (option === 2) { | ||
// pidiendo frase a descifrar y validando que sea un string | ||
do { | ||
var secondString = prompt('Escriba la frase que desea descifrar'); | ||
} while (!secondString || !isNaN(secondString)); | ||
decipher(secondString); | ||
} else { | ||
alert('Escoja una opción del menu'); | ||
} | ||
} while (!option); |
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.
Es posible combinar los dos loops en uno (vea abajo)