Encrypting and Decrypting Data Using Javascript

I am working on an app that allows users that are not logged in to have an account. The problem is that I need to encrypt and decrypt user data, but I can only encrypt using a very simple algorithm at the moment using this javascript:

let letters = 'abcdefghijklmnopqrstuvwxyz'.split(''); 
let letters2 = (p2 + 'abcdefghijklmnopqrstuvwxyz'.slice(0,-p2.length));
var encrypted = [];
for (i=0;i<p1.length;i++) {
encrypted.push(letters2[letters.indexOf(p1.toLowerCase()[i])])
}

for (i=0;i<p2.length;i++) {
encrypted.push(letters2[letters.indexOf(p2.toLowerCase()[i])])
}

return encrypted.join('');

p1 is the data as a string that is being encrypted and p2 is the key that the data is being encrypted with.

How can I reverse this, so I can decrypt the data in the most efficient way possible?

Be aware that this method is not secure. Data residing in Glide is still downloadable, and using a JavaScript column for “encrypt/decrypt” won’t change that, unfortunately.

To prevent data from being downloaded by the wrong people, you must use Row Owners.

2 Likes