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) {}
};
During encryption:
Input: abcd
Output: bcde
During decryption:
Input: bcde
Output: ϕϟϩϳ
But I want the output as abcd not ϕϟϩϳ.
So I restarted my pc and the code works now.