This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Agregando index.html y app.js#79
Open
nikedia wants to merge 1 commit intoLaboratoria-learning:masterfrom
Open
Conversation
|
Hola @nikedia queda pendiente un detalle para poder enviar tu pull request a los googlers, // Se crea la función para preguntar al usuario la frase a través de un prompt
function askPhrase() {
do {
var answer = prompt('Ingresar la frase a cifrar');
} while (answer === null || answer === '');
}
// Se crea la función cipher.
function cipher(str) {
var arr = []; // Se crea un array vacio para guardar los códigos de las letras en ASCII.
for (var i = 0; i < str.length; i++) {
if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) { // Usamos str.charCodeAt(i) para hallar su equivalente en ASCII
arr.push((str.charCodeAt(i) - 65 + 33) % 26 + 65); // Con arrr.push(), agregamos al arr la conversión de las letras
} else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 120) { // Se usa la fórmula brindada por Michelle que es la sgte: ((x-65+n)%26+65)
arr.push((str.charCodeAt(i) - 97 + 33) % 26 + 97); // ((x-97+n)%26+97)
} else {
arr.push(str.charCodeAt[i]); // para los que no son letras mayúsculas ni minúsculas.
}
}
return arr; // retornar datos del array 'arr'
}
// cipher('ABC'); // (6) [72, undefined, 73, undefined, 74, undefined] lo q me sale en la consola
// Se crea la función decipher
function decipher() {
arr2 = []; // Se crea un array vacio para almacenar los # ASCII en letras.
for (var i = 0; i < arr.length; i++) {
var x = arr.charCodeAt(i); // Se crea la variable x para reemplazar en las demás líneas de código.
if (x >= 65 && x <= 90) { // Para letras mayúsculas
arr2.push(String.fromCharCode(x)); // Con String.fromCharCode(x), lo que hace es convertir los # ASCII en letras
} else if (x >= 97 && x <= 120) { // Para letras mayúsculas
arr2.push(String.fromCharCode(x)); // Con push() se almacena los datos obtenidos de String.fromCharCode en arr2
} else {// para los que no son letras mayúsculas ni minúsculas.
arr2.push(x);
}
}
return arr2; // retornar datos del array 'arr2'
}
askPhrase(); // Llamando a la función askPhrase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.