34 lines
702 B
JavaScript
34 lines
702 B
JavaScript
|
// A simple function to encrypt string
|
||
|
// to avoid being collected by robots.
|
||
|
function hide(seed, str) {
|
||
|
const str_arr = new TextEncoder().encode(str);
|
||
|
const res_arr = [];
|
||
|
seed %= 1000000007;
|
||
|
|
||
|
for (let i = 0; i < str_arr.length; i++) {
|
||
|
res_arr.push((str_arr[i] + seed) % 256);
|
||
|
seed = seed * seed % 1000000007;
|
||
|
}
|
||
|
|
||
|
|
||
|
return res_arr;
|
||
|
}
|
||
|
|
||
|
function unhide(seed, arr) {
|
||
|
seed %= 1000000007;
|
||
|
const str_arr = [];
|
||
|
for (let i = 0; i < arr.length; i++) {
|
||
|
str_arr.push((((arr[i] - seed) % 256) + 256) % 256)
|
||
|
seed = seed * seed % 1000000007;
|
||
|
}
|
||
|
|
||
|
const ui8_arr = new Uint8Array(str_arr);
|
||
|
const str = new TextDecoder().decode(ui8_arr);
|
||
|
return str;
|
||
|
}
|
||
|
|
||
|
export {
|
||
|
hide,
|
||
|
unhide
|
||
|
}
|