Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
String.fromCharCode() not working as intended

So, I'm trying to make a simple encryption and decryption application where the user inputs are upped by some amount of characters. For Eg: user inputs "abcd" then it converts to "bcde".

Code used for encryption:

const encryptedInput = (input) => {
  try {
    // convert to array
    let splitInput = sanitize(input).split("");

    //down the characters by derived
    let mapped = splitInput.map((element) =>
      element == " "
        ? element
        : String.fromCharCode(element.charCodeAt(0) + process.env.NUMBEROFCHARS)
    );

    let encryptedInput = mapped.join(""); // result
    return encryptedInput; //return
  } catch (err) {}
};

The above code works perfectly fine. Its when I try to decrypt it back to original form, It gives me weird symbols and not the original message.

Code used for decryption:

const decryptedInput = (input) => {
  try {
    // convert to array
    let splitInput = sanitize(input).split("");

    //down the characters by derived
    let mapped = splitInput.map((element) =>
      element == " "
        ? element
        : String.fromCharCode(element.charCodeAt(0) - process.env.NUMBEROFCHARS)
    );

    let decryptedInput = mapped.join(""); // result
    return decryptedInput; //return
  } catch (err) {}
};

Output / Result:

During encryption:
Input: abcd
Output: bcde

During decryption:
Input: bcde
Output: ϕϟϩϳ

But I want the output as abcd not ϕϟϩϳ.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So I restarted my pc and the code works now.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda