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
}
}
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.
64 changes: 64 additions & 0 deletions JS/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
let phrase = prompt('Write here');
let phraseArr = phrase.split('');
// console.log(Array.isArray(phraseArr)); // ["abc"]

const cipher = word => {
// debugger;
// Verificando si es una palabra y diferente de vacia además de que no tenga espacios.
if (Number.isNaN(parseInt(word)) && word !== '') {
let strCipher = '';
let positionOfLetter;
// En lugar de for se usará filter para recorrer la frase palabra por palabra
let positionPhraseLetter = phraseArr.filter((position) => { // Iteración de las palabras de phrase
positionOfLetter = phraseArr.indexOf(position);
// console.log(positionOfLetter); // retorna su posición
// // regresa el codigo en número ascii
let letter = word.charCodeAt(positionOfLetter);
// console.log(letter); // retorna su codigo ascii
// para mayúsculas
if (letter >= 65 && letter <= 90) {
let num = (letter - 65 + 33) % 26 + 65;
console.log(num);
strCipher += String.fromCharCode(num);
console.log(strCipher);
// para minúsculas
} else if (letter >= 97 && letter <= 122) {
// usando fórmula
let num2 = (letter - 97 + 33) % 26 + 97;
// num a string
strCipher += String.fromCharCode(num2);
console.log(strCipher);
}
});
console.log(positionOfLetter);
return alert(`Your cipher number is ${strCipher}`);
} else {
alert('Write Again, please.');
}
};
cipher(phrase);


const decipher = word => {
if (Number.isNaN(parseInt(word)) && word !== '') {
let strDecipher = '';
let positionOfLetter;
let positionPhraseLetter = phraseArr.filter((position) => {
positionOfLetter = phraseArr.indexOf(position);
let letter = word.charCodeAt(positionOfLetter);
if (65 <= letter && letter <= 90) {
// añadir la formula y almaceno en num
let num = (letter - 65 + 26) % 26 + 65;
strDecipher += String.fromCharCode(num);
} else if (97 <= letter && letter <= 122) {
let num2 = (letter - 97 + 26) % 26 + 97;
strDecipher += String.fromCharCode(num2);
}
});
return alert(`Your decipher number is ${strDecipher}`);
}
// else {
// alert('Write Again, please.');
// }
};
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>