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
}
}
Binary file added ASSETS/DOCS/diagramadeFlujo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions JS/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var phrase = prompt('Write here');

function cipher(word) {

var strCipher = '' ;
for (var i = 0; i < word.length; i++) {
// turn word into ASCII code.
var letter = word.charCodeAt(i);
// if 'word' is uppercase...
if (Number.isNaN(parseInt(word)) && 65 <= letter && letter <= 90 && word !== '') {
// using the formula.
var num = (letter - 65 + 33) % 26 + 65;
// num into string
strCipher =+ String.fromCharCode(num);
// if 'word' is lowercase...
} else if (Number.isNaN(parseInt(word)) && 97 <= letter && letter <= 122 && word !== '') {
// using the formula.
var num2 = (letter - 97 + 33) % 26 + 97;
// num into string
strCipher = strCipher + String.fromCharCode(num2);
} else {
alert('Write Again, please.');
}
}
return alert(strCipher);
}
cipher(phrase);
Copy link

Choose a reason for hiding this comment

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

No deberias de cifrar a menos que el usuario lo pida. Puedes hacer un menu donde el usuario pueda ingresar "1" para cifrar o "2" para descifrar



function decipher(word) {
var strDecipher = '' ;
for (var i = 0; i < word.length; i++ ) {
var letter = word.charCodeAt(i);

if (Number.isNaN(parseInt(word)) && 65 <= letter && letter <= 90 && word !== '') {
Copy link

Choose a reason for hiding this comment

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

parseInt va a regresar NaN por cualquier cosa incluyendo chars como estos: @#%^&@#$:{}".
Por que no haces un helper function que regrese un boolean de true cuando el texto sea solamente letras y espacios y false cuando tenga otros chars que no sean letras y espacios.

// añadir la formula y almaceno en num
var num = (letter - 65 + 26) % 26 + 65;

strDecipher = strDecipher + String.fromCharCode(num);
} else if (Number.isNaN(parseInt(word)) && 97 <= letter && letter <= 122 && word !== '') {
Copy link

Choose a reason for hiding this comment

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

cambia los valores de ASCII de las letras por 'A'.charCodeAt(0) con cada letra

var num2 = (letter - 97 + 26) % 26 + 97;
strDecipher = strDecipher + String.fromCharCode(num2);
} else {
alert('Write Again, please.');
Copy link

Choose a reason for hiding this comment

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

Me sale una alerta de "write again, please" por cada numero que ponga en el mensaje!

}
}
return alert(strDecipher);
}
decipher(phrase);
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 César</title>
</head>
<body>
<h1>Coding and Decoding</h1>
<p>Write a word, and we show you the same word coded and decoded.</p>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>