const Crypto = {
encryption(data) {
data = JSON.stringify(data)
let str = '';
let alterText = [];
let varCost = [];
const TextLength = data.length;
for (let i = 0; i < TextLength; i++) {
let random = parseInt(Math.random() * 266);
alterText[i] = data.charCodeAt(i) + random;
varCost[i] = random;
}
for (let i = 0; i < TextLength; i++) {
str += String.fromCharCode(alterText[i], varCost[i]);
}
return str;
},
decrypt(text) {
let str = '';
let alterText = [];
let varCost = [];
const TextLength = text.length;
for (let i = 0; i < TextLength; i++) {
alterText[i] = text.charCodeAt(i);
varCost[i] = text.charCodeAt(i + 1);
}
for (let i = 0; i < TextLength; i = i + 2) {
str += String.fromCharCode(alterText[i] - varCost[i]);
}
return JSON.parse(str);
}
};
export default Crypto;