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 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
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
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 = "app.js">
Copy link
Collaborator

Choose a reason for hiding this comment

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

no uses espacios sobre el =


</script>
</body>
</html>
1 change: 1 addition & 0 deletions js/app
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

77 changes: 77 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
function cipher(word) {
var word = prompt('Ingrese la frase');
Copy link
Collaborator

Choose a reason for hiding this comment

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

El prompt debe ser fuera de la función, y después puedes llamar el función así:

var userInput = prompt('Ingrese la frase');
console.log(cipher(userInput));

(Este puede estar en la línea 40)

// ingreso de la palabra

// Validadno que la cadena no este vacia
if (word === '');
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 ; aquí

Copy link
Collaborator

Choose a reason for hiding this comment

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

(El if no funciona si hay ; )

{
Copy link
Collaborator

Choose a reason for hiding this comment

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

{ debe estar en la línea anterior

alert('Tienes que ingresar una frase');
}
// Validando que solo permita el ingreso de letras minusculas y mayusculas

if ((word.charCodeAt() >= 97 && word.charCodeAt() <= 122) || (word.charCodeAt() >= 65 && word.charCodeAt() <= 90)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

charCodeAt necesita un parametro - el índice del caracter en la cadena. Si no usas parametro, el índice predeterminado es 0 - entonces, este código solo verifica la primera letra de la cadena.

https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/String/charCodeAt

alert('muy bien');
} else {
alert('No es valido ingresar numeros');
}

var wordTemp = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pienso que puedes elegir mejor nombre por esta variable. Por ejemplo, newAsciiCode.

var wordCipher = ''; // Se define para almacenara la palabra cifrada
var codeAscii = 0;// variable donde se guarda el codigo correspondiente a cada letra en ascii
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pon un espacio antes del //

for (var i = 0; i < word.length; i++) {
codeAscii = word.charCodeAt(i); // para obtener el codigo ascii de una palabra ingresada
if (codeAscii >= 65 && codeAscii <= 90) // Para letras mayusculas
wordTemp = (word.charCodeAt(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.

Elimina esta línea en blanco


// Para letras minusculas
else {
(codeAscii >= 97 && codeAscii <= 122);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Esta línea no hace nada. ¿Querías escribir else if (codeAscii >= 97 && codeAscii <= 122) ?

wordTemp = (word.charCodeAt(i) - 65 + 33) % 26 + 97;
}
wordCipher += (String.fromCharCode(wordTemp));

// se va almacenando uno por uno de acuerdo a la cantidad de letras de la palabra que se ingreso
Copy link
Collaborator

Choose a reason for hiding this comment

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

Este comentario tiene más sentido antes del loop (antes de la línea 21).

}

return wordCipher;// retorna la salida de la palabra cifrada
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pon un espacio antes del //

}

console.log(cipher('a'));


function decipher(word) {
var word = prompt('Ingrese la frase');// ingreso de la palabra
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hay el mismo problema que la función cipher - este prompt debe ser fuera de la función.

// Validadno que la cadena no este vacia
if (word === '') {
alert('Tienes que ingresar una frase');
}
// Validando que solo permita el ingreso de letras minusculas y mayusculas

if ((word.charCodeAt() >= 97 && word.charCodeAt() <= 122) || (word.charCodeAt() >= 65 && word.charCodeAt() <= 90)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

charCodeAt() necesita parametro

alert('muy bien');
} else {
alert('No es valido ingresar numeros');
}
var word = prompt('Ingrese la frase');
var wordTemp = 0;
var wordCipher = ''; // Se define para almacenara la palabra decifrada
var codeAscii = 0;// variable donde se guarda el codigo correspondiente a cada letra en ascii
Copy link
Collaborator

Choose a reason for hiding this comment

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

Espacio antes de //

for (var i = 0; i < word.length; i++) {
codeAscii = word.charCodeAt(i); // para obtener el codigo ascii de una palabra ingresada
// Para letras mayusculas
if (codeAscii >= 65 && codeAscii <= 90) {
wordTemp = ((word.charCodeAt(i) - 33) % 26) ;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Elimina el espacio antes de ;

// Para letras minusculas
} else {
(codeAscii >= 97 && codeAscii <= 122);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Esta línea no hace nada - ¿necesitas else if?

wordTemp = ((word.charCodeAt(i) - 33) % 26) ;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Elimina esta línea en blanco


wordCipher += (String.fromCharCode(wordTemp)); // se va almacenando uno por uno de acuerdo a la cantidad de letras de la palabra que se ingreso
}

return wordCipher; // retorna la salida de la palabra decifrada
}
// console.log(decipher ('Alas'));
Loading