
const lk = new ToolKit(`电信助手`, `Telecom`);

const TelecomConstKey = {
    // -----通用助手相关的-----
    Mobile: 'lkTelecomMobile',
    Password: 'lkTelecomPassword',
    Token: 'lkTelecomToken',
    SignCount: 'lkTelecomSignCount',
};


let telecomMobile = lk.getVal(TelecomConstKey.Mobile, '');
let telecomPassword = lk.getVal(TelecomConstKey.Password, '');

//公钥
const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBkLT15ThVgz6/NOl6s8GNPofdWzWbCkWnkaAm7O2LjkM1H7dMvzkiqdxU02jamGRHLX/ZNMCXHnPcW/sDhiFCBN18qFvy8g6VYb9QtroI09e176s+ZCtiv7hbin2cCTj99iUpnEloZm19lwHyo69u5UMiPMpq0/XKBO8lYhN/gwIDAQAB';
//私钥
const privateKey = '';

const GCommoTelecomHeads = {
    "Accept": "application/json",
    "Content-Type": "application/json; charset=UTF-8",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip",
};


if (!lk.isExecComm) {
    if (lk.isRequest()) {
        checkHandleRequest();
        if (retBody) {
            lk.done({ body: JSON.stringify(retBody) });
        } else {
            lk.done();
        }
    }else{
        all();
    }
}


function checkHandleRequest() {

}


function getSignCount() {
    let SignCount = lk.getVal(TelecomConstKey.SignCount);
    let td = lk.formatDate(new Date(), 'yyyyMMdd');
    if (SignCount) {
        let [date, num] = SignCount.split('_');
        if (date == td && num) {
            return Number(num);
        } else {
            lk.setVal(TelecomConstKey.SignCount, `${td}_0`);
            return 0;
        }
    } else {
        lk.setVal(TelecomConstKey.SignCount, `${td}_0`);
        return 0;
    }
}

async function all() {
    if (lk.isEmpty(telecomMobile) || lk.isEmpty(telecomPassword)) {
        lk.log('⚠️ 请配置手机号(lkTelecomMobile)和密码(lkTelecomPassword)');
        lk.done();
        return;
    }
    await doLogin();
    lk.msg('');
    lk.done();
}


//RSA加密
function encryptRSA(data, key = publicKey) {
    let JSEncrypt = createJSEncrypt();
    let encryptor = new JSEncrypt()
    encryptor.setPublicKey(key)
    // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
    return encryptor.encrypt(data)
}

//rea解密
function decryptRSA(data, key = privateKey) {
    let JSEncrypt = createJSEncrypt();
    let encryptor = new JSEncrypt()
    encryptor.setPrivateKey(key)
    // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
    return encryptor.decrypt(data)
}

function transPhone(phoneNum) {
    let result = '';
    let ArrPhone = phoneNum.toString().split('');
    for (let i = 0; i < 11; i++) {
        result = `${result}` + String.fromCharCode(ArrPhone[i].charCodeAt(0) + 2 & 65535);
    }
    return result;
}

async function doLogin(){
    return new Promise((resolve, _reject) => {
        if (getSignCount() > 10) {
            lk.appendNotifyInfo('⚠️ 当日登录已超过10次!  请明天再试');
            resolve();
            return;
        }
        let timestamp = lk.formatDate(new Date(),'yyyyMMddHHmm00')
        let loginStr = `iPhone 14 16.6.1${telecomMobile}${telecomMobile}${timestamp}${telecomPassword}0$$$0.`;
        let body = {
            content: {
                fieldData: {
                    accountType: '',
                    authentication: telecomPassword,
                    deviceUid: `3${telecomMobile}`,
                    isChinatelecom: '0',
                    loginAuthCipherAsymmertric: encryptRSA(loginStr),
                    loginType: "4",
                    phoneNum: transPhone(telecomMobile),
                    systemVersion: "16.6.1",
                },
                attach: "iPhone",
            },
            headerInfos: {
                clientType: '#9.6.1#channel50#iPhone 14 Pro#',
                code: 'userLoginNormal',
                shopId: '20002',
                source: '110003',
                sourcePassword: 'Sid98s',
                timestamp: timestamp,
                userLoginName: telecomMobile,
            }
        }
        lk.log('--- request body:');
        lk.log(JSON.stringify(body));

        let reqData = {
            url: "https://appgologin.189.cn:9031/login/client/userLoginNormal",
            headers: GCommoTelecomHeads,
            body: JSON.stringify(body),
        };
        lk.post(reqData, async (error, _response, data) => {
            let ret;
            try {
                if (error) {
                    lk.log(`请求发生错误`);
                    lk.execFail();
                } else {
                    lk.log('--- response body:');
                    lk.log(data);
                    let info = JSON.parse(data);
                    let loginInfo = info.responseData.data.loginSuccessResult;
                    if (loginInfo && loginInfo.token) {
                        lk.setVal(TelecomConstKey.Token, loginInfo.token);
                    }else{
                        let errMsg = data.responseData.resultDesc || data.headerInfos.reason;
                        if(errMsg){
                            lk.appendNotifyInfo(`⚠️ ${errMsg}`);
                        }
                    }
                }
            } catch (e) {
                lk.log(`请求发生错误`);
                lk.logErr(e);
                lk.execFail();
            } finally {
                resolve(ret);
            }
        });
    });
}

//---SyncByPyScript---ToolKit-start
function ToolKit(t,s,e){return new class{constructor(t,s,e){this.tgEscapeCharMapping={"&":"＆","#":"＃"},this.userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15",this.prefix="lk",this.name=t,this.id=s,this.data=null,this.dataFile=this.getRealPath(""+this.prefix+this.id+".dat"),this.boxJsJsonFile=this.getRealPath(""+this.prefix+this.id+".boxjs.json"),this.options=e,this.isExecComm=!1,this.isEnableLog=this.getVal(this.prefix+"IsEnableLog"+this.id),this.isEnableLog=!!this.isEmpty(this.isEnableLog)||JSON.parse(this.isEnableLog),this.isNotifyOnlyFail=this.getVal(this.prefix+"NotifyOnlyFail"+this.id),this.isNotifyOnlyFail=!this.isEmpty(this.isNotifyOnlyFail)&&JSON.parse(this.isNotifyOnlyFail),this.isEnableTgNotify=this.getVal(this.prefix+"IsEnableTgNotify"+this.id),this.isEnableTgNotify=!this.isEmpty(this.isEnableTgNotify)&&JSON.parse(this.isEnableTgNotify),this.tgNotifyUrl=this.getVal(this.prefix+"TgNotifyUrl"+this.id),this.isEnableTgNotify=this.isEnableTgNotify&&!this.isEmpty(this.tgNotifyUrl),this.costTotalStringKey=this.prefix+"CostTotalString"+this.id,this.costTotalString=this.getVal(this.costTotalStringKey),this.costTotalString=this.isEmpty(this.costTotalString)?"0,0":this.costTotalString.replace('"',""),this.costTotalMs=this.costTotalString.split(",")[0],this.execCount=this.costTotalString.split(",")[1],this.costTotalMs=this.isEmpty(this.costTotalMs)?0:parseInt(this.costTotalMs),this.execCount=this.isEmpty(this.execCount)?0:parseInt(this.execCount),this.logSeparator="\n██",this.now=new Date,this.startTime=this.now.getTime(),this.node=this.isNode()?{request:require("request")}:null,this.execStatus=!0,this.notifyInfo=[],this.log(this.name+", 开始执行!"),this.initCache(),this.checkRecordRequestBody(),this.execComm()}checkRecordRequestBody(){if(this.isRequest()){var s=$request.body;if(s){var e=$request.path;let t=this.id+"#"+e.replace("/","_");t=t.replace("?","#"),this.isQuanX()&&$prefs.setValueForKey(s,t),(this.isLoon()||this.isSurge())&&$persistentStore.write(s,t),this.isNode()&&this.node.fs.writeFileSync(t+".json",s,{flag:"w"},t=>console.log(t))}}}getRequestBody(){var t=$request.path;let s=this.id+"#"+t.replace("/","_");if(s=s.replace("?","#"),this.isSurge()||this.isLoon())return $persistentStore.read(s);if(this.isQuanX())return $prefs.valueForKey(s);if(this.isNode()){t=s+".json";if(!this.node.fs.existsSync(t))return JSON.parse(this.node.fs.readFileSync(t))}}initCache(){var t,s=this.getPersistKey();this.isQuanX()&&(this.cache=JSON.parse($prefs.valueForKey(s)||"{}")),(this.isLoon()||this.isSurge())&&(this.cache=JSON.parse($persistentStore.read(s)||"{}")),this.isNode()&&(this.node.fs.existsSync(t="root.json")||this.node.fs.writeFileSync(t,JSON.stringify({}),{flag:"wx"},t=>console.log(t)),this.root={},this.node.fs.existsSync(t=s+".json")?this.cache=JSON.parse(this.node.fs.readFileSync(s+".json")):(this.node.fs.writeFileSync(t,JSON.stringify({}),{flag:"wx"},t=>console.log(t)),this.cache={}))}getPersistKey(){return this.id+"#privateCache"}persistCache(){var t=this.getPersistKey(),s=JSON.stringify(this.cache,null,2);this.isQuanX()&&$prefs.setValueForKey(s,t),(this.isLoon()||this.isSurge())&&$persistentStore.write(s,t),this.isNode()&&(this.node.fs.writeFileSync(t+".json",s,{flag:"w"},t=>console.log(t)),this.node.fs.writeFileSync("root.json",JSON.stringify(this.root,null,2),{flag:"w"},t=>console.log(t)))}write(t,s){if(this.log("SET "+s),-1!==s.indexOf("#")){if(s=s.substr(1),isSurge||this.isLoon())return $persistentStore.write(t,s);if(this.isQuanX())return $prefs.setValueForKey(t,s);this.isNode()&&(this.root[s]=t)}else this.cache[s]=t;this.persistCache()}read(t){return this.log("READ "+t),-1!==t.indexOf("#")?(t=t.substr(1),this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?this.root[t]:void 0):this.cache[t]}delete(t){if(this.log("DELETE "+t),-1!==t.indexOf("#")){if(t=t.substr(1),this.isSurge()||this.isLoon())return $persistentStore.write(null,t);if(this.isQuanX())return $prefs.removeValueForKey(t);this.isNode()&&delete this.root[t]}else delete this.cache[t];this.persistCache()}getRealPath(t){var s;return this.isNode()?((s=process.argv.slice(1,2)[0].split("/"))[s.length-1]=t,s.join("/")):t}getUrlHost(t){return t.slice(0,t.indexOf("/",8))}getUrlPath(t){var s=t.lastIndexOf("/")===t.length-1?-1:void 0;return t.slice(t.indexOf("/",8),s)}async execComm(){if(this.isNode()){this.comm=process.argv.slice(1);let t=!1;"p"==this.comm[1]&&(this.isExecComm=!0,this.log(`开始执行指令【${this.comm[1]}】=> 发送到手机测试脚本！`),this.isEmpty(this.options)||this.isEmpty(this.options.httpApi)?(this.log("未设置options，使用默认值"),this.isEmpty(this.options)&&(this.options={}),this.options.httpApi="ffff@10.0.0.9:6166"):/.*?@.*?:[0-9]+/.test(this.options.httpApi)||(t=!0,this.log("❌httpApi格式错误！格式：ffff@3.3.3.18:6166"),this.done()),t||this.callApi(this.comm[2]))}}callApi(t){let i=this.comm[0],s=(this.log(`获取【${i}】内容传给手机`),"");this.fs=this.fs||require("fs"),this.path=this.path||require("path");var e=this.path.resolve(i),r=this.path.resolve(process.cwd(),i),o=this.fs.existsSync(e),h=!o&&this.fs.existsSync(r);if(o||h){h=o?e:r;try{s=this.fs.readFileSync(h)}catch(t){s=""}}else s="";o={url:`http://${this.options.httpApi.split("@")[1]}/v1/scripting/evaluate`,headers:{"X-Key":""+this.options.httpApi.split("@")[0]},body:{script_text:""+s,mock_type:"cron",timeout:!this.isEmpty(t)&&5<t?t:5},json:!0};this.post(o,(t,s,e)=>{this.log(`已将脚本【${i}】发给手机！`),this.done()})}getCallerFileNameAndLine(){let s;try{throw Error("")}catch(t){s=t}var t=s.stack.split("\n")[1];return this.path=this.path||require("path"),`[${t.substring(t.lastIndexOf(this.path.sep)+1,t.lastIndexOf(":"))}]`}getFunName(t){t=t.toString();return t=(t=t.substr("function ".length)).substr(0,t.indexOf("("))}boxJsJsonBuilder(s,r){if(this.isNode()){let i="/Users/lowking/Desktop/Scripts/lowking.boxjs.json";if(r&&r.hasOwnProperty("target_boxjs_json_path")&&(i=r.target_boxjs_json_path),this.fs.existsSync(i))if(this.isJsonObject(s)&&this.isJsonObject(r)){this.log("using node");var o=["settings","keys"],h="https://raw.githubusercontent.com/Orz-3";let e={},t="#lk{script_url}";if(r&&r.hasOwnProperty("script_url")&&(t=this.isEmpty(r.script_url)?"#lk{script_url}":r.script_url),e.id=""+this.prefix+this.id,e.name=this.name,e.desc_html=`⚠️使用说明</br>详情【<a href='${t}?raw=true'><font class='red--text'>点我查看</font></a>】`,e.icons=[h+`/mini/master/Alpha/${this.id.toLocaleLowerCase()}.png`,h+`/mini/master/Color/${this.id.toLocaleLowerCase()}.png`],e.keys=[],e.settings=[{id:this.prefix+"IsEnableLog"+this.id,name:"开启/关闭日志",val:!0,type:"boolean",desc:"默认开启"},{id:this.prefix+"NotifyOnlyFail"+this.id,name:"只当执行失败才通知",val:!1,type:"boolean",desc:"默认关闭"},{id:this.prefix+"IsEnableTgNotify"+this.id,name:"开启/关闭Telegram通知",val:!1,type:"boolean",desc:"默认关闭"},{id:this.prefix+"TgNotifyUrl"+this.id,name:"Telegram通知地址",val:"",type:"text",desc:"Tg的通知地址，如：https://api.telegram.org/bot-token/sendMessage?chat_id=-100140&parse_mode=Markdown&text="}],e.author="#lk{author}",e.repo="#lk{repo}",e.script=t+"?raw=true",!this.isEmpty(s))for(var n in o){var a=o[n];if(!this.isEmpty(s[a])){if("settings"===a)for(let t=0;t<s[a].length;t++){var l=s[a][t];for(let t=0;t<e.settings.length;t++){var p=e.settings[t];l.id===p.id&&e.settings.splice(t,1)}}e[a]=e[a].concat(s[a])}delete s[a]}if(Object.assign(e,s),this.isNode()){this.fs=this.fs||require("fs"),this.path=this.path||require("path");var h=this.path.resolve(this.boxJsJsonFile),c=this.path.resolve(process.cwd(),this.boxJsJsonFile),u=this.fs.existsSync(h),d=!u&&this.fs.existsSync(c),f=JSON.stringify(e,null,"\t"),u=(!u&&d?this.fs.writeFileSync(c,f):this.fs.writeFileSync(h,f),JSON.parse(this.fs.readFileSync(i)));if(u.hasOwnProperty("apps")&&Array.isArray(u.apps)&&0<u.apps.length){d=u.apps,c=d.indexOf(d.filter(t=>t.id==e.id)[0]);0<=c?u.apps[c]=e:u.apps.push(e);let s=JSON.stringify(u,null,2);if(!this.isEmpty(r))for(const m in r){let t="";r.hasOwnProperty(m)?t=r[m]:"author"===m?t="@lowking":"repo"===m&&(t="https://github.com/lowking/Scripts"),s=s.replace(`#lk{${m}}`,t)}for(var g,y=/(?:#lk\{)(.+?)(?=\})/,S=(null!==y.exec(s)&&this.log("生成BoxJs还有未配置的参数，请参考https://github.com/lowking/Scripts/blob/master/util/example/ToolKitDemo.js#L17-L18传入参数：\n"),new Set);null!==(g=y.exec(s));)S.add(g[1]),s=s.replace(`#lk{${g[1]}}`,"");S.forEach(t=>{console.log(t+" ")}),this.fs.writeFileSync(i,s)}}}else this.log("构建BoxJsJson传入参数格式错误，请传入json对象")}}isJsonObject(t){return"object"==typeof t&&"[object object]"==Object.prototype.toString.call(t).toLowerCase()&&!t.length}appendNotifyInfo(t,s){1==s?this.notifyInfo=t:this.notifyInfo.push(t)}prependNotifyInfo(t){this.notifyInfo.splice(0,0,t)}execFail(){this.execStatus=!1}isRequest(){return"undefined"!=typeof $request}isSurge(){return"undefined"!=typeof $httpClient}isQuanX(){return"undefined"!=typeof $task}isLoon(){return"undefined"!=typeof $loon}isJSBox(){return"undefined"!=typeof $app&&"undefined"!=typeof $http}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}isNode(){return"function"==typeof require&&!this.isJSBox()}async sleep(s){return new Promise(t=>setTimeout(t,s))}async wait(s){return new Promise(t=>setTimeout(t,s))}async delay(s){return new Promise(t=>setTimeout(t,s))}log(t){this.isEnableLog&&console.log(""+this.logSeparator+t)}logErr(t){this.execStatus=!0,this.isEnableLog&&(console.log(""+this.logSeparator+this.name+"执行异常:"),console.log(t),console.log("\n"+t.message))}msg(t,s,e,i){if((this.isRequest()||!this.isNotifyOnlyFail||!this.execStatus)&&(this.isEmpty(s)&&(s=Array.isArray(this.notifyInfo)?this.notifyInfo.join("\n"):this.notifyInfo),!this.isEmpty(s)))if(this.isEnableTgNotify){for(var r in this.log(this.name+"Tg通知开始"),this.tgEscapeCharMapping)this.tgEscapeCharMapping.hasOwnProperty(r)&&(s=s.replace(r,this.tgEscapeCharMapping[r]));this.get({url:encodeURI(this.tgNotifyUrl+"📌"+this.name+"\n"+s)},(t,s,e)=>{this.log("Tg通知完毕")})}else{var o={},h=!this.isEmpty(e),n=!this.isEmpty(i);this.isQuanX()&&(h&&(o["open-url"]=e),n&&(o["media-url"]=i),$notify(this.name,t,s,o)),(this.isSurge()||this.isStash())&&(h&&(o.url=e),$notification.post(this.name,t,s,o)),this.isNode()&&this.log("⭐️"+this.name+"\n"+t+"\n"+s),this.isJSBox()&&$push.schedule({title:this.name,body:t?t+"\n"+s:s})}}pushWxMsg(t,s,e,i=()=>{}){s={appToken:"AT_rTc93GQYIdMU8XLRnoJaSea8WkfhSzhX",content:s,summary:t,contentType:1,topicIds:[],uids:["UID_6P4B00X6Zv8U2oKC0I2R09emxtqq"],url:"",verifyPay:!1},e&&(s.url=e),t=this.getJsonDoneHeaders(),t.Host="wxpusher.zjiecode.com",t["Content-Type"]="application/json;charset=UTF-8",e={url:"https://wxpusher.zjiecode.com/api/send/message",headers:t,body:JSON.stringify(s)};this.post(e,i)}getVal(t,s=""){let e;return(e=this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loadData(),process.env[t]||this.data[t]):this.data&&this.data[t]||null)||s}setVal(t,s){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.write(s,t):this.isQuanX()?$prefs.setValueForKey(s,t):this.isNode()?(this.data=this.loadData(),this.data[t]=s,this.writeData(),!0):this.data&&this.data[t]||null}loadData(){if(!this.isNode())return{};this.fs=this.fs||require("fs"),this.path=this.path||require("path");var t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}writeData(){var t,s,e,i,r;this.isNode()&&(this.fs=this.fs||require("fs"),this.path=this.path||require("path"),t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),i=!(e=this.fs.existsSync(t))&&this.fs.existsSync(s),r=JSON.stringify(this.data),!e&&i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r))}adapterStatus(t){return t&&(t.status?t.statusCode=t.status:t.statusCode&&(t.status=t.statusCode)),t}get(t,i=()=>{}){this.isQuanX()&&((t="string"==typeof t?{url:t}:t).method="GET",$task.fetch(t).then(t=>{i(null,this.adapterStatus(t),t.body)},t=>i(t.error,null,null))),(this.isSurge()||this.isLoon()||this.isStash())&&$httpClient.get(t,(t,s,e)=>{i(t,this.adapterStatus(s),e)}),this.isNode()&&this.node.request(t,(t,s,e)=>{i(t,this.adapterStatus(s),e)}),this.isJSBox()&&((t="string"==typeof t?{url:t}:t).header=t.headers,t.handler=function(t){let s=t.error,e=(s=s&&JSON.stringify(t.error),t.data);"object"==typeof e&&(e=JSON.stringify(t.data)),i(s,this.adapterStatus(t.response),e)},$http.get(t))}post(t,i=()=>{}){this.isQuanX()&&((t="string"==typeof t?{url:t}:t).method="POST",$task.fetch(t).then(t=>{i(null,this.adapterStatus(t),t.body)},t=>i(t.error,null,null))),(this.isSurge()||this.isLoon()||this.isStash())&&$httpClient.post(t,(t,s,e)=>{i(t,this.adapterStatus(s),e)}),this.isNode()&&this.node.request.post(t,(t,s,e)=>{i(t,this.adapterStatus(s),e)}),this.isJSBox()&&((t="string"==typeof t?{url:t}:t).header=t.headers,t.handler=function(t){let s=t.error,e=(s=s&&JSON.stringify(t.error),t.data);"object"==typeof e&&(e=JSON.stringify(t.data)),i(s,this.adapterStatus(t.response),e)},$http.post(t))}put(t,i=()=>{}){this.isQuanX()&&((t="string"==typeof t?{url:t}:t).method="PUT",$task.fetch(t).then(t=>{i(null,this.adapterStatus(t),t.body)},t=>i(t.error,null,null))),(this.isSurge()||this.isLoon()||this.isStash())&&(t.method="PUT",$httpClient.put(t,(t,s,e)=>{i(t,this.adapterStatus(s),e)})),this.isNode()&&(t.method="PUT",this.node.request.put(t,(t,s,e)=>{i(t,this.adapterStatus(s),e)})),this.isJSBox()&&((t="string"==typeof t?{url:t}:t).header=t.headers,t.handler=function(t){let s=t.error,e=(s=s&&JSON.stringify(t.error),t.data);"object"==typeof e&&(e=JSON.stringify(t.data)),i(s,this.adapterStatus(t.response),e)},$http.post(t))}costTime(){let t=this.name+"执行完毕！";this.isNode()&&this.isExecComm&&(t=`指令【${this.comm[1]}】执行完毕！`);var s=(new Date).getTime()-this.startTime,e=s/1e3;this.execCount++,this.costTotalMs+=s,this.log(`${t}耗时【${e}】秒\n总共执行【${this.execCount}】次，平均耗时【${(this.costTotalMs/this.execCount/1e3).toFixed(4)}】秒`),this.setVal(this.costTotalStringKey,JSON.stringify(this.costTotalMs+","+this.execCount))}done(t={}){this.costTime(),(this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash())&&$done(t)}getRequestUrl(){return $request.url}getResponseBody(){if($response)return $response.body}isGetCookie(t){return!("OPTIONS"==$request.method||!this.getRequestUrl().match(t))}isEmpty(t){return void 0===t||null==t||""==t||"null"==t||"undefined"==t||0===t.length}randomString(s){s=s||32;var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890",i=e.length,r="";for(let t=0;t<s;t++)r+=e.charAt(Math.floor(Math.random()*i));return r}autoComplete(s,t,e,i,r,o,h,n,a,l){if((s+="").length<r)for(;s.length<r;)0==o?s+=i:s=i+s;if(h){let t="";for(var p=0;p<n;p++)t+=l;s=s.substring(0,a)+t+s.substring(n+a)}return this.toDBC(s=t+s+e)}customReplace(t,s,e,i){try{for(var r in this.isEmpty(e)&&(e="#{"),this.isEmpty(i)&&(i="}"),s)t=t.replace(""+e+r+i,s[r])}catch(t){this.logErr(t)}return t}toDBC(t){for(var s="",e=0;e<t.length;e++)32==t.charCodeAt(e)?s+=String.fromCharCode(12288):t.charCodeAt(e)<127&&(s+=String.fromCharCode(t.charCodeAt(e)+65248));return s}hash(t){let s=0,e,i;for(e=0;e<t.length;e++)i=t.charCodeAt(e),s=(s<<5)-s+i,s|=0;return String(s)}formatDate(t,s){var e,i={"M+":t.getMonth()+1,"d+":t.getDate(),"H+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"q+":Math.floor((t.getMonth()+3)/3),S:t.getMilliseconds()};for(e in/(y+)/.test(s)&&(s=s.replace(RegExp.$1,(t.getFullYear()+"").substr(4-RegExp.$1.length))),i)new RegExp("("+e+")").test(s)&&(s=s.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return s}parseDate(n,t){let a={y:0,M:1,d:0,H:0,h:0,m:0,s:0,S:0};(t=t||"yyyy-MM-dd").replace(/([^yMdHmsS]*?)(([yMdHmsS])\3*)([^yMdHmsS]*?)/g,function(t,s,e,i,r,o,h){return n=n.replace(new RegExp(s+"(\\d{"+e.length+"})"+r),function(t,s){return a[i]=parseInt(s),""}),""}),a.M--;t=new Date(a.y,a.M,a.d,a.H,a.m,a.s);return 0!==a.S&&t.setMilliseconds(a.S),t}objToQueryStr(s,e){let i="";for(const r in s){let t=s[r];null!=t&&""!==t&&("object"==typeof t?t=JSON.stringify(t):e&&(t=encodeURIComponent(t)),i+=`${r}=${t}&`)}return i=i.substring(0,i.length-1)}parseQueryStr(t){var s={},e=(t=-1<t.indexOf("?")?t.split("?")[1]:t).split("&");for(let t=0;t<e.length;t++){var i=e[t].split("=");s[i[0]]=i[1]}return s}deepClone(t,s){for(var e in s=s||{},t)"object"==typeof t[e]?(s[e]=t[e].constructor===Array?[]:{},this.deepClone(t[e],s[e])):s[e]=t[e];return s}getBaseDoneHeaders(t={}){return Object.assign({"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST,GET,OPTIONS,PUT,DELETE","Access-Control-Allow-Headers":"Origin, X-Requested-With, Content-Type, Accept"},t)}getHtmlDoneHeaders(){return this.getBaseDoneHeaders({"Content-Type":"text/html;charset=UTF-8"})}getJsonDoneHeaders(){return this.getBaseDoneHeaders({"Content-Type":"text/json; charset=utf-8",Connection:"keep-alive"})}shallowClone(t){var s,e={};for(s in t)t.hasOwnProperty(s)&&(e[s]=t[s]);return e}parseCookies(t){let s={};return t&&t.split(";").forEach(function(t){t=t.split("=");s[t.shift().trim()]=decodeURI(t.join("="))}),s}serializeCookies(t){var s,e=[];for(s in t){var i=t[s],i=encodeURIComponent(s)+"="+encodeURIComponent(i);e.push(i)}return e.join("; ")}parseSetCookies(t){const r=["Expires","Max-Age","Domain","Path","HttpOnly","SameSite"];t=t.split(";");let o=null;const h={},n=[];return t.forEach(t=>{var s,t=t.trim();let e=null,i=!0;if(t.includes("=")?(s=t.split("="),e=s[0].trim(),i=s[1].trim()):e=t,r.includes(e))h[o]&&(h[o][e]=i,h[o].attribs[e]=i);else{o=e;let s={};o.includes(",")&&o.split(",").forEach(t=>{t=t.trim();r.includes(t)?s[t]=!0:o=t}),h[o]={name:o,value:i,attribs:s},n.push(h[o])}}),n}base64Encode(t){var s,e,i,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";let o,h,n;for(n=t.length,h=0,o="";h<n;){if(s=255&t.charCodeAt(h++),h==n){o=(o+=r.charAt(s>>2))+r.charAt((3&s)<<4)+"==";break}if(e=t.charCodeAt(h++),h==n){o=(o=(o+=r.charAt(s>>2))+r.charAt((3&s)<<4|(240&e)>>4))+r.charAt((15&e)<<2)+"=";break}i=t.charCodeAt(h++),o=(o=(o=(o+=r.charAt(s>>2))+r.charAt((3&s)<<4|(240&e)>>4))+r.charAt((15&e)<<2|(192&i)>>6))+r.charAt(63&i)}return o}base64Decode(t){var s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(/([^\s]+[^0-9a-zA-Z\+\/\=]|[^0-9a-zA-Z\+\/\=]\s+)/.test(t))throw new Error("Invalid base64 input");var e,i,r,o,h,n,a=t.replace(/\s/g,"");let l="",p=0;for(;p<a.length;)r=s.indexOf(a.charAt(p++)),e=(15&(o=s.indexOf(a.charAt(p++))))<<4|(h=s.indexOf(a.charAt(p++)))>>2,i=(3&h)<<6|(n=s.indexOf(a.charAt(p++))),l+=String.fromCharCode(r<<2|o>>4),64!==h&&(l+=String.fromCharCode(e)),64!==n&&(l+=String.fromCharCode(i));return l=this.utf8Decode(l)}utf8Decode(s){let t=[],e=0,i=0,r=0;for(s=s.replace(/\r\n/g,"\n");e<s.length;){i=255&s.charCodeAt(e),r=0,r=i<=191?(i&=127,1):i<=223?(i&=31,2):i<=239?(i&=15,3):(i&=7,4);for(let t=1;t<r;++t)i=i<<6|63&s.charCodeAt(t+e);4===r?(i-=65536,t.push(String.fromCharCode(55296|i>>10&1023)),t.push(String.fromCharCode(56320|1023&i))):t.push(String.fromCharCode(i)),e+=r}return t.join("")}parseJwt(t){try{var s=t.split("."),e=s[0].replace(/-/g,"+").replace(/_/g,"/"),i=this.base64Decode(e).replace(/\0/g,""),r=JSON.parse(i),o=s[1].replace(/-/g,"+").replace(/_/g,"/"),h=this.base64Decode(o).replace(/\0/g,"");return{header:r,payload:JSON.parse(h),signature:s[2]}}catch(t){return this.log(t),null}}}(t,s,e)}
//---SyncByPyScript---ToolKit-end

//---SyncByPyScript---JSEncrypt-start
function createJSEncrypt(){function a(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function L(t,e){return t&e}function h(t,e){return t|e}function j(t,e){return t^e}function H(t,e){return t&~e}var u,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function r(t){for(var e,i="",r=0;r+3<=t.length;r+=3)e=parseInt(t.substring(r,r+3),16),i+=o.charAt(e>>6)+o.charAt(63&e);for(r+1==t.length?(e=parseInt(t.substring(r,r+1),16),i+=o.charAt(e<<2)):r+2==t.length&&(e=parseInt(t.substring(r,r+2),16),i+=o.charAt(e>>2)+o.charAt((3&e)<<4));0<(3&i.length);)i+="=";return i}function C(t){for(var e="",i=0,r=0,n=0;n<t.length&&"="!=t.charAt(n);++n){var s=o.indexOf(t.charAt(n));s<0||(i=0==i?(e+=a(s>>2),r=3&s,1):1==i?(e+=a(r<<2|s>>4),r=15&s,2):2==i?(e=(e+=a(r))+a(s>>2),r=3&s,3):(e=(e+=a(r<<2|s>>4))+a(15&s),0))}return 1==i&&(e+=a(r<<2)),e}var c,F=function(t){if(void 0===u){var e="0123456789ABCDEF",i=" \f\n\r\t \u2028\u2029";for(u={},o=0;o<16;++o)u[e.charAt(o)]=o;for(e=e.toLowerCase(),o=10;o<16;++o)u[e.charAt(o)]=o;for(o=0;o<i.length;++o)u[i.charAt(o)]=-1}for(var r=[],n=0,s=0,o=0;o<t.length;++o){var h=t.charAt(o);if("="==h)break;if(-1!=(h=u[h])){if(void 0===h)throw new Error("Illegal character at offset "+o);n|=h,2<=++s?(r[r.length]=n,s=n=0):n<<=4}}if(s)throw new Error("Hex encoding incomplete: 4 bits missing");return r},U={decode:function(t){if(void 0===c){var e="= \f\n\r\t \u2028\u2029";for(c=Object.create(null),s=0;s<64;++s)c["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(s)]=s;for(c["-"]=62,c._=63,s=0;s<e.length;++s)c[e.charAt(s)]=-1}for(var i=[],r=0,n=0,s=0;s<t.length;++s){var o=t.charAt(s);if("="==o)break;if(-1!=(o=c[o])){if(void 0===o)throw new Error("Illegal character at offset "+s);r|=o,4<=++n?(i[i.length]=r>>16,i[i.length]=r>>8&255,i[i.length]=255&r,n=r=0):r<<=6}}switch(n){case 1:throw new Error("Base64 encoding incomplete: at least 2 bits missing");case 2:i[i.length]=r>>10;break;case 3:i[i.length]=r>>16,i[i.length]=r>>8&255}return i},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(t){var e=U.re.exec(t);if(e)if(e[1])t=e[1];else{if(!e[2])throw new Error("RegExp out of sync");t=e[2]}return U.decode(t)}},f=1e13,l=(t.prototype.mulAdd=function(t,e){for(var i,r=this.buf,n=r.length,s=0;s<n;++s)(i=r[s]*t+e)<f?e=0:i-=(e=0|i/f)*f,r[s]=i;0<e&&(r[s]=e)},t.prototype.sub=function(t){for(var e,i=this.buf,r=i.length,n=0;n<r;++n)t=(e=i[n]-t)<0?(e+=f,1):0,i[n]=e;for(;0===i[i.length-1];)i.pop()},t.prototype.toString=function(t){if(10!=(t||10))throw new Error("only base 10 is supported");for(var e=this.buf,i=e[e.length-1].toString(),r=e.length-2;0<=r;--r)i+=(f+e[r]).toString().substring(1);return i},t.prototype.valueOf=function(){for(var t=this.buf,e=0,i=t.length-1;0<=i;--i)e=e*f+t[i];return e},t.prototype.simplify=function(){var t=this.buf;return 1==t.length?t[0]:this},t);function t(t){this.buf=[+t||0]}var K=/^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,k=/^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;function p(t,e){return t=t.length>e?t.substring(0,e)+"…":t}i.prototype.get=function(t){if((t=void 0===t?this.pos++:t)>=this.enc.length)throw new Error("Requesting byte offset ".concat(t," on a stream of length ").concat(this.enc.length));return"string"==typeof this.enc?this.enc.charCodeAt(t):this.enc[t]},i.prototype.hexByte=function(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(15&t)},i.prototype.hexDump=function(t,e,i){for(var r="",n=t;n<e;++n)if(r+=this.hexByte(this.get(n)),!0!==i)switch(15&n){case 7:r+="  ";break;case 15:r+="\n";break;default:r+=" "}return r},i.prototype.isASCII=function(t,e){for(var i=t;i<e;++i){var r=this.get(i);if(r<32||176<r)return!1}return!0},i.prototype.parseStringISO=function(t,e){for(var i="",r=t;r<e;++r)i+=String.fromCharCode(this.get(r));return i},i.prototype.parseStringUTF=function(t,e){for(var i="",r=t;r<e;){var n=this.get(r++);i+=n<128?String.fromCharCode(n):191<n&&n<224?String.fromCharCode((31&n)<<6|63&this.get(r++)):String.fromCharCode((15&n)<<12|(63&this.get(r++))<<6|63&this.get(r++))}return i},i.prototype.parseStringBMP=function(t,e){for(var i,r,n="",s=t;s<e;)i=this.get(s++),r=this.get(s++),n+=String.fromCharCode(i<<8|r);return n},i.prototype.parseTime=function(t,e,i){t=this.parseStringISO(t,e),e=(i?K:k).exec(t);return e?(i&&(e[1]=+e[1],e[1]+=+e[1]<70?2e3:1900),t=e[1]+"-"+e[2]+"-"+e[3]+" "+e[4],e[5]&&(t+=":"+e[5],e[6])&&(t+=":"+e[6],e[7])&&(t+="."+e[7]),e[8]&&(t+=" UTC","Z"!=e[8])&&(t+=e[8],e[9])&&(t+=":"+e[9]),t):"Unrecognized time: "+t},i.prototype.parseInteger=function(t,e){for(var i,r=this.get(t),n=127<r,s=n?255:0,o="";r==s&&++t<e;)r=this.get(t);if(0===(i=e-t))return n?-1:0;if(4<i){for(o=r,i<<=3;0==(128&(+o^s));)o=+o<<1,--i;o="("+i+" bit)\n"}n&&(r-=256);for(var h=new l(r),a=t+1;a<e;++a)h.mulAdd(256,this.get(a));return o+h.toString()},i.prototype.parseBitString=function(t,e,i){for(var r=this.get(t),n="("+((e-t-1<<3)-r)+" bit)\n",s="",o=t+1;o<e;++o){for(var h=this.get(o),a=o==e-1?r:0,u=7;a<=u;--u)s+=h>>u&1?"1":"0";if(s.length>i)return n+p(s,i)}return n+s},i.prototype.parseOctetString=function(t,e,i){if(this.isASCII(t,e))return p(this.parseStringISO(t,e),i);var r=e-t,n="("+r+" byte)\n";(i/=2)<r&&(e=t+i);for(var s=t;s<e;++s)n+=this.hexByte(this.get(s));return i<r&&(n+="…"),n},i.prototype.parseOID=function(t,e,i){for(var r="",n=new l,s=0,o=t;o<e;++o){var h=this.get(o);if(n.mulAdd(128,127&h),s+=7,!(128&h)){if(""===r?r=(n=n.simplify())instanceof l?(n.sub(80),"2."+n.toString()):(h=n<80?n<40?0:1:2)+"."+(n-40*h):r+="."+n.toString(),r.length>i)return p(r,i);n=new l,s=0}}return 0<s&&(r+=".incomplete"),r};var _=i;function i(t,e){this.hexDigits="0123456789ABCDEF",t instanceof i?(this.enc=t.enc,this.pos=t.pos):(this.enc=t,this.pos=e)}g.prototype.typeName=function(){switch(this.tag.tagClass){case 0:switch(this.tag.tagNumber){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString"}return"Universal_"+this.tag.tagNumber.toString();case 1:return"Application_"+this.tag.tagNumber.toString();case 2:return"["+this.tag.tagNumber.toString()+"]";case 3:return"Private_"+this.tag.tagNumber.toString()}},g.prototype.content=function(t){if(void 0!==this.tag){void 0===t&&(t=1/0);var e=this.posContent(),i=Math.abs(this.length);if(!this.tag.isUniversal())return null!==this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+i,t);switch(this.tag.tagNumber){case 1:return 0===this.stream.get(e)?"false":"true";case 2:return this.stream.parseInteger(e,e+i);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(e,e+i,t);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+i,t);case 6:return this.stream.parseOID(e,e+i,t);case 16:case 17:return null!==this.sub?"("+this.sub.length+" elem)":"(no elem)";case 12:return p(this.stream.parseStringUTF(e,e+i),t);case 18:case 19:case 20:case 21:case 22:case 26:return p(this.stream.parseStringISO(e,e+i),t);case 30:return p(this.stream.parseStringBMP(e,e+i),t);case 23:case 24:return this.stream.parseTime(e,e+i,23==this.tag.tagNumber)}}return null},g.prototype.toString=function(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(null===this.sub?"null":this.sub.length)+"]"},g.prototype.toPrettyString=function(t){var e=(t=void 0===t?"":t)+this.typeName()+" @"+this.stream.pos;if(0<=this.length&&(e+="+"),e+=this.length,this.tag.tagConstructed?e+=" (constructed)":!this.tag.isUniversal()||3!=this.tag.tagNumber&&4!=this.tag.tagNumber||null===this.sub||(e+=" (encapsulates)"),e+="\n",null!==this.sub){t+="  ";for(var i=0,r=this.sub.length;i<r;++i)e+=this.sub[i].toPrettyString(t)}return e},g.prototype.posStart=function(){return this.stream.pos},g.prototype.posContent=function(){return this.stream.pos+this.header},g.prototype.posEnd=function(){return this.stream.pos+this.header+Math.abs(this.length)},g.prototype.toHexString=function(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)},g.decodeLength=function(t){var e=127&(i=t.get());if(e==i)return e;if(6<e)throw new Error("Length over 48 bits not supported at position "+(t.pos-1));if(0==e)return null;for(var i=0,r=0;r<e;++r)i=256*i+t.get();return i},g.prototype.getHexStringValue=function(){var t=this.toHexString(),e=2*this.header,i=2*this.length;return t.substr(e,i)},g.decode=function(t){function e(){var t=[];if(null!==n){for(var e=s+n;r.pos<e;)t[t.length]=g.decode(r);if(r.pos!=e)throw new Error("Content size is not correct for container starting at offset "+s)}else try{for(;;){var i=g.decode(r);if(i.tag.isEOC())break;t[t.length]=i}n=s-r.pos}catch(t){throw new Error("Exception while decoding undefined length content: "+t)}return t}var r=t instanceof _?t:new _(t,0),t=new _(r),i=new Z(r),n=g.decodeLength(r),s=r.pos,o=s-t.pos,h=null;if(i.tagConstructed)h=e();else if(i.isUniversal()&&(3==i.tagNumber||4==i.tagNumber))try{if(3==i.tagNumber&&0!=r.get())throw new Error("BIT STRINGs with unused bits cannot encapsulate.");for(var h=e(),a=0;a<h.length;++a)if(h[a].tag.isEOC())throw new Error("EOC is not supposed to be actual content.")}catch(t){h=null}if(null===h){if(null===n)throw new Error("We can't skip over an invalid tag with undefined length at offset "+s);r.pos=s+Math.abs(n)}return new g(t,o,n,i,h)};var z=g;function g(t,e,i,r,n){if(!(r instanceof Z))throw new Error("Invalid tag value.");this.stream=t,this.header=e,this.length=i,this.tag=r,this.sub=n}G.prototype.isUniversal=function(){return 0===this.tagClass},G.prototype.isEOC=function(){return 0===this.tagClass&&0===this.tagNumber};var Z=G;function G(t){var e=t.get();if(this.tagClass=e>>6,this.tagConstructed=0!=(32&e),this.tagNumber=31&e,31==this.tagNumber){for(var i=new l;e=t.get(),i.mulAdd(128,127&e),128&e;);this.tagNumber=i.simplify()}}var d=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],$=(1<<26)/d[d.length-1],m=(y.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,r=(1<<e)-1,n=!1,s="",o=this.t,h=this.DB-o*this.DB%e;if(0<o--)for(h<this.DB&&0<(i=this[o]>>h)&&(n=!0,s=a(i));0<=o;)h<e?(i=(this[o]&(1<<h)-1)<<e-h,i|=this[--o]>>(h+=this.DB-e)):(i=this[o]>>(h-=e)&r,h<=0&&(h+=this.DB,--o)),(n=0<i?!0:n)&&(s+=a(i));return n?s:"0"},y.prototype.negate=function(){var t=b();return y.ZERO.subTo(this,t),t},y.prototype.abs=function(){return this.s<0?this.negate():this},y.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;0<=--i;)if(0!=(e=this[i]-t[i]))return e;return 0},y.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+R(this[this.t-1]^this.s&this.DM)},y.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&0<e.compareTo(y.ZERO)&&t.subTo(e,e),e},y.prototype.modPowInt=function(t,e){e=new(t<256||e.isEven()?J:X)(e);return this.exp(t,e)},y.prototype.clone=function(){var t=b();return this.copyTo(t),t},y.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]},y.prototype.byteValue=function(){return 0==this.t?this.s:this[0]<<24>>24},y.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},y.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},y.prototype.toByteArray=function(){var t,e=this.t,i=[],r=(i[0]=this.s,this.DB-e*this.DB%8),n=0;if(0<e--)for(r<this.DB&&(t=this[e]>>r)!=(this.s&this.DM)>>r&&(i[n++]=t|this.s<<this.DB-r);0<=e;)r<8?(t=(this[e]&(1<<r)-1)<<8-r,t|=this[--e]>>(r+=this.DB-8)):(t=this[e]>>(r-=8)&255,r<=0&&(r+=this.DB,--e)),0!=(128&t)&&(t|=-256),0==n&&(128&this.s)!=(128&t)&&++n,(0<n||t!=this.s)&&(i[n++]=t);return i},y.prototype.equals=function(t){return 0==this.compareTo(t)},y.prototype.min=function(t){return this.compareTo(t)<0?this:t},y.prototype.max=function(t){return 0<this.compareTo(t)?this:t},y.prototype.and=function(t){var e=b();return this.bitwiseTo(t,L,e),e},y.prototype.or=function(t){var e=b();return this.bitwiseTo(t,h,e),e},y.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,j,e),e},y.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,H,e),e},y.prototype.not=function(){for(var t=b(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t},y.prototype.shiftLeft=function(t){var e=b();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e},y.prototype.shiftRight=function(t){var e=b();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e},y.prototype.getLowestSetBit=function(){for(var t,e,i=0;i<this.t;++i)if(0!=this[i])return i*this.DB+(t=this[i],e=void 0,0==t?-1:((e=0)==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e));return this.s<0?this.t*this.DB:-1},y.prototype.bitCount=function(){for(var t=0,e=this.s&this.DM,i=0;i<this.t;++i)t+=function(t){for(var e=0;0!=t;)t&=t-1,++e;return e}(this[i]^e);return t},y.prototype.testBit=function(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:0!=(this[e]&1<<t%this.DB)},y.prototype.setBit=function(t){return this.changeBit(t,h)},y.prototype.clearBit=function(t){return this.changeBit(t,H)},y.prototype.flipBit=function(t){return this.changeBit(t,j)},y.prototype.add=function(t){var e=b();return this.addTo(t,e),e},y.prototype.subtract=function(t){var e=b();return this.subTo(t,e),e},y.prototype.multiply=function(t){var e=b();return this.multiplyTo(t,e),e},y.prototype.divide=function(t){var e=b();return this.divRemTo(t,e,null),e},y.prototype.remainder=function(t){var e=b();return this.divRemTo(t,null,e),e},y.prototype.divideAndRemainder=function(t){var e=b(),i=b();return this.divRemTo(t,e,i),[e,i]},y.prototype.modPow=function(t,e){var i=t.bitLength(),r=x(1);if(i<=0)return r;var n=i<18?1:i<48?3:i<144?4:i<768?5:6,s=new(i<8?J:e.isEven()?Q:X)(e),o=[],h=3,a=n-1,u=(1<<n)-1;if(o[1]=s.convert(this),1<n){var c=b();for(s.sqrTo(o[1],c);h<=u;)o[h]=b(),s.mulTo(c,o[h-2],o[h]),h+=2}for(var f,l,p=t.t-1,g=!0,d=b(),i=R(t[p])-1;0<=p;){for(a<=i?f=t[p]>>i-a&u:(f=(t[p]&(1<<i+1)-1)<<a-i,0<p&&(f|=t[p-1]>>this.DB+i-a)),h=n;0==(1&f);)f>>=1,--h;if((i-=h)<0&&(i+=this.DB,--p),g)o[f].copyTo(r),g=!1;else{for(;1<h;)s.sqrTo(r,d),s.sqrTo(d,r),h-=2;0<h?s.sqrTo(r,d):(l=r,r=d,d=l),s.mulTo(d,o[f],r)}for(;0<=p&&0==(t[p]&1<<i);)s.sqrTo(r,d),l=r,r=d,d=l,--i<0&&(i=this.DB-1,--p)}return s.revert(r)},y.prototype.modInverse=function(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return y.ZERO;for(var i=t.clone(),r=this.clone(),n=x(1),s=x(0),o=x(0),h=x(1);0!=i.signum();){for(;i.isEven();)i.rShiftTo(1,i),e?(n.isEven()&&s.isEven()||(n.addTo(this,n),s.subTo(t,s)),n.rShiftTo(1,n)):s.isEven()||s.subTo(t,s),s.rShiftTo(1,s);for(;r.isEven();)r.rShiftTo(1,r),e?(o.isEven()&&h.isEven()||(o.addTo(this,o),h.subTo(t,h)),o.rShiftTo(1,o)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);0<=i.compareTo(r)?(i.subTo(r,i),e&&n.subTo(o,n),s.subTo(h,s)):(r.subTo(i,r),e&&o.subTo(n,o),h.subTo(s,h))}return 0!=r.compareTo(y.ONE)?y.ZERO:0<=h.compareTo(t)?h.subtract(t):h.signum()<0&&(h.addTo(t,h),h.signum()<0)?h.add(t):h},y.prototype.pow=function(t){return this.exp(t,new Y)},y.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone(),r=(e.compareTo(i)<0&&(t=e,e=i,i=t),e.getLowestSetBit()),t=i.getLowestSetBit();if(t<0)return e;for(0<(t=r<t?r:t)&&(e.rShiftTo(t,e),i.rShiftTo(t,i));0<e.signum();)0<(r=e.getLowestSetBit())&&e.rShiftTo(r,e),0<(r=i.getLowestSetBit())&&i.rShiftTo(r,i),0<=e.compareTo(i)?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return 0<t&&i.lShiftTo(t,i),i},y.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=d[d.length-1]){for(e=0;e<d.length;++e)if(i[0]==d[e])return!0;return!1}if(i.isEven())return!1;for(e=1;e<d.length;){for(var r=d[e],n=e+1;n<d.length&&r<$;)r*=d[n++];for(r=i.modInt(r);e<n;)if(r%d[e++]==0)return!1}return i.millerRabin(t)},y.prototype.copyTo=function(t){for(var e=this.t-1;0<=e;--e)t[e]=this[e];t.t=this.t,t.s=this.s},y.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,0<t?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},y.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var r=t.length,n=!1,s=0;0<=--r;){var o=8==i?255&+t[r]:W(t,r);o<0?"-"==t.charAt(r)&&(n=!0):(n=!1,0==s?this[this.t++]=o:s+i>this.DB?(this[this.t-1]|=(o&(1<<this.DB-s)-1)<<s,this[this.t++]=o>>this.DB-s):this[this.t-1]|=o<<s,(s+=i)>=this.DB&&(s-=this.DB))}8==i&&0!=(128&+t[0])&&(this.s=-1,0<s)&&(this[this.t-1]|=(1<<this.DB-s)-1<<s),this.clamp(),n&&y.ZERO.subTo(this,this)},y.prototype.clamp=function(){for(var t=this.s&this.DM;0<this.t&&this[this.t-1]==t;)--this.t},y.prototype.dlShiftTo=function(t,e){for(var i=this.t-1;0<=i;--i)e[i+t]=this[i];for(i=t-1;0<=i;--i)e[i]=0;e.t=this.t+t,e.s=this.s},y.prototype.drShiftTo=function(t,e){for(var i=t;i<this.t;++i)e[i-t]=this[i];e.t=Math.max(this.t-t,0),e.s=this.s},y.prototype.lShiftTo=function(t,e){for(var i=t%this.DB,r=this.DB-i,n=(1<<r)-1,s=Math.floor(t/this.DB),o=this.s<<i&this.DM,h=this.t-1;0<=h;--h)e[h+s+1]=this[h]>>r|o,o=(this[h]&n)<<i;for(h=s-1;0<=h;--h)e[h]=0;e[s]=o,e.t=this.t+s+1,e.s=this.s,e.clamp()},y.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var r=t%this.DB,n=this.DB-r,s=(1<<r)-1;e[0]=this[i]>>r;for(var o=i+1;o<this.t;++o)e[o-i-1]|=(this[o]&s)<<n,e[o-i]=this[o]>>r;0<r&&(e[this.t-i-1]|=(this.s&s)<<n),e.t=this.t-i,e.clamp()}},y.prototype.subTo=function(t,e){for(var i=0,r=0,n=Math.min(t.t,this.t);i<n;)r+=this[i]-t[i],e[i++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;i<this.t;)r+=this[i],e[i++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;i<t.t;)r-=t[i],e[i++]=r&this.DM,r>>=this.DB;r-=t.s}e.s=r<0?-1:0,r<-1?e[i++]=this.DV+r:0<r&&(e[i++]=r),e.t=i,e.clamp()},y.prototype.multiplyTo=function(t,e){var i=this.abs(),r=t.abs(),n=i.t;for(e.t=n+r.t;0<=--n;)e[n]=0;for(n=0;n<r.t;++n)e[n+i.t]=i.am(0,r[n],e,n,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&y.ZERO.subTo(e,e)},y.prototype.squareTo=function(t){for(var e=this.abs(),i=t.t=2*e.t;0<=--i;)t[i]=0;for(i=0;i<e.t-1;++i){var r=e.am(i,e[i],t,2*i,0,1);(t[i+e.t]+=e.am(i+1,2*e[i],t,2*i+1,r,e.t-i-1))>=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}0<t.t&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},y.prototype.divRemTo=function(t,e,i){var r=t.abs();if(!(r.t<=0)){var n=this.abs();if(n.t<r.t)null!=e&&e.fromInt(0),null!=i&&this.copyTo(i);else{null==i&&(i=b());var s=b(),o=this.s,t=t.s,h=this.DB-R(r[r.t-1]),a=(0<h?(r.lShiftTo(h,s),n.lShiftTo(h,i)):(r.copyTo(s),n.copyTo(i)),s.t),u=s[a-1];if(0!=u){var r=u*(1<<this.F1)+(1<a?s[a-2]>>this.F2:0),c=this.FV/r,f=(1<<this.F1)/r,l=1<<this.F2,p=i.t,g=p-a,d=null==e?b():e;for(s.dlShiftTo(g,d),0<=i.compareTo(d)&&(i[i.t++]=1,i.subTo(d,i)),y.ONE.dlShiftTo(a,d),d.subTo(s,s);s.t<a;)s[s.t++]=0;for(;0<=--g;){var m=i[--p]==u?this.DM:Math.floor(i[p]*c+(i[p-1]+l)*f);if((i[p]+=s.am(0,m,i,g,0,a))<m)for(s.dlShiftTo(g,d),i.subTo(d,i);i[p]<--m;)i.subTo(d,i)}null!=e&&(i.drShiftTo(a,e),o!=t)&&y.ZERO.subTo(e,e),i.t=a,i.clamp(),0<h&&i.rShiftTo(h,i),o<0&&y.ZERO.subTo(i,i)}}}},y.prototype.invDigit=function(){var t,e;return this.t<1||0==(1&(t=this[0]))?0:0<(e=(e=(e=(e=(e=3&t)*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)?this.DV-e:-e},y.prototype.isEven=function(){return 0==(0<this.t?1&this[0]:this.s)},y.prototype.exp=function(t,e){if(4294967295<t||t<1)return y.ONE;var i,r=b(),n=b(),s=e.convert(this),o=R(t)-1;for(s.copyTo(r);0<=--o;)e.sqrTo(r,n),0<(t&1<<o)?e.mulTo(n,s,r):(i=r,r=n,n=i);return e.revert(r)},y.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},y.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||36<t)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),r=x(i),n=b(),s=b(),o="";for(this.divRemTo(r,n,s);0<n.signum();)o=(i+s.intValue()).toString(t).substr(1)+o,n.divRemTo(r,n,s);return s.intValue().toString(t)+o},y.prototype.fromRadix=function(t,e){this.fromInt(0);for(var i=this.chunkSize(e=null==e?10:e),r=Math.pow(e,i),n=!1,s=0,o=0,h=0;h<t.length;++h){var a=W(t,h);a<0?"-"==t.charAt(h)&&0==this.signum()&&(n=!0):(o=e*o+a,++s>=i&&(this.dMultiply(r),this.dAddOffset(o,0),o=s=0))}0<s&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(o,0)),n&&y.ZERO.subTo(this,this)},y.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(y.ONE.shiftLeft(t-1),h,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(y.ONE.shiftLeft(t-1),this);else{var i=[],r=7&t;i.length=1+(t>>3),e.nextBytes(i),0<r?i[0]&=(1<<r)-1:i[0]=0,this.fromString(i,256)}},y.prototype.bitwiseTo=function(t,e,i){for(var r,n=Math.min(t.t,this.t),s=0;s<n;++s)i[s]=e(this[s],t[s]);if(t.t<this.t){for(r=t.s&this.DM,s=n;s<this.t;++s)i[s]=e(this[s],r);i.t=this.t}else{for(r=this.s&this.DM,s=n;s<t.t;++s)i[s]=e(r,t[s]);i.t=t.t}i.s=e(this.s,t.s),i.clamp()},y.prototype.changeBit=function(t,e){t=y.ONE.shiftLeft(t);return this.bitwiseTo(t,e,t),t},y.prototype.addTo=function(t,e){for(var i=0,r=0,n=Math.min(t.t,this.t);i<n;)r+=this[i]+t[i],e[i++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r+=t.s;i<this.t;)r+=this[i],e[i++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;i<t.t;)r+=t[i],e[i++]=r&this.DM,r>>=this.DB;r+=t.s}e.s=r<0?-1:0,0<r?e[i++]=r:r<-1&&(e[i++]=this.DV+r),e.t=i,e.clamp()},y.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},y.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},y.prototype.multiplyLowerTo=function(t,e,i){var r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;0<r;)i[--r]=0;for(var n=i.t-this.t;r<n;++r)i[r+this.t]=this.am(0,t[r],i,r,0,this.t);for(n=Math.min(t.t,e);r<n;++r)this.am(0,t[r],i,r,0,e-r);i.clamp()},y.prototype.multiplyUpperTo=function(t,e,i){var r=i.t=this.t+t.t- --e;for(i.s=0;0<=--r;)i[r]=0;for(r=Math.max(e-this.t,0);r<t.t;++r)i[this.t+r-e]=this.am(e-r,t[r],i,0,0,this.t+r-e);i.clamp(),i.drShiftTo(1,i)},y.prototype.modInt=function(t){if(t<=0)return 0;var e=this.DV%t,i=this.s<0?t-1:0;if(0<this.t)if(0==e)i=this[0]%t;else for(var r=this.t-1;0<=r;--r)i=(e*i+this[r])%t;return i},y.prototype.millerRabin=function(t){var e=this.subtract(y.ONE),i=e.getLowestSetBit();if(i<=0)return!1;for(var r=e.shiftRight(i),n=(d.length<(t=t+1>>1)&&(t=d.length),b()),s=0;s<t;++s){n.fromInt(d[Math.floor(Math.random()*d.length)]);var o=n.modPow(r,this);if(0!=o.compareTo(y.ONE)&&0!=o.compareTo(e)){for(var h=1;h++<i&&0!=o.compareTo(e);)if(0==(o=o.modPowInt(2,this)).compareTo(y.ONE))return!1;if(0!=o.compareTo(e))return!1}}return!0},y.prototype.square=function(){var t=b();return this.squareTo(t),t},y.prototype.gcda=function(t,e){var i,r=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone(),s=(r.compareTo(n)<0&&(t=r,r=n,n=t),r.getLowestSetBit()),o=n.getLowestSetBit();o<0?e(r):(0<(o=s<o?s:o)&&(r.rShiftTo(o,r),n.rShiftTo(o,n)),i=function(){0<(s=r.getLowestSetBit())&&r.rShiftTo(s,r),0<(s=n.getLowestSetBit())&&n.rShiftTo(s,n),0<=r.compareTo(n)?(r.subTo(n,r),r.rShiftTo(1,r)):(n.subTo(r,n),n.rShiftTo(1,n)),0<r.signum()?setTimeout(i,0):(0<o&&n.lShiftTo(o,n),setTimeout(function(){e(n)},0))},setTimeout(i,10))},y.prototype.fromNumberAsync=function(t,e,i,r){var n,s,o;"number"==typeof e?t<2?this.fromInt(1):(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(y.ONE.shiftLeft(t-1),h,this),this.isEven()&&this.dAddOffset(1,0),n=this,s=function(){n.dAddOffset(2,0),n.bitLength()>t&&n.subTo(y.ONE.shiftLeft(t-1),n),n.isProbablePrime(e)?setTimeout(function(){r()},0):setTimeout(s,0)},setTimeout(s,0)):(i=7&t,(o=[]).length=1+(t>>3),e.nextBytes(o),0<i?o[0]&=(1<<i)-1:o[0]=0,this.fromString(o,256))},y);function y(t,e,i){null!=t&&("number"==typeof t?this.fromNumber(t,e,i):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}e.prototype.convert=function(t){return t},e.prototype.revert=function(t){return t},e.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},e.prototype.sqrTo=function(t,e){t.squareTo(e)};var Y=e;function e(){}n.prototype.convert=function(t){return t.s<0||0<=t.compareTo(this.m)?t.mod(this.m):t},n.prototype.revert=function(t){return t},n.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},n.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},n.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var J=n;function n(t){this.m=t}s.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&0<e.compareTo(m.ZERO)&&this.m.subTo(e,e),e},s.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},s.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var i=32767&t[e],r=i*this.mpl+((i*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,r,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),0<=t.compareTo(this.m)&&t.subTo(this.m,t)},s.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},s.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var X=s;function s(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}v.prototype.convert=function(t){var e;return t.s<0||t.t>2*this.m.t?t.mod(this.m):t.compareTo(this.m)<0?t:(e=b(),t.copyTo(e),this.reduce(e),e)},v.prototype.revert=function(t){return t},v.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);0<=t.compareTo(this.m);)t.subTo(this.m,t)},v.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},v.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var Q=v;function v(t){this.m=t,this.r2=b(),this.q3=b(),m.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t)}function b(){return new m(null)}function T(t,e){return new m(t,e)}for(var S="undefined"!=typeof navigator,S=S&&"Microsoft Internet Explorer"==navigator.appName?(m.prototype.am=function(t,e,i,r,n,s){for(var o=32767&e,h=e>>15;0<=--s;){var a=32767&this[t],u=this[t++]>>15,c=h*a+u*o;n=((a=o*a+((32767&c)<<15)+i[r]+(1073741823&n))>>>30)+(c>>>15)+h*u+(n>>>30),i[r++]=1073741823&a}return n},30):S&&"Netscape"!=navigator.appName?(m.prototype.am=function(t,e,i,r,n,s){for(;0<=--s;){var o=e*this[t++]+i[r]+n;n=Math.floor(o/67108864),i[r++]=67108863&o}return n},26):(m.prototype.am=function(t,e,i,r,n,s){for(var o=16383&e,h=e>>14;0<=--s;){var a=16383&this[t],u=this[t++]>>14,c=h*a+u*o;n=((a=o*a+((16383&c)<<14)+i[r]+n)>>28)+(c>>14)+h*u,i[r++]=268435455&a}return n},28),E=(m.prototype.DB=S,m.prototype.DM=(1<<S)-1,m.prototype.DV=1<<S,m.prototype.FV=Math.pow(2,52),m.prototype.F1=52-S,m.prototype.F2=2*S-52,[]),w="0".charCodeAt(0),D=0;D<=9;++D)E[w++]=D;for(w="a".charCodeAt(0),D=10;D<36;++D)E[w++]=D;for(w="A".charCodeAt(0),D=10;D<36;++D)E[w++]=D;function W(t,e){t=E[t.charCodeAt(e)];return null==t?-1:t}function x(t){var e=b();return e.fromInt(t),e}function R(t){var e,i=1;return 0!=(e=t>>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}m.ZERO=x(0),m.ONE=x(1);et.prototype.init=function(t){for(var e,i,r=0;r<256;++r)this.S[r]=r;for(r=e=0;r<256;++r)e=e+this.S[r]+t[r%t.length]&255,i=this.S[r],this.S[r]=this.S[e],this.S[e]=i;this.i=0,this.j=0},et.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]};var tt=et;function et(){this.i=0,this.j=0,this.S=[]}var it,B,A,rt,nt,O,V=null;if(null==V){if(V=[],A=void(B=0),"undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues)for(rt=new Uint32Array(256),window.crypto.getRandomValues(rt),A=0;A<rt.length;++A)V[B++]=255&rt[A];nt=0,O=function(t){if(256<=(nt=nt||0)||256<=B)window.removeEventListener?window.removeEventListener("mousemove",O,!1):window.detachEvent&&window.detachEvent("onmousemove",O);else try{var e=t.x+t.y;V[B++]=255&e,nt+=1}catch(t){}},"undefined"!=typeof window&&(window.addEventListener?window.addEventListener("mousemove",O,!1):window.attachEvent&&window.attachEvent("onmousemove",O))}function st(){if(null==it){for(it=new tt;B<256;){var t=Math.floor(65536*Math.random());V[B++]=255&t}for(it.init(V),B=0;B<V.length;++B)V[B]=0;B=0}return it.next()}ht.prototype.nextBytes=function(t){for(var e=0;e<t.length;++e)t[e]=st()};var ot=ht;function ht(){}I.prototype.doPublic=function(t){return t.modPowInt(this.e,this.n)},I.prototype.doPrivate=function(t){if(null==this.p||null==this.q)return t.modPow(this.d,this.n);for(var e=t.mod(this.p).modPow(this.dmp1,this.p),i=t.mod(this.q).modPow(this.dmq1,this.q);e.compareTo(i)<0;)e=e.add(this.p);return e.subtract(i).multiply(this.coeff).mod(this.p).multiply(this.q).add(i)},I.prototype.setPublic=function(t,e){null!=t&&null!=e&&0<t.length&&0<e.length?(this.n=T(t,16),this.e=parseInt(e,16)):console.error("Invalid RSA public key")},I.prototype.encrypt=function(t){var e=this.n.bitLength()+7>>3,t=function(t,e){if(e<t.length+11)return console.error("Message too long for RSA"),null;for(var i=[],r=t.length-1;0<=r&&0<e;){var n=t.charCodeAt(r--);n<128?i[--e]=n:127<n&&n<2048?(i[--e]=63&n|128,i[--e]=n>>6|192):(i[--e]=63&n|128,i[--e]=n>>6&63|128,i[--e]=n>>12|224)}i[--e]=0;for(var s=new ot,o=[];2<e;){for(o[0]=0;0==o[0];)s.nextBytes(o);i[--e]=o[0]}return i[--e]=2,i[--e]=0,new m(i)}(t,e);if(null==t)return null;t=this.doPublic(t);if(null==t)return null;for(var i=t.toString(16),r=i.length,n=0;n<2*e-r;n++)i="0"+i;return i},I.prototype.setPrivate=function(t,e,i){null!=t&&null!=e&&0<t.length&&0<e.length?(this.n=T(t,16),this.e=parseInt(e,16),this.d=T(i,16)):console.error("Invalid RSA private key")},I.prototype.setPrivateEx=function(t,e,i,r,n,s,o,h){null!=t&&null!=e&&0<t.length&&0<e.length?(this.n=T(t,16),this.e=parseInt(e,16),this.d=T(i,16),this.p=T(r,16),this.q=T(n,16),this.dmp1=T(s,16),this.dmq1=T(o,16),this.coeff=T(h,16)):console.error("Invalid RSA private key")},I.prototype.generate=function(t,e){for(var i=new ot,r=t>>1,n=(this.e=parseInt(e,16),new m(e,16));;){for(;this.p=new m(t-r,1,i),0!=this.p.subtract(m.ONE).gcd(n).compareTo(m.ONE)||!this.p.isProbablePrime(10););for(;this.q=new m(r,1,i),0!=this.q.subtract(m.ONE).gcd(n).compareTo(m.ONE)||!this.q.isProbablePrime(10););this.p.compareTo(this.q)<=0&&(s=this.p,this.p=this.q,this.q=s);var s=this.p.subtract(m.ONE),o=this.q.subtract(m.ONE),h=s.multiply(o);if(0==h.gcd(n).compareTo(m.ONE)){this.n=this.p.multiply(this.q),this.d=n.modInverse(h),this.dmp1=this.d.mod(s),this.dmq1=this.d.mod(o),this.coeff=this.q.modInverse(this.p);break}}},I.prototype.decrypt=function(t){t=T(t,16),t=this.doPrivate(t);if(null==t)return null;for(var e=this.n.bitLength()+7>>3,i=t.toByteArray(),r=0;r<i.length&&0==i[r];)++r;if(i.length-r!=e-1||2!=i[r])return null;for(++r;0!=i[r];)if(++r>=i.length)return null;for(var n="";++r<i.length;){var s=255&i[r];s<128?n+=String.fromCharCode(s):191<s&&s<224?(n+=String.fromCharCode((31&s)<<6|63&i[r+1]),++r):(n+=String.fromCharCode((15&s)<<12|(63&i[r+1])<<6|63&i[r+2]),r+=2)}return n},I.prototype.generateAsync=function(t,e,n){var s=new ot,o=t>>1,h=(this.e=parseInt(e,16),new m(e,16)),a=this,u=function(){function e(){a.p=b(),a.p.fromNumberAsync(t-o,1,s,function(){a.p.subtract(m.ONE).gcda(h,function(t){0==t.compareTo(m.ONE)&&a.p.isProbablePrime(10)?setTimeout(r,0):setTimeout(e,0)})})}var i=function(){a.p.compareTo(a.q)<=0&&(t=a.p,a.p=a.q,a.q=t);var t=a.p.subtract(m.ONE),e=a.q.subtract(m.ONE),i=t.multiply(e);0==i.gcd(h).compareTo(m.ONE)?(a.n=a.p.multiply(a.q),a.d=h.modInverse(i),a.dmp1=a.d.mod(t),a.dmq1=a.d.mod(e),a.coeff=a.q.modInverse(a.p),setTimeout(function(){n()},0)):setTimeout(u,0)},r=function(){a.q=b(),a.q.fromNumberAsync(o,1,s,function(){a.q.subtract(m.ONE).gcda(h,function(t){0==t.compareTo(m.ONE)&&a.q.isProbablePrime(10)?setTimeout(i,0):setTimeout(r,0)})})};setTimeout(e,0)};setTimeout(u,0)},I.prototype.sign=function(t,e,i){i=function(t,e){if(e<t.length+22)return console.error("Message too long for RSA"),null;for(var i=e-t.length-6,r="",n=0;n<i;n+=2)r+="ff";return T("0001"+r+"00"+t,16)}((at[i]||"")+e(t).toString(),this.n.bitLength()/4);return null==i||null==(e=this.doPrivate(i))?null:0==(1&(t=e.toString(16)).length)?t:"0"+t},I.prototype.verify=function(t,e,i){e=T(e,16),e=this.doPublic(e);return null==e?null:function(t){for(var e in at)if(at.hasOwnProperty(e)){var e=at[e],i=e.length;if(t.substr(0,i)==e)return t.substr(i)}return t}(e.toString(16).replace(/^1f+00/,""))==i(t).toString()};S=I;function I(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}var at={md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",ripemd160:"3021300906052b2403020105000414"};var N={lang:{extend:function(t,e,i){if(!e||!t)throw new Error("YAHOO.lang.extend failed, please check that all dependencies are included.");function r(){}if(r.prototype=e.prototype,t.prototype=new r,(t.prototype.constructor=t).superclass=e.prototype,e.prototype.constructor==Object.prototype.constructor&&(e.prototype.constructor=e),i){for(var n in i)t.prototype[n]=i[n];var e=function(){},s=["toString","valueOf"];try{/MSIE/.test(navigator.userAgent)&&(e=function(t,e){for(n=0;n<s.length;n+=1){var i=s[n],r=e[i];"function"==typeof r&&r!=Object.prototype[i]&&(t[i]=r)}})}catch(t){}e(t.prototype,i)}}}},P={};void 0!==P.asn1&&P.asn1||(P.asn1={}),P.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){t=t.toString(16);return t=t.length%2==1?"0"+t:t},this.bigIntToMinTwosComplementsHex=function(t){if("-"!=(n=t.toString(16)).substr(0,1))n.length%2==1?n="0"+n:n.match(/^[0-7]/)||(n="00"+n);else{for(var e=n.substr(1).length,i=(e%2==1?e+=1:n.match(/^[0-7]/)||(e+=2),""),r=0;r<e;r++)i+="f";var n=new m(i,16).xor(t).add(m.ONE).toString(16).replace(/^-/,"")}return n},this.getPEMStringFromHex=function(t,e){return hextopem(t,e)},this.newObject=function(t){var e=P.asn1,i=e.DERBoolean,r=e.DERInteger,n=e.DERBitString,s=e.DEROctetString,o=e.DERNull,h=e.DERObjectIdentifier,a=e.DEREnumerated,u=e.DERUTF8String,c=e.DERNumericString,f=e.DERPrintableString,l=e.DERTeletexString,p=e.DERIA5String,g=e.DERUTCTime,d=e.DERGeneralizedTime,m=e.DERSequence,y=e.DERSet,v=e.DERTaggedObject,b=e.ASN1Util.newObject,e=Object.keys(t);if(1!=e.length)throw"key of param shall be only one.";e=e[0];if(-1==":bool:int:bitstr:octstr:null:oid:enum:utf8str:numstr:prnstr:telstr:ia5str:utctime:gentime:seq:set:tag:".indexOf(":"+e+":"))throw"undefined key: "+e;if("bool"==e)return new i(t[e]);if("int"==e)return new r(t[e]);if("bitstr"==e)return new n(t[e]);if("octstr"==e)return new s(t[e]);if("null"==e)return new o(t[e]);if("oid"==e)return new h(t[e]);if("enum"==e)return new a(t[e]);if("utf8str"==e)return new u(t[e]);if("numstr"==e)return new c(t[e]);if("prnstr"==e)return new f(t[e]);if("telstr"==e)return new l(t[e]);if("ia5str"==e)return new p(t[e]);if("utctime"==e)return new g(t[e]);if("gentime"==e)return new d(t[e]);if("seq"==e){for(var T=t[e],S=[],E=0;E<T.length;E++){var w=b(T[E]);S.push(w)}return new m({array:S})}if("set"==e){for(T=t[e],S=[],E=0;E<T.length;E++){w=b(T[E]);S.push(w)}return new y({array:S})}if("tag"==e){i=t[e];if("[object Array]"===Object.prototype.toString.call(i)&&3==i.length)return r=b(i[2]),new v({tag:i[0],explicit:i[1],obj:r});n={};if(void 0!==i.explicit&&(n.explicit=i.explicit),void 0!==i.tag&&(n.tag=i.tag),void 0===i.obj)throw"obj shall be specified for 'tag'.";return n.obj=b(i.obj),new v(n)}},this.jsonToASN1HEX=function(t){return this.newObject(t).getEncodedHex()}},P.asn1.ASN1Util.oidHexToInt=function(t){for(var e="",i=parseInt(t.substr(0,2),16),e=Math.floor(i/40)+"."+i%40,r="",n=2;n<t.length;n+=2){var s=("00000000"+parseInt(t.substr(n,2),16).toString(2)).slice(-8);r+=s.substr(1,7),"0"==s.substr(0,1)&&(e=e+"."+new m(r,2).toString(10),r="")}return e},P.asn1.ASN1Util.oidIntToHex=function(t){var h=function(t){t=t.toString(16);return t=1==t.length?"0"+t:t};if(!t.match(/^[0-9.]+$/))throw"malformed oid string: "+t;var e="",i=t.split("."),t=40*parseInt(i[0])+parseInt(i[1]);e+=h(t),i.splice(0,2);for(var r=0;r<i.length;r++)e+=function(t){for(var e="",i=7-(s=new m(t,10).toString(2)).length%7,r=(7==i&&(i=0),""),n=0;n<i;n++)r+="0";for(var s=r+s,n=0;n<s.length-1;n+=7){var o=s.substr(n,7);n!=s.length-7&&(o="1"+o),e+=h(parseInt(o,2))}return e}(i[r]);return e},P.asn1.ASN1Object=function(){this.getLengthHexFromValue=function(){if(void 0===this.hV||null==this.hV)throw"this.hV is null or undefined.";if(this.hV.length%2==1)throw"value hex must be even length: n="+"".length+",v="+this.hV;var t=this.hV.length/2,e=t.toString(16);if(e.length%2==1&&(e="0"+e),t<128)return e;var i=e.length/2;if(15<i)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return null!=this.hTLV&&!this.isModified||(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},P.asn1.DERAbstractString=function(t){P.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=stohex(this.s)},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},N.lang.extend(P.asn1.DERAbstractString,P.asn1.ASN1Object),P.asn1.DERAbstractTime=function(t){P.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var r=this.zeroPadding,t=this.localDateToUTC(t),n=String(t.getFullYear()),e=("utc"==e&&(n=n.substr(2,2)),r(String(t.getMonth()+1),2)),n=n+e+r(String(t.getDate()),2)+r(String(t.getHours()),2)+r(String(t.getMinutes()),2)+r(String(t.getSeconds()),2);return(n=!0===i&&0!=(e=t.getMilliseconds())?n+"."+r(String(e),3).replace(/[0]+$/,""):n)+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=stohex(t)},this.setByDateValue=function(t,e,i,r,n,s){t=new Date(Date.UTC(t,e-1,i,r,n,s,0));this.setByDate(t)},this.getFreshValueHex=function(){return this.hV}},N.lang.extend(P.asn1.DERAbstractTime,P.asn1.ASN1Object),P.asn1.DERAbstractStructured=function(t){P.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},N.lang.extend(P.asn1.DERAbstractStructured,P.asn1.ASN1Object),P.asn1.DERBoolean=function(){P.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},N.lang.extend(P.asn1.DERBoolean,P.asn1.ASN1Object),P.asn1.DERInteger=function(t){P.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=P.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){t=new m(String(t),10);this.setByBigInteger(t)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},N.lang.extend(P.asn1.DERInteger,P.asn1.ASN1Object),P.asn1.DERBitString=function(t){var e;void 0!==t&&void 0!==t.obj&&(e=P.asn1.ASN1Util.newObject(t.obj),t.hex="00"+e.getEncodedHex()),P.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7<t)throw"unused bits shall be from 0 to 7: u = "+t;t="0"+t;this.hTLV=null,this.isModified=!0,this.hV=t+e},this.setByBinaryString=function(t){var e=8-(t=t.replace(/0+$/,"")).length%8;8==e&&(e=0);for(var i=0;i<=e;i++)t+="0";for(var r="",i=0;i<t.length-1;i+=8){var n=t.substr(i,8),n=parseInt(n,2).toString(16);r+=n=1==n.length?"0"+n:n}this.hTLV=null,this.isModified=!0,this.hV="0"+e+r},this.setByBooleanArray=function(t){for(var e="",i=0;i<t.length;i++)1==t[i]?e+="1":e+="0";this.setByBinaryString(e)},this.newFalseArray=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=!1;return e},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t&&t.toLowerCase().match(/^[0-9a-f]+$/)?this.setHexValueIncludingUnusedBits(t):void 0!==t.hex?this.setHexValueIncludingUnusedBits(t.hex):void 0!==t.bin?this.setByBinaryString(t.bin):void 0!==t.array&&this.setByBooleanArray(t.array))},N.lang.extend(P.asn1.DERBitString,P.asn1.ASN1Object),P.asn1.DEROctetString=function(t){var e;void 0!==t&&void 0!==t.obj&&(e=P.asn1.ASN1Util.newObject(t.obj),t.hex=e.getEncodedHex()),P.asn1.DEROctetString.superclass.constructor.call(this,t),this.hT="04"},N.lang.extend(P.asn1.DEROctetString,P.asn1.DERAbstractString),P.asn1.DERNull=function(){P.asn1.DERNull.superclass.constructor.call(this),this.hT="05",this.hTLV="0500"},N.lang.extend(P.asn1.DERNull,P.asn1.ASN1Object),P.asn1.DERObjectIdentifier=function(t){var h=function(t){t=t.toString(16);return t=1==t.length?"0"+t:t};P.asn1.DERObjectIdentifier.superclass.constructor.call(this),this.hT="06",this.setValueHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.setValueOidString=function(t){if(!t.match(/^[0-9.]+$/))throw"malformed oid string: "+t;var e="",i=t.split("."),t=40*parseInt(i[0])+parseInt(i[1]);e+=h(t),i.splice(0,2);for(var r=0;r<i.length;r++)e+=function(t){for(var e="",i=7-(s=new m(t,10).toString(2)).length%7,r=(7==i&&(i=0),""),n=0;n<i;n++)r+="0";for(var s=r+s,n=0;n<s.length-1;n+=7){var o=s.substr(n,7);n!=s.length-7&&(o="1"+o),e+=h(parseInt(o,2))}return e}(i[r]);this.hTLV=null,this.isModified=!0,this.s=null,this.hV=e},this.setValueName=function(t){var e=P.asn1.x509.OID.name2oid(t);if(""===e)throw"DERObjectIdentifier oidName undefined: "+t;this.setValueOidString(e)},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?t.match(/^[0-2].[0-9.]+$/)?this.setValueOidString(t):this.setValueName(t):void 0!==t.oid?this.setValueOidString(t.oid):void 0!==t.hex?this.setValueHex(t.hex):void 0!==t.name&&this.setValueName(t.name))},N.lang.extend(P.asn1.DERObjectIdentifier,P.asn1.ASN1Object),P.asn1.DEREnumerated=function(t){P.asn1.DEREnumerated.superclass.constructor.call(this),this.hT="0a",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=P.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){t=new m(String(t),10);this.setByBigInteger(t)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},N.lang.extend(P.asn1.DEREnumerated,P.asn1.ASN1Object),P.asn1.DERUTF8String=function(t){P.asn1.DERUTF8String.superclass.constructor.call(this,t),this.hT="0c"},N.lang.extend(P.asn1.DERUTF8String,P.asn1.DERAbstractString),P.asn1.DERNumericString=function(t){P.asn1.DERNumericString.superclass.constructor.call(this,t),this.hT="12"},N.lang.extend(P.asn1.DERNumericString,P.asn1.DERAbstractString),P.asn1.DERPrintableString=function(t){P.asn1.DERPrintableString.superclass.constructor.call(this,t),this.hT="13"},N.lang.extend(P.asn1.DERPrintableString,P.asn1.DERAbstractString),P.asn1.DERTeletexString=function(t){P.asn1.DERTeletexString.superclass.constructor.call(this,t),this.hT="14"},N.lang.extend(P.asn1.DERTeletexString,P.asn1.DERAbstractString),P.asn1.DERIA5String=function(t){P.asn1.DERIA5String.superclass.constructor.call(this,t),this.hT="16"},N.lang.extend(P.asn1.DERIA5String,P.asn1.DERAbstractString),P.asn1.DERUTCTime=function(t){P.asn1.DERUTCTime.superclass.constructor.call(this,t),this.hT="17",this.setByDate=function(t){this.hTLV=null,this.isModified=!0,this.date=t,this.s=this.formatDate(this.date,"utc"),this.hV=stohex(this.s)},this.getFreshValueHex=function(){return void 0===this.date&&void 0===this.s&&(this.date=new Date,this.s=this.formatDate(this.date,"utc"),this.hV=stohex(this.s)),this.hV},void 0!==t&&(void 0!==t.str?this.setString(t.str):"string"==typeof t&&t.match(/^[0-9]{12}Z$/)?this.setString(t):void 0!==t.hex?this.setStringHex(t.hex):void 0!==t.date&&this.setByDate(t.date))},N.lang.extend(P.asn1.DERUTCTime,P.asn1.DERAbstractTime),P.asn1.DERGeneralizedTime=function(t){P.asn1.DERGeneralizedTime.superclass.constructor.call(this,t),this.hT="18",this.withMillis=!1,this.setByDate=function(t){this.hTLV=null,this.isModified=!0,this.date=t,this.s=this.formatDate(this.date,"gen",this.withMillis),this.hV=stohex(this.s)},this.getFreshValueHex=function(){return void 0===this.date&&void 0===this.s&&(this.date=new Date,this.s=this.formatDate(this.date,"gen",this.withMillis),this.hV=stohex(this.s)),this.hV},void 0!==t&&(void 0!==t.str?this.setString(t.str):"string"==typeof t&&t.match(/^[0-9]{14}Z$/)?this.setString(t):void 0!==t.hex?this.setStringHex(t.hex):void 0!==t.date&&this.setByDate(t.date),!0===t.millis)&&(this.withMillis=!0)},N.lang.extend(P.asn1.DERGeneralizedTime,P.asn1.DERAbstractTime),P.asn1.DERSequence=function(t){P.asn1.DERSequence.superclass.constructor.call(this,t),this.hT="30",this.getFreshValueHex=function(){for(var t="",e=0;e<this.asn1Array.length;e++)t+=this.asn1Array[e].getEncodedHex();return this.hV=t,this.hV}},N.lang.extend(P.asn1.DERSequence,P.asn1.DERAbstractStructured),P.asn1.DERSet=function(t){P.asn1.DERSet.superclass.constructor.call(this,t),this.hT="31",this.sortFlag=!0,this.getFreshValueHex=function(){for(var t=new Array,e=0;e<this.asn1Array.length;e++){var i=this.asn1Array[e];t.push(i.getEncodedHex())}return 1==this.sortFlag&&t.sort(),this.hV=t.join(""),this.hV},void 0!==t&&void 0!==t.sortflag&&0==t.sortflag&&(this.sortFlag=!1)},N.lang.extend(P.asn1.DERSet,P.asn1.DERAbstractStructured),P.asn1.DERTaggedObject=function(t){P.asn1.DERTaggedObject.superclass.constructor.call(this),this.hT="a0",this.hV="",this.isExplicit=!0,this.asn1Object=null,this.setASN1Object=function(t,e,i){this.hT=e,this.isExplicit=t,this.asn1Object=i,this.isExplicit?(this.hV=this.asn1Object.getEncodedHex(),this.hTLV=null,this.isModified=!0):(this.hV=null,this.hTLV=i.getEncodedHex(),this.hTLV=this.hTLV.replace(/^../,e),this.isModified=!1)},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.tag&&(this.hT=t.tag),void 0!==t.explicit&&(this.isExplicit=t.explicit),void 0!==t.obj)&&(this.asn1Object=t.obj,this.setASN1Object(this.isExplicit,this.hT,this.asn1Object))},N.lang.extend(P.asn1.DERTaggedObject,P.asn1.ASN1Object),ut=function(t,e){return(ut=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}))(t,e)};(function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}ut(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)})(M,ct=S),M.prototype.parseKey=function(t){try{var e=0,i=0,r=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/.test(t)?F(t):U.unarmor(t),n=z.decode(r);if(9===(n=3===n.sub.length?n.sub[2].sub[0]:n).sub.length){e=n.sub[1].getHexStringValue(),this.n=T(e,16),i=n.sub[2].getHexStringValue(),this.e=parseInt(i,16);var s=n.sub[3].getHexStringValue(),o=(this.d=T(s,16),n.sub[4].getHexStringValue()),h=(this.p=T(o,16),n.sub[5].getHexStringValue()),a=(this.q=T(h,16),n.sub[6].getHexStringValue()),u=(this.dmp1=T(a,16),n.sub[7].getHexStringValue()),c=(this.dmq1=T(u,16),n.sub[8].getHexStringValue());this.coeff=T(c,16)}else{if(2!==n.sub.length)return!1;var f,i=(n.sub[0].sub?(e=(f=n.sub[1].sub[0]).sub[0].getHexStringValue(),this.n=T(e,16),f):(e=n.sub[0].getHexStringValue(),this.n=T(e,16),n)).sub[1].getHexStringValue();this.e=parseInt(i,16)}return!0}catch(t){return!1}},M.prototype.getPrivateBaseKey=function(){var t={array:[new P.asn1.DERInteger({int:0}),new P.asn1.DERInteger({bigint:this.n}),new P.asn1.DERInteger({int:this.e}),new P.asn1.DERInteger({bigint:this.d}),new P.asn1.DERInteger({bigint:this.p}),new P.asn1.DERInteger({bigint:this.q}),new P.asn1.DERInteger({bigint:this.dmp1}),new P.asn1.DERInteger({bigint:this.dmq1}),new P.asn1.DERInteger({bigint:this.coeff})]};return new P.asn1.DERSequence(t).getEncodedHex()},M.prototype.getPrivateBaseKeyB64=function(){return r(this.getPrivateBaseKey())},M.prototype.getPublicBaseKey=function(){var t=new P.asn1.DERSequence({array:[new P.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.1.1"}),new P.asn1.DERNull]}),e=new P.asn1.DERSequence({array:[new P.asn1.DERInteger({bigint:this.n}),new P.asn1.DERInteger({int:this.e})]}),e=new P.asn1.DERBitString({hex:"00"+e.getEncodedHex()});return new P.asn1.DERSequence({array:[t,e]}).getEncodedHex()},M.prototype.getPublicBaseKeyB64=function(){return r(this.getPublicBaseKey())},M.wordwrap=function(t,e){return e=e||64,t&&t.match(RegExp("(.{1,"+e+"})( +|$\n?)|(.{1,"+e+"})","g")).join("\n")},M.prototype.getPrivateKey=function(){var t="-----BEGIN RSA PRIVATE KEY-----\n";return t+(M.wordwrap(this.getPrivateBaseKeyB64())+"\n")+"-----END RSA PRIVATE KEY-----"},M.prototype.getPublicKey=function(){var t="-----BEGIN PUBLIC KEY-----\n";return t+(M.wordwrap(this.getPublicBaseKeyB64())+"\n")+"-----END PUBLIC KEY-----"},M.hasPublicKeyProperty=function(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")},M.hasPrivateKeyProperty=function(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")&&t.hasOwnProperty("d")&&t.hasOwnProperty("p")&&t.hasOwnProperty("q")&&t.hasOwnProperty("dmp1")&&t.hasOwnProperty("dmq1")&&t.hasOwnProperty("coeff")},M.prototype.parsePropertiesFrom=function(t){this.n=t.n,this.e=t.e,t.hasOwnProperty("d")&&(this.d=t.d,this.p=t.p,this.q=t.q,this.dmp1=t.dmp1,this.dmq1=t.dmq1,this.coeff=t.coeff)};var ut,ct,ft=M;function M(t){var e=ct.call(this)||this;return t&&("string"==typeof t?e.parseKey(t):(M.hasPrivateKeyProperty(t)||M.hasPublicKeyProperty(t))&&e.parsePropertiesFrom(t)),e}S="undefined"==typeof process||null==(N=process.env)?void 0:N.npm_package_version;function q(t){this.default_key_size=(t=(t=void 0===t?{}:t)||{}).default_key_size?parseInt(t.default_key_size,10):1024,this.default_public_exponent=t.default_public_exponent||"010001",this.log=t.log||!1,this.key=null}return q.prototype.setKey=function(t){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new ft(t)},q.prototype.setPrivateKey=function(t){this.setKey(t)},q.prototype.setPublicKey=function(t){this.setKey(t)},q.prototype.decrypt=function(t){try{return this.getKey().decrypt(C(t))}catch(t){return!1}},q.prototype.encrypt=function(t){try{return r(this.getKey().encrypt(t))}catch(t){return!1}},q.prototype.sign=function(t,e,i){try{return r(this.getKey().sign(t,e,i))}catch(t){return!1}},q.prototype.verify=function(t,e,i){try{return this.getKey().verify(t,C(e),i)}catch(t){return!1}},q.prototype.getKey=function(t){if(!this.key){if(this.key=new ft,t&&"[object Function]"==={}.toString.call(t))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,t);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},q.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},q.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},q.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},q.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()},q.version=S,q}
//---SyncByPyScript---JSEncrypt-end