Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Cifrado Cesar #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Lauraisa
Copy link

@Lauraisa Lauraisa commented Nov 7, 2017

Hola
Soy Laura Galindo, les envío mi código de Cifrado.
Gracias.

@Gabx04
Copy link

Gabx04 commented Nov 14, 2017

Hola @Lauraisa está pendiente un detalle para poder enviar tu pull request a los googlers,
te dejo tu código según la guía de estilo, recuerda usar el eslint.
Por favor actualiza el tuyo y me confirmas.

/* crearemos la primera funcion para cifrar*/
function cipher() {
  /* dentro de ella crearemos las variables*/
  var alphabet = prompt('Ingresa el alfabeto').toUpperCase(); 
  var newArray = alphabet.split('');
  // en la nueva varible newAlphabet se colocara los elementos nuevos
  var newAlphabet = [];
  // realizaremos un bucle con for.
  for (i = 0; i < newArray.length; i++) {
  // dentro del for realizarmos la condicion pedida, para ello crearemos un var
  // de la locacion del alfabeto.
    var location = newArray[i].charCodeAt();
    var locationTwo = ((location - 65 + 33) % 26 + 65);
    var code = String.fromCharCode(locationTwo);
    newAlphabet.push(code);
  }
  // con un return para retornar el cifrado
  return newAlphabet.join('');
}

cipher();
function decipher() {
  // Descifrando la palabra cifrada
  for (j = 0; j < newAlphabet.length; j++) {
  // dentro del for realizarmos la condicion pedida, para ello crearemos un var
  // de la locacion del alfabeto.
    var cifri = [];
    var position1 = newAlphabet[j].charCodeAt();
    var position2 = ((position1 + 33) % 26 + 65);
    var codeTwo = String.fromCharCode(position2);
    cifri.push(codeTwo);
  }
  return (cifri.join(''));
}
decipher();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants