nitlix-crypto
Version:
😍 Another starting collection of hashing, salting and other encryption tools 🚀 for the back-end side of the web.
20 lines (19 loc) • 838 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 = data.split(":").map((val) => parseInt(val));
const keyVals = [];
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;
//divide each data value by the corresponding key value
const decryptedVals = [];
for (let i = 0; i < dataVals.length; i++) {
decryptedVals.push(Math.round(dataVals[i] / (keyVals[i % keyVals.length] * variator)));
}
//return the decrypted data as a string
return decryptedVals.map((val) => String.fromCharCode(val)).join("");
}