Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
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
}
}
28 changes: 28 additions & 0 deletions JS/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var phrase = prompt('Ingresa la frase a decodificar');
var newarray = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

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 declares newarray dentro de la función cipher (por ejemplo, en la linea 6). De lo contrario, si ejecutas el código dos veces, el arreglo contendrá letras de ambas palabras.

var unicode = [];

function cipher(str) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No estás usando este parámetro 'str'
Debes reemplazar 'phrase' con 'str' dentro de esta función

var array = phrase.split('');
for (i = 0; i <= array.length - 1;i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

usa 'var' para declarar una nueva variable
for (var i = 0;

espacio antes de i++
for (i = 0; i <= array.length - 1; i++) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefiero i < array.length a i <= array.length - 1

unicode.push(phrase.charCodeAt(i));
}

for (i = 0; i <= unicode.length - 1; i++) {
newarray.push((unicode[i] - 65 + 33) % 26 + 65);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Este código solo funciona para letras mayúsculas. ¿Cómo puedes añadir código para las letras minúsculas?

}
return newarray;
Copy link
Collaborator

Choose a reason for hiding this comment

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

newarray es arreglo. La función cipher debe devolver un string.
Por ejemplo,
cipher('HOLA'); \\ --> 'OVSH'

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Usa una línea en blanco después de una función

var arr = cipher(phrase);
Copy link
Collaborator

Choose a reason for hiding this comment

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

La resulta de la función cipher debe ser un string - esta variable sería mejor llamada algo así como encodedPhrase.

function decipher(array2) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

El parámetro aquí debe ser string. decipher debe funcionar como así:
decipher('OVSH'); // --> 'HOLA'

var arr2 = [];
for (i = 0; i <= array2.length - 1; i++) {
arr2.push(String.fromCharCode(array2[i]));
return arr2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

El return debe ser fuera del loop. Ahora, esta función devuelta el arreglo después del primer iteración del loop.

}
if (isNaN(phrase) === false) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

¿Qué está tratando de hacer aquí? Este código prueba si phrase es un número.

También, no necesitas === false - puedes usar un !, así :
if (!isNaN(phrase))

'Ingrese una frase por favor';
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No necesitas una else vacío.

}
}
decipher(arr);
11 changes: 11 additions & 0 deletions index.html
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>