强智

js加密函数

function(ret) {
    if (ret.data == 'no') {
        return false;
    } else {
        var data = ret.data ;//服务器发送的字符串
        var scode = data.split("#")[0];
        var sxh = data.split("#")[1];
        var code = document.getElementById("Form1").USERNAME.value + '%%%' + document.getElementById("Form1").PASSWORD.value;
        var encoded = '';
        for (var i = 0; i < code.length; i++) {
            if (i < 20) {
                encoded = encoded + code.substring(i, i + 1) + scode.substring(0, parseInt(sxh.substring(i, i + 1)));
                scode = scode.substring(parseInt(sxh.substring(i, i + 1)), scode.length);
            } else {
                encoded = encoded + code.substring(i, code.length);
                i = code.length;
            }
          //加密后结果
          encode = encode 
        }


python简化后的加密函数

dataStr = 'Xf6IdjyLrb793B9xcPBe40Uv5b5ml99d2XfYw1dxQ#13331111233312223312'#服务器发送的字符串
scode=dataStr.split("#")[0]#密钥
sxh=dataStr.split("#")[1] #salt
account = ''#用户名
password= ''#密码
code=account +"%%%"+ password
encoded=""
for i in range(0,len(code)):
    if i < 20:
        index = int(sxh[i])
        encoded = encoded + code[i] + scode[0:index]
        scode = scode[index:len(scode)]
    else:
        encoded = encoded + code[i:len(code)]
print(encoded)#加密后结果

python解密函数

salt = '13331111233312223312'    #salt
def simple_decode(encoded,salt):
    sxh=salt
    decoded = ''
    for i in range(0,len(sxh)):
        n = int(sxh[i])
        code = encoded[0:n]
        n = 1+ n
        encoded = encoded[n:]
        if len(code)>0:
            decoded = decoded + code[0]
        else:
            break
    replace_length = 1
    while True:
        if len(encoded) > replace_length:
            encoded = encoded[0:len(encoded)-replace_length]
            replace_length += 1
        else:
            break
    decoded = decoded + encoded
    return decoded

 

你可能感兴趣的:(JS)