pptv key 算法 js版本

2017-12-30 admin 算法

对于广大用户写js播放影片时所需用到的pptv算法,此代码来源于:http://bbs.ckplayer.com/forum.php?mod=viewthread&tid=24437&fromuid=26158

function getkey(param1) {
    var w5 = 0;
    var w6 = 0;
    var w7 = 0; 
    var w2 = param1;
    var w3 = 0;
    var w4 = 0;
    while (w4 < w2.length) {
        w5 = w2[w4];
        w6 = w5.charCodeAt(0);
        w7 = w6 << w4 % 4 * 8;
        w3 = w3 ^ w7;
        w4++;
    }
    return w3;
}

function encrypt(param1, param2) {
    var w5 = 0;
    var w6 = 0;
    var w7 = 0;
    var w13 = 0;
    var w14 = 0;
    var w15 = 0;
    var w16 = 0;
    var w17 = 0;
    var w18 = 0;
    var w19 = 0;
    var w20 = 0;
    var w21 = 0;
    var w22 = 0;
    var w23 = 0;
    var w24 = 0;
    var w25 = 0;
    var w26 = 0;
    var w27 = 0;
    var w28 = 0;
    var w29 = 0;
    var w30 = 0;
    var w31 = 0;
    var w32 = 0;
    var w33 = 0;
    var w34 = 0;
    var w35 = 0;
    var w36 = 0;
    var w37 = 0;
    var w38 = 0;
    var w39 = 0;
    var w40 = 0;
    var w41 = 0;
    var w3 = 16;
    var w4 = getkey(param2); 
    var w8 = param1; 
    var w9 = param2;
    var w10 = w4;
    w5 = w10 << 8 | w10 >>> 24;
    w6 = w10 << 16 | w10 >>> 16;
    w7 = w10 << 24 | w10 >>> 8;
    var w11 = "";
    var w12 = 0;
    while (w12 + w3 <= w8.length) {
        w13 = w8[w12].charCodeAt(0) << 0;
        w14 = w8[(w12 + 1)].charCodeAt(0) << 8;
        w15 = w8[w12 + 2].charCodeAt(0) << 16;
        w16 = w8[w12 + 3].charCodeAt(0) << 24;
        w17 = w8[w12 + 4].charCodeAt(0) << 0;
        w18 = w8[w12 + 5].charCodeAt(0) << 8;
        w19 = w8[w12 + 6].charCodeAt(0) << 16;
        w20 = w8[w12 + 7].charCodeAt(0) << 24;
        w21 = 0 | w13 | w14 | w15 | w16;
        w22 = 0 | w17 | w18 | w19 | w20;
        w23 = 0;
        w24 = 0;
        while (w24 < 32) {
            w23 = w23 + 2654435769;
            w33 = (w22 << 4) + w4;
            w34 = w22 + w23;
            w35 = (w22 >>> 5) + w5;
            w36 = w33 ^ w34 ^ w35;
            w21 = w21 + w36;
            w37 = (w21 << 4) + w6;
            w38 = w21 + w23;
            w39 = w21 >>> 5;
            w40 = w39 + w7;
            w41 = w37 ^ w38 ^ w40;
            w22 = w22 + w41;
            w24++;
        }
        w25 = w21 >>> 0 & 255;
        w26 = w21 >>> 8 & 255;
        w27 = w21 >>> 16 & 255;
        w28 = w21 >>> 24 & 255;
        w29 = w22 >>> 0 & 255;
        w30 = w22 >>> 8 & 255;
        w31 = w22 >>> 16 & 255;
        w32 = w22 >>> 24 & 255;
        w11 = w11 + String.fromCharCode(w21 >>> 0 & 255);
        w11 = w11 + String.fromCharCode(w21 >>> 8 & 255);
        w11 = w11 + String.fromCharCode(w21 >>> 16 & 255);
        w11 = w11 + String.fromCharCode(w21 >>> 24 & 255);
        w11 = w11 + String.fromCharCode(w22 >>> 0 & 255);
        w11 = w11 + String.fromCharCode(w22 >>> 8 & 255);
        w11 = w11 + String.fromCharCode(w22 >>> 16 & 255);
        w11 = w11 + String.fromCharCode(w22 >>> 24 & 255);
        w12 = w12 + w3;
    } 
    w11 = w11 + param1.slice(8, 16).join("");
    return w11;
}

function add(param1, param2) {
    var w3 = 0;
    while (w3 < param2) {
        param1 = param1 + String.fromCharCode(0);
        w3++;
    }
    param1 = param1.split("");
    return param1;
}

function time2String(param1) {
    var w8 = 0;
    var w2 = new Array(8);
    var w4 = "0123456789abcdef";
    var w5 = w4.split("");
    var w6 = 0;
    while (w6 < 8) {
        w8 = param1 >>> 28 - w6 % 8 * 4 & 15;
        w2[w6] = w5[w8];
        w6++;
    }
    var w7 = w2.join("");
    return w7;
}

function Str2Hex(param1) {
    var w7 = 0;
    var w8 = 0;
    var w2 = "0123456789abcdef".split("");
    var w3 = w2;
    var w4 = param1;
    var w6 = w4.length;
    var w5 = new Array(2 * w6);
    var w9 = 0;
    while (w9 < w6) {
        if (w9 < 8) {
            w7 = w4[w9].charCodeAt(0) & 15;
            w8 = w4[w9].charCodeAt(0) >>> 4 & 15;
            w5[2 * w9] = w3[w4[w9].charCodeAt(0) & 15];
            w5[2 * w9 + 1] = w3[w4[w9].charCodeAt(0) >>> 4 & 15];
        } else {
            w5[2 * w9] = w3[Math.floor(Math.random() * 15)];
            w5[2 * w9 + 1] = w3[Math.floor(Math.random() * 15)];
        }
        w9++;
    }
    return w5.join("");
}

function constructKey(param1) {
    var w2 = time2String(param1);
    var w3 = w2;
    if (w3.length < 16) {
        w2 = add(w2, 16 - w3.length);
    }
    var w4 = "";
    var w5 = "qqqqqww";
    if (w5.length < 16) {
        w5 = add(w5, 16 - w5.length);
    }
    w4 = encrypt(w2, w5);
    w4 = Str2Hex(w4);
    return w4;
}

标签: pptv

发表评论:

Powered by emlog