nitlix-crypto
Version:
😍 Another starting collection of hashing, salting and other encryption tools 🚀 for the back-end side of the web.
23 lines (22 loc) • 840 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
function default_1(data, key) {
//get unicode integer values of each character in the data and key
const dataVals = [];
const keyVals = [];
for (let i = 0; i < data.length; i++) {
dataVals.push(data.charCodeAt(i));
}
for (let i = 0; i < key.length; i++) {
keyVals.push(key.charCodeAt(i));
}
const variator = (keyVals.reduce((acc, val) => acc + val, 0) / keyVals.length) ** 3;
//multiply each data value by the corresponding key value
const encryptedVals = [];
for (let i = 0; i < dataVals.length; i++) {
encryptedVals.push(dataVals[i] * keyVals[i % keyVals.length] * variator);
}
//return the encrypted data as a string
return encryptedVals.join(":");
}