Generation

code to explanationFri, 10 Feb 2023

function cifrar(frase, clave){ let letra, respuesta=''; let alfabeto = 'abcdefghijklmnopqrstuvwxyz'; let cifrado = alfabeto.slice(-clave); cifrado += alfabeto.slice(0, alfabeto.length - clave); for(let i=0; i< frase.length; i++){ letra = frase[i].toLowerCase(); if(letra ==' '){ letra =' '; } else{ letra = cifrado[alfabeto.indexOf(letra)] ; } respuesta += letra; } return respuesta; }

In this function we use an array to store the alphabet and a variable that receives the value of the array, this function allows us to use the method slice that is the one that allows us to cut the array and add the value of the array to the variable, this is used to move the letters.

Questions about programming?Chat with your personal AI assistant