加密函数:
- 加解密支持程度由BASE字符串控制
let BASE = "";
function encrypt(address) {
let e1 = "";
let e2 = "";
for (let i=0,len = address.length; i < len; i++) {
let index =BASE.indexOf(address[i]) + i + 1
if (index > BASE.length) {
index -=BASE.length;
}
if (i%2===0) {
e1 += BASE[index]
} else {
e2 += BASE[index]
}
}
return e1+e2
}
解密函数:
function decrypt(encode) {
let sp = Math.ceil(encode.length/2)
let e1 = encode.substring(0,sp);
let e2 = encode.substring(sp);
let s = "";
for (let i=0,len = e1.length; i < len; i++) {
let index1 = BASE.indexOf(e1[i])
// 下面两段顺序不能变
//倒推 e1
index1 = index1 - i*2 - 1
if (index1 < 0) {
index1 +=BASE.length;
}
s += BASE[index1]
//倒推 e2
if (typeof e2[i] !== 'undefined') {
let index2 = BASE.indexOf(e2[i])
index2 = index2 - i*2 - 2
if (index2 < 0) {
index2 +=BASE.length;
}
s += BASE[index2]
}
}
return s
}