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
}
}
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!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>Cipher Cesar</title>
</head>
<body>
<h2 style='font-family:Tahoma;color:blueviolet'>The first word is encrypted and the second word is decrypted </h2>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Es mejor usar un archivo .css que un atributo style

<script type='text/javascript' src='js/app.js'></script>
</body>
</html>
53 changes: 53 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var word = prompt('Write a word to encrypt');
function cipher(string) {
// Creamos una variable vacia para almacenar el string encriptado//
Copy link
Collaborator

Choose a reason for hiding this comment

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

indenta esta línea - los comentarios debe estar alineados con el código

var newString = '';
// Iteramos cada caracter del string
for (var i = 0; i < word.length; i++) {
// Almacenamos el codigo ASCII de cada caracter
var encrypter = word.charCodeAt(i);
Copy link
Collaborator

Choose a reason for hiding this comment

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

El nombre 'encrypter' no describe que hace esta variable. Algo como letter o oldLetter sería un poco mejor.

// Verificamos si las letras son mayusculas.
if (encrypter >= 65 && encrypter <= 90) {
// Aplicamos la formula para obtener el codigo ASCII
var letters = (encrypter - 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.

Esta variable también sería nombrado mejor - como letter o newLetter (letters es plural, pero solo hay una letra en esta cadena)

// Convertimos el codigo ASCII en letra encriptada y lo unimos al string vacío
newString += String.fromCharCode(letters);
} else if (encrypter >= 97 && encrypter <= 122) { // Repetimos el procedimiento si son minusculas.
var lettersTwo = (encrypter - 97 + 33) % 26 + 97;
newString += String.fromCharCode(lettersTwo);
} else if (typeof string !== String) { // Verificamos que el usuario no ingrese un numero o campo vacio
alert('You have not entered a word');
}
}
return newString;
}
// Llamamos a la funcion
document.write(cipher('word'));

var word = prompt('Write a word to decode');
function decipher(string) {
// Creamos una variable vacia para almacenar el string encriptado
var newString = ' ';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Eliminar el espacio blanco dentro de las comillas
var newString = '';

// Iteramos cada caracter del string
for (var i = 0; i < word.length; i++) {
// Almacenamos el codigo ASCII de cada caracter
var encrypter = word.charCodeAt(i);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tengo los mismos comentarios que los anteriores sobre los nombres de las variables en esta función

// Verificamos si las letras son mayusculas.
if (encrypter >= 65 && encrypter <= 90) {
// Aplicamos la formula para obtener el codigo ASCII
var letters = (encrypter - 65 - 33) % 26 + 65;
// Convertimos el codigo ASCII en letra encriptada y lo unimos al string vacío
newString += String.fromCharCode(letters);
} else if (encrypter >= 97 && encrypter <= 122) {// Repetimos el procedimiento si son minusculas.
var lettersTwo = (encrypter - 97 - 33) % 26 + 97;
newString += String.fromCharCode(lettersTwo);
} else if (typeof string !== String) {// Verificamos que el usuario no ingrese un numero o campo vacio
alert('You have not entered a word');
}
}
return newString;
}
// Llamamos a la funcion
document.write(decipher('word'));