Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Cifrado Cesar - Manuela Flores #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .eslintrc
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 added assets/docs/diagrama.cifrado.pdf
Binary file not shown.
Binary file added assets/docs/diagrama_cifrado1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/docs/diagrama_cifrado2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/docs/diagrama_cifrado3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions index.html
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>
78 changes: 78 additions & 0 deletions js/app.js
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 = [];
Copy link
Collaborator

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)

// 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
return 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 = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es posible combinar estos dos loops en uno:

var newString = '';
for (var i = 0; i < string.length; i++) {
    // agregando las posiciones de las letras del string en codigo ASCII a newPosition
    var newPosition = (string.charCodeAt(i) - 13 - 33) % 26 + 65);
    newString += String.fromCharCode(newPosition);
}

// 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 descifrada es ' + newString);
return newString;

}
}

// 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);