This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Open
Conversation
|
Hola @Nefelijm queda pendiente un detalle para poder enviar tu pull request a los googlers, function ejCifradoCesar() {
do {
var respuestaUsuario = prompt('Ingresa: \n 1 Si quieres cifrar \n 2 Si quieres descifrar');
if (respuestaUsuario !== '') {
if (respuestaUsuario === '1') {
cifrar();
} else if (respuestaUsuario === '2') {
descifrar();
} else {
alert('La opción ingresada no es Válida. Intentalo nuevamente.');
}
}
} while (respuestaUsuario === '' || (respuestaUsuario !== '1' && respuestaUsuario !== '2'));
}
var cifrar = function(ingresaPalabra) {
do {
ingresaPalabra = prompt('Ingresa la palabra que quieres cifrar:');
var cifrado = '';
if (/^[a-zA-Z]*$/.test(ingresaPalabra)) {
for (var i = 0; i < ingresaPalabra.length; i ++) {
var aCifrar = ingresaPalabra[i];
if (aCifrar.match(/[a-z]/i)) {
var toAscci = ingresaPalabra.charCodeAt(i);
if ((toAscci >= 65) && (toAscci <= 90))
aCifrar = String.fromCharCode(((toAscci - 65 + 33) % 26) + 65);
else if ((toAscci >= 97) && (toAscci <= 122))
aCifrar = String.fromCharCode(((toAscci - 97 + 33) % 26) + 97);
}
cifrado += aCifrar;
}
return alert(cifrado);
} else {
alert('Ingresa un Texto Válido');
}
}
while (ingresaPalabra === '' || /^[a-zA-Z]*$/.test(ingresaPalabra) === false);
};
var descifrar = function(ingresaPalabra) {
do {
ingresaPalabra = prompt('Ingresa la palabra que quieres descifrar:');
var descifrado = '';
if (/^[a-zA-Z]*$/.test(ingresaPalabra)) {
for (var i = 0; i < ingresaPalabra.length; i ++) {
var aDescifrar = ingresaPalabra[i];
if (aDescifrar.match(/[a-z]/i)) {
var toAscci = ingresaPalabra.charCodeAt(i);
if ((toAscci >= 65) && (toAscci <= 90))
aDescifrar = String.fromCharCode(((toAscci - 65 - 7 + 52) % 26) + 65);
else if ((toAscci >= 97) && (toAscci <= 122))
aDescifrar = String.fromCharCode(((toAscci - 97 - 7 + 52) % 26) + 97);
}
descifrado += aDescifrar;
}
return alert(descifrado);
} else {
alert('Ingresa un Texto Válido');
}
} while (ingresaPalabra === '' || /^[a-zA-Z]*$/.test(ingresaPalabra) === false);
};
ejCifradoCesar(); |
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.