欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python干货实战之逆向登录世界上最大的游戏平台Stream

程序员文章站 2022-06-17 19:58:02
目录大家好,我是辣条。前言今天带来爬虫实战的第30篇文章。在挑选游戏的过程中感受学习,让你突飞猛进。python爬虫实战:steam逆向rsa登录解析。采集目标网址:工具准备开发工具:pycharm开...

大家好,我是辣条。

前言

今天带来爬虫实战的第30篇文章。在挑选游戏的过程中感受学习,让你突飞猛进。python爬虫实战:steam逆向rsa登录解析。

采集目标

网址:

Python干货实战之逆向登录世界上最大的游戏平台Stream

工具准备

开发工具:pycharm

开发环境:python3.7, windows10 使用工具包:requests

项目思路解析

访问登录页面重登录页面获取登录接口, 先输入错误的账户密码去测试登录接口。

Python干货实战之逆向登录世界上最大的游戏平台Stream

获取到登录的接口地址,请求方法是post请求,找到需要传递的参数,可以看到密码数据是加密的第一个数据是时间戳密码加密字段应该用的base64,rsatimestamp字段目前还不清楚是什么,其他的都是固定数据。

Python干货实战之逆向登录世界上最大的游戏平台Stream

找到password字段的加密位置,这里我们直接进行搜索,找加密位置,可以通过名字来大致判断加密文件。

Python干货实战之逆向登录世界上最大的游戏平台Stream

在文件进行搜索,查看数据值是否存在。

Python干货实战之逆向登录世界上最大的游戏平台Stream

当前可以看出代码为rsa加密,这里辣条选择直接补js环境,先把加密段代码端进行添加,rsa加密的公秘钥需要重其他它接口获取。

Python干货实战之逆向登录世界上最大的游戏平台Stream

Python干货实战之逆向登录世界上最大的游戏平台Stream

加密的秘钥以及其他来自这个页面,需要提取发送请求获取到,要注意cookie需要保持一致,开始补js环境。

Python干货实战之逆向登录世界上最大的游戏平台Stream

我们不需要账号信息的获取,可以直接注释掉,打印数据,尝试运行,哪里报错补哪里。

Python干货实战之逆向登录世界上最大的游戏平台Stream

少了rsa功能。

Python干货实战之逆向登录世界上最大的游戏平台Stream

当前文件都拿过来,后面的方法也一样的直接拿过来就行。

// copyright (c) 2005  tom wu
// all rights reserved.
// see "license" for details.
​
/*
 * copyright (c) 2003-2005  tom wu
 * all rights reserved.
 *
 * permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "software"), to deal in the software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the software, and to
 * permit persons to whom the software is furnished to do so, subject to
 * the following conditions:
 *
 * the above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the software.
 *
 * the software is provided "as-is" and without warranty of any kind,
 * express, implied or otherwise, including without limitation, any
 * warranty of merchantability or fitness for a particular purpose.
 *
 * in no event shall tom wu be liable for any special, incidental,
 * indirect or consequential damages of any kind, or any damages whatsoever
 * resulting from loss of use, data or profits, whether or not advised of
 * the possibility of damage, and on any theory of liability, arising out
 * of or in connection with the use or performance of this software.
 *
 * in addition, the following condition applies:
 *
 * all redistributions must retain an intact copy of this copyright notice
 * and disclaimer.
 */
​
// basic javascript bn library - subset useful for rsa encryption.
​
// bits per digit
var dbits;
​
// javascript engine analysis
var canary = 0xdeadbeefcafe;
var j_lm = ((canary&0xffffff)==0xefcafe);
​
// (public) constructor
function biginteger(a,b,c) {
    if(a != null)
        if("number" == typeof a) this.fromnumber(a,b,c);
        else if(b == null && "string" != typeof a) this.fromstring(a,256);
        else this.fromstring(a,b);
}
​
// return new, unset biginteger
function nbi() { return new biginteger(null); }
​
// am: compute w_j += (x*this_i), propagate carries,
// c is initial carry, returns final carry.
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
// we need to select the fastest one that works in this environment.
​
// am1: use a single mult and divide to get the high bits,
// max digit bits should be 26 because
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
function am1(i,x,w,j,c,n) {
    while(--n >= 0) {
        var v = x*this[i++]+w[j]+c;
        c = math.floor(v/0x4000000);
        w[j++] = v&0x3ffffff;
    }
    return c;
}
// am2 avoids a big mult-and-extract completely.
// max digit bits should be <= 30 because we do bitwise ops
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
function am2(i,x,w,j,c,n) {
    var xl = x&0x7fff, xh = x>>15;
    while(--n >= 0) {
        var l = this[i]&0x7fff;
        var h = this[i++]>>15;
        var m = xh*l+h*xl;
        l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
        c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
        w[j++] = l&0x3fffffff;
    }
    return c;
}
// alternately, set max digit bits to 28 since some
// browsers slow down when dealing with 32-bit numbers.
function am3(i,x,w,j,c,n) {
    var xl = x&0x3fff, xh = x>>14;
    while(--n >= 0) {
        var l = this[i]&0x3fff;
        var h = this[i++]>>14;
        var m = xh*l+h*xl;
        l = xl*l+((m&0x3fff)<<14)+w[j]+c;
        c = (l>>28)+(m>>14)+xh*h;
        w[j++] = l&0xfffffff;
    }
    return c;
}
if(j_lm) {
    biginteger.prototype.am = am2;
    dbits = 30;
}
else if(j_lm) {
    biginteger.prototype.am = am1;
    dbits = 26;
}
else { // mozilla/netscape seems to prefer am3
    biginteger.prototype.am = am3;
    dbits = 28;
}
​
biginteger.prototype.db = dbits;
biginteger.prototype.dm = ((1<<dbits)-1);
biginteger.prototype.dv = (1<<dbits);
​
var bi_fp = 52;
biginteger.prototype.fv = math.pow(2,bi_fp);
biginteger.prototype.f1 = bi_fp-dbits;
biginteger.prototype.f2 = 2*dbits-bi_fp;
​
// digit conversions
var bi_rm = "0123456789abcdefghijklmnopqrstuvwxyz";
var bi_rc = new array();
var rr,vv;
rr = "0".charcodeat(0);
for(vv = 0; vv <= 9; ++vv) bi_rc[rr++] = vv;
rr = "a".charcodeat(0);
for(vv = 10; vv < 36; ++vv) bi_rc[rr++] = vv;
rr = "a".charcodeat(0);
for(vv = 10; vv < 36; ++vv) bi_rc[rr++] = vv;
​
function int2char(n) { return bi_rm.charat(n); }
function intat(s,i) {
    var c = bi_rc[s.charcodeat(i)];
    return (c==null)?-1:c;
}
​
// (protected) copy this to r
function bnpcopyto(r) {
    for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
    r.t = this.t;
    r.s = this.s;
}
​
// (protected) set from integer value x, -dv <= x < dv
function bnpfromint(x) {
    this.t = 1;
    this.s = (x<0)?-1:0;
    if(x > 0) this[0] = x;
    else if(x < -1) this[0] = x+dv;
    else this.t = 0;
}
​
// return bigint initialized to value
function nbv(i) { var r = nbi(); r.fromint(i); return r; }
​
// (protected) set from string and radix
function bnpfromstring(s,b) {
    var k;
    if(b == 16) k = 4;
    else if(b == 8) k = 3;
    else if(b == 256) k = 8; // byte array
    else if(b == 2) k = 1;
    else if(b == 32) k = 5;
    else if(b == 4) k = 2;
    else { this.fromradix(s,b); return; }
    this.t = 0;
    this.s = 0;
    var i = s.length, mi = false, sh = 0;
    while(--i >= 0) {
        var x = (k==8)?s[i]&0xff:intat(s,i);
        if(x < 0) {
            if(s.charat(i) == "-") mi = true;
            continue;
        }
        mi = false;
        if(sh == 0)
            this[this.t++] = x;
        else if(sh+k > this.db) {
            this[this.t-1] |= (x&((1<<(this.db-sh))-1))<<sh;
            this[this.t++] = (x>>(this.db-sh));
        }
        else
            this[this.t-1] |= x<<sh;
        sh += k;
        if(sh >= this.db) sh -= this.db;
    }
    if(k == 8 && (s[0]&0x80) != 0) {
        this.s = -1;
        if(sh > 0) this[this.t-1] |= ((1<<(this.db-sh))-1)<<sh;
    }
    this.clamp();
    if(mi) biginteger.zero.subto(this,this);
}
​
// (protected) clamp off excess high words
function bnpclamp() {
    var c = this.s&this.dm;
    while(this.t > 0 && this[this.t-1] == c) --this.t;
}
​
// (public) return string representation in given radix
function bntostring(b) {
    if(this.s < 0) return "-"+this.negate().tostring(b);
    var k;
    if(b == 16) k = 4;
    else if(b == 8) k = 3;
    else if(b == 2) k = 1;
    else if(b == 32) k = 5;
    else if(b == 4) k = 2;
    else return this.toradix(b);
    var km = (1<<k)-1, d, m = false, r = "", i = this.t;
    var p = this.db-(i*this.db)%k;
    if(i-- > 0) {
        if(p < this.db && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
        while(i >= 0) {
            if(p < k) {
                d = (this[i]&((1<<p)-1))<<(k-p);
                d |= this[--i]>>(p+=this.db-k);
            }
            else {
                d = (this[i]>>(p-=k))&km;
                if(p <= 0) { p += this.db; --i; }
            }
            if(d > 0) m = true;
            if(m) r += int2char(d);
        }
    }
    return m?r:"0";
}
​
// (public) -this
function bnnegate() { var r = nbi(); biginteger.zero.subto(this,r); return r; }
​
// (public) |this|
function bnabs() { return (this.s<0)?this.negate():this; }
​
// (public) return + if this > a, - if this < a, 0 if equal
function bncompareto(a) {
    var r = this.s-a.s;
    if(r != 0) return r;
    var i = this.t;
    r = i-a.t;
    if(r != 0) return r;
    while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
    return 0;
}
​
// returns bit length of the integer x
function nbits(x) {
    var r = 1, t;
    if((t=x>>>16) != 0) { x = t; r += 16; }
    if((t=x>>8) != 0) { x = t; r += 8; }
    if((t=x>>4) != 0) { x = t; r += 4; }
    if((t=x>>2) != 0) { x = t; r += 2; }
    if((t=x>>1) != 0) { x = t; r += 1; }
    return r;
}
​
// (public) return the number of bits in "this"
function bnbitlength() {
    if(this.t <= 0) return 0;
    return this.db*(this.t-1)+nbits(this[this.t-1]^(this.s&this.dm));
}
​
// (protected) r = this << n*db
function bnpdlshiftto(n,r) {
    var i;
    for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
    for(i = n-1; i >= 0; --i) r[i] = 0;
    r.t = this.t+n;
    r.s = this.s;
}
​
// (protected) r = this >> n*db
function bnpdrshiftto(n,r) {
    for(var i = n; i < this.t; ++i) r[i-n] = this[i];
    r.t = math.max(this.t-n,0);
    r.s = this.s;
}
​
// (protected) r = this << n
function bnplshiftto(n,r) {
    var bs = n%this.db;
    var cbs = this.db-bs;
    var bm = (1<<cbs)-1;
    var ds = math.floor(n/this.db), c = (this.s<<bs)&this.dm, i;
    for(i = this.t-1; i >= 0; --i) {
        r[i+ds+1] = (this[i]>>cbs)|c;
        c = (this[i]&bm)<<bs;
    }
    for(i = ds-1; i >= 0; --i) r[i] = 0;
    r[ds] = c;
    r.t = this.t+ds+1;
    r.s = this.s;
    r.clamp();
}
​
// (protected) r = this >> n
function bnprshiftto(n,r) {
    r.s = this.s;
    var ds = math.floor(n/this.db);
    if(ds >= this.t) { r.t = 0; return; }
    var bs = n%this.db;
    var cbs = this.db-bs;
    var bm = (1<<bs)-1;
    r[0] = this[ds]>>bs;
    for(var i = ds+1; i < this.t; ++i) {
        r[i-ds-1] |= (this[i]&bm)<<cbs;
        r[i-ds] = this[i]>>bs;
    }
    if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
    r.t = this.t-ds;
    r.clamp();
}
​
// (protected) r = this - a
function bnpsubto(a,r) {
    var i = 0, c = 0, m = math.min(a.t,this.t);
    while(i < m) {
        c += this[i]-a[i];
        r[i++] = c&this.dm;
        c >>= this.db;
    }
    if(a.t < this.t) {
        c -= a.s;
        while(i < this.t) {
            c += this[i];
            r[i++] = c&this.dm;
            c >>= this.db;
        }
        c += this.s;
    }
    else {
        c += this.s;
        while(i < a.t) {
            c -= a[i];
            r[i++] = c&this.dm;
            c >>= this.db;
        }
        c -= a.s;
    }
    r.s = (c<0)?-1:0;
    if(c < -1) r[i++] = this.dv+c;
    else if(c > 0) r[i++] = c;
    r.t = i;
    r.clamp();
}
​
// (protected) r = this * a, r != this,a (hac 14.12)
// "this" should be the larger one if appropriate.
function bnpmultiplyto(a,r) {
    var x = this.abs(), y = a.abs();
    var i = x.t;
    r.t = i+y.t;
    while(--i >= 0) r[i] = 0;
    for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
    r.s = 0;
    r.clamp();
    if(this.s != a.s) biginteger.zero.subto(r,r);
}
​
// (protected) r = this^2, r != this (hac 14.16)
function bnpsquareto(r) {
    var x = this.abs();
    var i = r.t = 2*x.t;
    while(--i >= 0) r[i] = 0;
    for(i = 0; i < x.t-1; ++i) {
        var c = x.am(i,x[i],r,2*i,0,1);
        if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.dv) {
            r[i+x.t] -= x.dv;
            r[i+x.t+1] = 1;
        }
    }
    if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
    r.s = 0;
    r.clamp();
}
​
// (protected) divide this by m, quotient and remainder to q, r (hac 14.20)
// r != q, this != m.  q or r may be null.
function bnpdivremto(m,q,r) {
    var pm = m.abs();
    if(pm.t <= 0) return;
    var pt = this.abs();
    if(pt.t < pm.t) {
        if(q != null) q.fromint(0);
        if(r != null) this.copyto(r);
        return;
    }
    if(r == null) r = nbi();
    var y = nbi(), ts = this.s, ms = m.s;
    var nsh = this.db-nbits(pm[pm.t-1]);    // normalize modulus
    if(nsh > 0) { pm.lshiftto(nsh,y); pt.lshiftto(nsh,r); }
    else { pm.copyto(y); pt.copyto(r); }
    var ys = y.t;
    var y0 = y[ys-1];
    if(y0 == 0) return;
    var yt = y0*(1<<this.f1)+((ys>1)?y[ys-2]>>this.f2:0);
    var d1 = this.fv/yt, d2 = (1<<this.f1)/yt, e = 1<<this.f2;
    var i = r.t, j = i-ys, t = (q==null)?nbi():q;
    y.dlshiftto(j,t);
    if(r.compareto(t) >= 0) {
        r[r.t++] = 1;
        r.subto(t,r);
    }
    biginteger.one.dlshiftto(ys,t);
    t.subto(y,y);    // "negative" y so we can replace sub with am later
    while(y.t < ys) y[y.t++] = 0;
    while(--j >= 0) {
        // estimate quotient digit
        var qd = (r[--i]==y0)?this.dm:math.floor(r[i]*d1+(r[i-1]+e)*d2);
        if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) {    // try it out
            y.dlshiftto(j,t);
            r.subto(t,r);
            while(r[i] < --qd) r.subto(t,r);
        }
    }
    if(q != null) {
        r.drshiftto(ys,q);
        if(ts != ms) biginteger.zero.subto(q,q);
    }
    r.t = ys;
    r.clamp();
    if(nsh > 0) r.rshiftto(nsh,r);    // denormalize remainder
    if(ts < 0) biginteger.zero.subto(r,r);
}
​
// (public) this mod a
function bnmod(a) {
    var r = nbi();
    this.abs().divremto(a,null,r);
    if(this.s < 0 && r.compareto(biginteger.zero) > 0) a.subto(r,r);
    return r;
}
​
// modular reduction using "classic" algorithm
function classic(m) { this.m = m; }
function cconvert(x) {
    if(x.s < 0 || x.compareto(this.m) >= 0) return x.mod(this.m);
    else return x;
}
function crevert(x) { return x; }
function creduce(x) { x.divremto(this.m,null,x); }
function cmulto(x,y,r) { x.multiplyto(y,r); this.reduce(r); }
function csqrto(x,r) { x.squareto(r); this.reduce(r); }
​
classic.prototype.convert = cconvert;
classic.prototype.revert = crevert;
classic.prototype.reduce = creduce;
classic.prototype.multo = cmulto;
classic.prototype.sqrto = csqrto;
​
// (protected) return "-1/this % 2^db"; useful for mont. reduction
// justification:
//         xy == 1 (mod m)
//         xy =  1+km
//   xy(2-xy) = (1+km)(1-km)
// x[y(2-xy)] = 1-k^2m^2
// x[y(2-xy)] == 1 (mod m^2)
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
// js multiply "overflows" differently from c/c++, so care is needed here.
function bnpinvdigit() {
    if(this.t < 1) return 0;
    var x = this[0];
    if((x&1) == 0) return 0;
    var y = x&3;        // y == 1/x mod 2^2
    y = (y*(2-(x&0xf)*y))&0xf;    // y == 1/x mod 2^4
    y = (y*(2-(x&0xff)*y))&0xff;    // y == 1/x mod 2^8
    y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff;    // y == 1/x mod 2^16
    // last step - calculate inverse mod dv directly;
    // assumes 16 < db <= 32 and assumes ability to handle 48-bit ints
    y = (y*(2-x*y%this.dv))%this.dv;        // y == 1/x mod 2^dbits
    // we really want the negative inverse, and -dv < y < dv
    return (y>0)?this.dv-y:-y;
}
​
// montgomery reduction
function montgomery(m) {
    this.m = m;
    this.mp = m.invdigit();
    this.mpl = this.mp&0x7fff;
    this.mph = this.mp>>15;
    this.um = (1<<(m.db-15))-1;
    this.mt2 = 2*m.t;
}
​
// xr mod m
function montconvert(x) {
    var r = nbi();
    x.abs().dlshiftto(this.m.t,r);
    r.divremto(this.m,null,r);
    if(x.s < 0 && r.compareto(biginteger.zero) > 0) this.m.subto(r,r);
    return r;
}
​
// x/r mod m
function montrevert(x) {
    var r = nbi();
    x.copyto(r);
    this.reduce(r);
    return r;
}
​
// x = x/r mod m (hac 14.32)
function montreduce(x) {
    while(x.t <= this.mt2)    // pad x so am has enough room later
        x[x.t++] = 0;
    for(var i = 0; i < this.m.t; ++i) {
        // faster way of calculating u0 = x[i]*mp mod dv
        var j = x[i]&0x7fff;
        var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.dm;
        // use am to combine the multiply-shift-add into one call
        j = i+this.m.t;
        x[j] += this.m.am(0,u0,x,i,0,this.m.t);
        // propagate carry
        while(x[j] >= x.dv) { x[j] -= x.dv; x[++j]++; }
    }
    x.clamp();
    x.drshiftto(this.m.t,x);
    if(x.compareto(this.m) >= 0) x.subto(this.m,x);
}
​
// r = "x^2/r mod m"; x != r
function montsqrto(x,r) { x.squareto(r); this.reduce(r); }
​
// r = "xy/r mod m"; x,y != r
function montmulto(x,y,r) { x.multiplyto(y,r); this.reduce(r); }
​
montgomery.prototype.convert = montconvert;
montgomery.prototype.revert = montrevert;
montgomery.prototype.reduce = montreduce;
montgomery.prototype.multo = montmulto;
montgomery.prototype.sqrto = montsqrto;
​
// (protected) true iff this is even
function bnpiseven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
​
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (hac 14.79)
function bnpexp(e,z) {
    if(e > 0xffffffff || e < 1) return biginteger.one;
    var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
    g.copyto(r);
    while(--i >= 0) {
        z.sqrto(r,r2);
        if((e&(1<<i)) > 0) z.multo(r2,g,r);
        else { var t = r; r = r2; r2 = t; }
    }
    return z.revert(r);
}
​
// (public) this^e % m, 0 <= e < 2^32
function bnmodpowint(e,m) {
    var z;
    if(e < 256 || m.iseven()) z = new classic(m); else z = new montgomery(m);
    return this.exp(e,z);
}
​
// protected
biginteger.prototype.copyto = bnpcopyto;
biginteger.prototype.fromint = bnpfromint;
biginteger.prototype.fromstring = bnpfromstring;
biginteger.prototype.clamp = bnpclamp;
biginteger.prototype.dlshiftto = bnpdlshiftto;
biginteger.prototype.drshiftto = bnpdrshiftto;
biginteger.prototype.lshiftto = bnplshiftto;
biginteger.prototype.rshiftto = bnprshiftto;
biginteger.prototype.subto = bnpsubto;
biginteger.prototype.multiplyto = bnpmultiplyto;
biginteger.prototype.squareto = bnpsquareto;
biginteger.prototype.divremto = bnpdivremto;
biginteger.prototype.invdigit = bnpinvdigit;
biginteger.prototype.iseven = bnpiseven;
biginteger.prototype.exp = bnpexp;
​
// public
biginteger.prototype.tostring = bntostring;
biginteger.prototype.negate = bnnegate;
biginteger.prototype.abs = bnabs;
biginteger.prototype.compareto = bncompareto;
biginteger.prototype.bitlength = bnbitlength;
biginteger.prototype.mod = bnmod;
biginteger.prototype.modpowint = bnmodpowint;
​
// "constants"
biginteger.zero = nbv(0);
biginteger.one = nbv(1);
​
​
// copyright (c) 2005  tom wu
// all rights reserved.
// see "license" for details.
​
// extended javascript bn functions, required for rsa private ops.
​
// (public)
function bnclone() { var r = nbi(); this.copyto(r); return r; }
​
// (public) return value as integer
function bnintvalue() {
    if(this.s < 0) {
        if(this.t == 1) return this[0]-this.dv;
        else if(this.t == 0) return -1;
    }
    else if(this.t == 1) return this[0];
    else if(this.t == 0) return 0;
    // assumes 16 < db < 32
    return ((this[1]&((1<<(32-this.db))-1))<<this.db)|this[0];
}
​
// (public) return value as byte
function bnbytevalue() { return (this.t==0)?this.s:(this[0]<<24)>>24; }
​
// (public) return value as short (assumes db>=16)
function bnshortvalue() { return (this.t==0)?this.s:(this[0]<<16)>>16; }
​
// (protected) return x s.t. r^x < dv
function bnpchunksize(r) { return math.floor(math.ln2*this.db/math.log(r)); }
​
// (public) 0 if this == 0, 1 if this > 0
function bnsignum() {
    if(this.s < 0) return -1;
    else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0;
    else return 1;
}
​
// (protected) convert to radix string
function bnptoradix(b) {
    if(b == null) b = 10;
    if(this.signum() == 0 || b < 2 || b > 36) return "0";
    var cs = this.chunksize(b);
    var a = math.pow(b,cs);
    var d = nbv(a), y = nbi(), z = nbi(), r = "";
    this.divremto(d,y,z);
    while(y.signum() > 0) {
        r = (a+z.intvalue()).tostring(b).substr(1) + r;
        y.divremto(d,y,z);
    }
    return z.intvalue().tostring(b) + r;
}
​
// (protected) convert from radix string
function bnpfromradix(s,b) {
    this.fromint(0);
    if(b == null) b = 10;
    var cs = this.chunksize(b);
    var d = math.pow(b,cs), mi = false, j = 0, w = 0;
    for(var i = 0; i < s.length; ++i) {
        var x = intat(s,i);
        if(x < 0) {
            if(s.charat(i) == "-" && this.signum() == 0) mi = true;
            continue;
        }
        w = b*w+x;
        if(++j >= cs) {
            this.dmultiply(d);
            this.daddoffset(w,0);
            j = 0;
            w = 0;
        }
    }
    if(j > 0) {
        this.dmultiply(math.pow(b,j));
        this.daddoffset(w,0);
    }
    if(mi) biginteger.zero.subto(this,this);
}
​
// (protected) alternate constructor
function bnpfromnumber(a,b,c) {
    if("number" == typeof b) {
        // new biginteger(int,int,rng)
        if(a < 2) this.fromint(1);
        else {
            this.fromnumber(a,c);
            if(!this.testbit(a-1))    // force msb set
                this.bitwiseto(biginteger.one.shiftleft(a-1),op_or,this);
            if(this.iseven()) this.daddoffset(1,0); // force odd
            while(!this.isprobableprime(b)) {
                this.daddoffset(2,0);
                if(this.bitlength() > a) this.subto(biginteger.one.shiftleft(a-1),this);
            }
        }
    }
    else {
        // new biginteger(int,rng)
        var x = new array(), t = a&7;
        x.length = (a>>3)+1;
        b.nextbytes(x);
        if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0;
        this.fromstring(x,256);
    }
}
​
// (public) convert to bigendian byte array
function bntobytearray() {
    var i = this.t, r = new array();
    r[0] = this.s;
    var p = this.db-(i*this.db)%8, d, k = 0;
    if(i-- > 0) {
        if(p < this.db && (d = this[i]>>p) != (this.s&this.dm)>>p)
            r[k++] = d|(this.s<<(this.db-p));
        while(i >= 0) {
            if(p < 8) {
                d = (this[i]&((1<<p)-1))<<(8-p);
                d |= this[--i]>>(p+=this.db-8);
            }
            else {
                d = (this[i]>>(p-=8))&0xff;
                if(p <= 0) { p += this.db; --i; }
            }
            if((d&0x80) != 0) d |= -256;
            if(k == 0 && (this.s&0x80) != (d&0x80)) ++k;
            if(k > 0 || d != this.s) r[k++] = d;
        }
    }
    return r;
}
​
function bnequals(a) { return(this.compareto(a)==0); }
function bnmin(a) { return(this.compareto(a)<0)?this:a; }
function bnmax(a) { return(this.compareto(a)>0)?this:a; }
​
// (protected) r = this op a (bitwise)
function bnpbitwiseto(a,op,r) {
    var i, f, m = math.min(a.t,this.t);
    for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]);
    if(a.t < this.t) {
        f = a.s&this.dm;
        for(i = m; i < this.t; ++i) r[i] = op(this[i],f);
        r.t = this.t;
    }
    else {
        f = this.s&this.dm;
        for(i = m; i < a.t; ++i) r[i] = op(f,a[i]);
        r.t = a.t;
    }
    r.s = op(this.s,a.s);
    r.clamp();
}
​
// (public) this & a
function op_and(x,y) { return x&y; }
function bnand(a) { var r = nbi(); this.bitwiseto(a,op_and,r); return r; }
​
// (public) this | a
function op_or(x,y) { return x|y; }
function bnor(a) { var r = nbi(); this.bitwiseto(a,op_or,r); return r; }
​
// (public) this ^ a
function op_xor(x,y) { return x^y; }
function bnxor(a) { var r = nbi(); this.bitwiseto(a,op_xor,r); return r; }
​
// (public) this & ~a
function op_andnot(x,y) { return x&~y; }
function bnandnot(a) { var r = nbi(); this.bitwiseto(a,op_andnot,r); return r; }
​
// (public) ~this
function bnnot() {
    var r = nbi();
    for(var i = 0; i < this.t; ++i) r[i] = this.dm&~this[i];
    r.t = this.t;
    r.s = ~this.s;
    return r;
}
​
// (public) this << n
function bnshiftleft(n) {
    var r = nbi();
    if(n < 0) this.rshiftto(-n,r); else this.lshiftto(n,r);
    return r;
}
​
// (public) this >> n
function bnshiftright(n) {
    var r = nbi();
    if(n < 0) this.lshiftto(-n,r); else this.rshiftto(n,r);
    return r;
}
​
// return index of lowest 1-bit in x, x < 2^31
function lbit(x) {
    if(x == 0) return -1;
    var r = 0;
    if((x&0xffff) == 0) { x >>= 16; r += 16; }
    if((x&0xff) == 0) { x >>= 8; r += 8; }
    if((x&0xf) == 0) { x >>= 4; r += 4; }
    if((x&3) == 0) { x >>= 2; r += 2; }
    if((x&1) == 0) ++r;
    return r;
}
​
// (public) returns index of lowest 1-bit (or -1 if none)
function bngetlowestsetbit() {
    for(var i = 0; i < this.t; ++i)
        if(this[i] != 0) return i*this.db+lbit(this[i]);
    if(this.s < 0) return this.t*this.db;
    return -1;
}
​
// return number of 1 bits in x
function cbit(x) {
    var r = 0;
    while(x != 0) { x &= x-1; ++r; }
    return r;
}
​
// (public) return number of set bits
function bnbitcount() {
    var r = 0, x = this.s&this.dm;
    for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x);
    return r;
}
​
// (public) true iff nth bit is set
function bntestbit(n) {
    var j = math.floor(n/this.db);
    if(j >= this.t) return(this.s!=0);
    return((this[j]&(1<<(n%this.db)))!=0);
}
​
// (protected) this op (1<<n)
function bnpchangebit(n,op) {
    var r = biginteger.one.shiftleft(n);
    this.bitwiseto(r,op,r);
    return r;
}
​
// (public) this | (1<<n)
function bnsetbit(n) { return this.changebit(n,op_or); }
​
// (public) this & ~(1<<n)
function bnclearbit(n) { return this.changebit(n,op_andnot); }
​
// (public) this ^ (1<<n)
function bnflipbit(n) { return this.changebit(n,op_xor); }
​
// (protected) r = this + a
function bnpaddto(a,r) {
    var i = 0, c = 0, m = math.min(a.t,this.t);
    while(i < m) {
        c += this[i]+a[i];
        r[i++] = c&this.dm;
        c >>= this.db;
    }
    if(a.t < this.t) {
        c += a.s;
        while(i < this.t) {
            c += this[i];
            r[i++] = c&this.dm;
            c >>= this.db;
        }
        c += this.s;
    }
    else {
        c += this.s;
        while(i < a.t) {
            c += a[i];
            r[i++] = c&this.dm;
            c >>= this.db;
        }
        c += a.s;
    }
    r.s = (c<0)?-1:0;
    if(c > 0) r[i++] = c;
    else if(c < -1) r[i++] = this.dv+c;
    r.t = i;
    r.clamp();
}
​
// (public) this + a
function bnadd(a) { var r = nbi(); this.addto(a,r); return r; }
​
// (public) this - a
function bnsubtract(a) { var r = nbi(); this.subto(a,r); return r; }
​
// (public) this * a
function bnmultiply(a) { var r = nbi(); this.multiplyto(a,r); return r; }
​
// (public) this / a
function bndivide(a) { var r = nbi(); this.divremto(a,r,null); return r; }
​
// (public) this % a
function bnremainder(a) { var r = nbi(); this.divremto(a,null,r); return r; }
​
// (public) [this/a,this%a]
function bndivideandremainder(a) {
    var q = nbi(), r = nbi();
    this.divremto(a,q,r);
    return new array(q,r);
}
​
// (protected) this *= n, this >= 0, 1 < n < dv
function bnpdmultiply(n) {
    this[this.t] = this.am(0,n-1,this,0,0,this.t);
    ++this.t;
    this.clamp();
}
​
// (protected) this += n << w words, this >= 0
function bnpdaddoffset(n,w) {
    while(this.t <= w) this[this.t++] = 0;
    this[w] += n;
    while(this[w] >= this.dv) {
        this[w] -= this.dv;
        if(++w >= this.t) this[this.t++] = 0;
        ++this[w];
    }
}
​
// a "null" reducer
function nullexp() {}
function nnop(x) { return x; }
function nmulto(x,y,r) { x.multiplyto(y,r); }
function nsqrto(x,r) { x.squareto(r); }
​
nullexp.prototype.convert = nnop;
nullexp.prototype.revert = nnop;
nullexp.prototype.multo = nmulto;
nullexp.prototype.sqrto = nsqrto;
​
// (public) this^e
function bnpow(e) { return this.exp(e,new nullexp()); }
​
// (protected) r = lower n words of "this * a", a.t <= n
// "this" should be the larger one if appropriate.
function bnpmultiplylowerto(a,n,r) {
    var i = math.min(this.t+a.t,n);
    r.s = 0; // assumes a,this >= 0
    r.t = i;
    while(i > 0) r[--i] = 0;
    var j;
    for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t);
    for(j = math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i);
    r.clamp();
}
​
// (protected) r = "this * a" without lower n words, n > 0
// "this" should be the larger one if appropriate.
function bnpmultiplyupperto(a,n,r) {
    --n;
    var i = r.t = this.t+a.t-n;
    r.s = 0; // assumes a,this >= 0
    while(--i >= 0) r[i] = 0;
    for(i = math.max(n-this.t,0); i < a.t; ++i)
        r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n);
    r.clamp();
    r.drshiftto(1,r);
}
​
// barrett modular reduction
function barrett(m) {
    // setup barrett
    this.r2 = nbi();
    this.q3 = nbi();
    biginteger.one.dlshiftto(2*m.t,this.r2);
    this.mu = this.r2.divide(m);
    this.m = m;
}
​
function barrettconvert(x) {
    if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m);
    else if(x.compareto(this.m) < 0) return x;
    else { var r = nbi(); x.copyto(r); this.reduce(r); return r; }
}
​
function barrettrevert(x) { return x; }
​
// x = x mod m (hac 14.42)
function barrettreduce(x) {
    x.drshiftto(this.m.t-1,this.r2);
    if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); }
    this.mu.multiplyupperto(this.r2,this.m.t+1,this.q3);
    this.m.multiplylowerto(this.q3,this.m.t+1,this.r2);
    while(x.compareto(this.r2) < 0) x.daddoffset(1,this.m.t+1);
    x.subto(this.r2,x);
    while(x.compareto(this.m) >= 0) x.subto(this.m,x);
}
​
// r = x^2 mod m; x != r
function barrettsqrto(x,r) { x.squareto(r); this.reduce(r); }
​
// r = x*y mod m; x,y != r
function barrettmulto(x,y,r) { x.multiplyto(y,r); this.reduce(r); }
​
barrett.prototype.convert = barrettconvert;
barrett.prototype.revert = barrettrevert;
barrett.prototype.reduce = barrettreduce;
barrett.prototype.multo = barrettmulto;
barrett.prototype.sqrto = barrettsqrto;
​
// (public) this^e % m (hac 14.85)
function bnmodpow(e,m) {
    var i = e.bitlength(), k, r = nbv(1), z;
    if(i <= 0) return r;
    else if(i < 18) k = 1;
    else if(i < 48) k = 3;
    else if(i < 144) k = 4;
    else if(i < 768) k = 5;
    else k = 6;
    if(i < 8)
        z = new classic(m);
    else if(m.iseven())
        z = new barrett(m);
    else
        z = new montgomery(m);
​
    // precomputation
    var g = new array(), n = 3, k1 = k-1, km = (1<<k)-1;
    g[1] = z.convert(this);
    if(k > 1) {
        var g2 = nbi();
        z.sqrto(g[1],g2);
        while(n <= km) {
            g[n] = nbi();
            z.multo(g2,g[n-2],g[n]);
            n += 2;
        }
    }
​
    var j = e.t-1, w, is1 = true, r2 = nbi(), t;
    i = nbits(e[j])-1;
    while(j >= 0) {
        if(i >= k1) w = (e[j]>>(i-k1))&km;
        else {
            w = (e[j]&((1<<(i+1))-1))<<(k1-i);
            if(j > 0) w |= e[j-1]>>(this.db+i-k1);
        }
​
        n = k;
        while((w&1) == 0) { w >>= 1; --n; }
        if((i -= n) < 0) { i += this.db; --j; }
        if(is1) {    // ret == 1, don't bother squaring or multiplying it
            g[w].copyto(r);
            is1 = false;
        }
        else {
            while(n > 1) { z.sqrto(r,r2); z.sqrto(r2,r); n -= 2; }
            if(n > 0) z.sqrto(r,r2); else { t = r; r = r2; r2 = t; }
            z.multo(r2,g[w],r);
        }
​
        while(j >= 0 && (e[j]&(1<<i)) == 0) {
            z.sqrto(r,r2); t = r; r = r2; r2 = t;
            if(--i < 0) { i = this.db-1; --j; }
        }
    }
    return z.revert(r);
}
​
// (public) gcd(this,a) (hac 14.54)
function bngcd(a) {
    var x = (this.s<0)?this.negate():this.clone();
    var y = (a.s<0)?a.negate():a.clone();
    if(x.compareto(y) < 0) { var t = x; x = y; y = t; }
    var i = x.getlowestsetbit(), g = y.getlowestsetbit();
    if(g < 0) return x;
    if(i < g) g = i;
    if(g > 0) {
        x.rshiftto(g,x);
        y.rshiftto(g,y);
    }
    while(x.signum() > 0) {
        if((i = x.getlowestsetbit()) > 0) x.rshiftto(i,x);
        if((i = y.getlowestsetbit()) > 0) y.rshiftto(i,y);
        if(x.compareto(y) >= 0) {
            x.subto(y,x);
            x.rshiftto(1,x);
        }
        else {
            y.subto(x,y);
            y.rshiftto(1,y);
        }
    }
    if(g > 0) y.lshiftto(g,y);
    return y;
}
​
// (protected) this % n, n < 2^26
function bnpmodint(n) {
    if(n <= 0) return 0;
    var d = this.dv%n, r = (this.s<0)?n-1:0;
    if(this.t > 0)
        if(d == 0) r = this[0]%n;
        else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n;
    return r;
}
​
// (public) 1/this % m (hac 14.61)
function bnmodinverse(m) {
    var ac = m.iseven();
    if((this.iseven() && ac) || m.signum() == 0) return biginteger.zero;
    var u = m.clone(), v = this.clone();
    var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
    while(u.signum() != 0) {
        while(u.iseven()) {
            u.rshiftto(1,u);
            if(ac) {
                if(!a.iseven() || !b.iseven()) { a.addto(this,a); b.subto(m,b); }
                a.rshiftto(1,a);
            }
            else if(!b.iseven()) b.subto(m,b);
            b.rshiftto(1,b);
        }
        while(v.iseven()) {
            v.rshiftto(1,v);
            if(ac) {
                if(!c.iseven() || !d.iseven()) { c.addto(this,c); d.subto(m,d); }
                c.rshiftto(1,c);
            }
            else if(!d.iseven()) d.subto(m,d);
            d.rshiftto(1,d);
        }
        if(u.compareto(v) >= 0) {
            u.subto(v,u);
            if(ac) a.subto(c,a);
            b.subto(d,b);
        }
        else {
            v.subto(u,v);
            if(ac) c.subto(a,c);
            d.subto(b,d);
        }
    }
    if(v.compareto(biginteger.one) != 0) return biginteger.zero;
    if(d.compareto(m) >= 0) return d.subtract(m);
    if(d.signum() < 0) d.addto(m,d); else return d;
    if(d.signum() < 0) return d.add(m); else return d;
}
​
var lowprimes = [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];
var lplim = (1<<26)/lowprimes[lowprimes.length-1];
​
// (public) test primality with certainty >= 1-.5^t
function bnisprobableprime(t) {
    var i, x = this.abs();
    if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) {
        for(i = 0; i < lowprimes.length; ++i)
            if(x[0] == lowprimes[i]) return true;
        return false;
    }
    if(x.iseven()) return false;
    i = 1;
    while(i < lowprimes.length) {
        var m = lowprimes[i], j = i+1;
        while(j < lowprimes.length && m < lplim) m *= lowprimes[j++];
        m = x.modint(m);
        while(i < j) if(m%lowprimes[i++] == 0) return false;
    }
    return x.millerrabin(t);
}
​
// (protected) true if probably prime (hac 4.24, miller-rabin)
function bnpmillerrabin(t) {
    var n1 = this.subtract(biginteger.one);
    var k = n1.getlowestsetbit();
    if(k <= 0) return false;
    var r = n1.shiftright(k);
    t = (t+1)>>1;
    if(t > lowprimes.length) t = lowprimes.length;
    var a = nbi();
    for(var i = 0; i < t; ++i) {
        a.fromint(lowprimes[i]);
        var y = a.modpow(r,this);
        if(y.compareto(biginteger.one) != 0 && y.compareto(n1) != 0) {
            var j = 1;
            while(j++ < k && y.compareto(n1) != 0) {
                y = y.modpowint(2,this);
                if(y.compareto(biginteger.one) == 0) return false;
            }
            if(y.compareto(n1) != 0) return false;
        }
    }
    return true;
}
​
// protected
biginteger.prototype.chunksize = bnpchunksize;
biginteger.prototype.toradix = bnptoradix;
biginteger.prototype.fromradix = bnpfromradix;
biginteger.prototype.fromnumber = bnpfromnumber;
biginteger.prototype.bitwiseto = bnpbitwiseto;
biginteger.prototype.changebit = bnpchangebit;
biginteger.prototype.addto = bnpaddto;
biginteger.prototype.dmultiply = bnpdmultiply;
biginteger.prototype.daddoffset = bnpdaddoffset;
biginteger.prototype.multiplylowerto = bnpmultiplylowerto;
biginteger.prototype.multiplyupperto = bnpmultiplyupperto;
biginteger.prototype.modint = bnpmodint;
biginteger.prototype.millerrabin = bnpmillerrabin;
​
// public
biginteger.prototype.clone = bnclone;
biginteger.prototype.intvalue = bnintvalue;
biginteger.prototype.bytevalue = bnbytevalue;
biginteger.prototype.shortvalue = bnshortvalue;
biginteger.prototype.signum = bnsignum;
biginteger.prototype.tobytearray = bntobytearray;
biginteger.prototype.equals = bnequals;
biginteger.prototype.min = bnmin;
biginteger.prototype.max = bnmax;
biginteger.prototype.and = bnand;
biginteger.prototype.or = bnor;
biginteger.prototype.xor = bnxor;
biginteger.prototype.andnot = bnandnot;
biginteger.prototype.not = bnnot;
biginteger.prototype.shiftleft = bnshiftleft;
biginteger.prototype.shiftright = bnshiftright;
biginteger.prototype.getlowestsetbit = bngetlowestsetbit;
biginteger.prototype.bitcount = bnbitcount;
biginteger.prototype.testbit = bntestbit;
biginteger.prototype.setbit = bnsetbit;
biginteger.prototype.clearbit = bnclearbit;
biginteger.prototype.flipbit = bnflipbit;
biginteger.prototype.add = bnadd;
biginteger.prototype.subtract = bnsubtract;
biginteger.prototype.multiply = bnmultiply;
biginteger.prototype.divide = bndivide;
biginteger.prototype.remainder = bnremainder;
biginteger.prototype.divideandremainder = bndivideandremainder;
biginteger.prototype.modpow = bnmodpow;
biginteger.prototype.modinverse = bnmodinverse;
biginteger.prototype.pow = bnpow;
biginteger.prototype.gcd = bngcd;
biginteger.prototype.isprobableprime = bnisprobableprime;
​
// biginteger interfaces not implemented in jsbn:
​
// biginteger(int signum, byte[] magnitude)
// double doublevalue()
// float floatvalue()
// int hashcode()
// long longvalue()
// static biginteger valueof(long val)
​
​
​
​
var rsapublickey = function($modulus_hex, $encryptionexponent_hex) {
    this.modulus = new biginteger( $modulus_hex, 16);
    this.encryptionexponent = new biginteger( $encryptionexponent_hex, 16);
};
​
var base64 = {
    base64: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/=",
    encode: function($input) {
        if (!$input) {
            return false;
        }
        var $output = "";
        var $chr1, $chr2, $chr3;
        var $enc1, $enc2, $enc3, $enc4;
        var $i = 0;
        do {
            $chr1 = $input.charcodeat($i++);
            $chr2 = $input.charcodeat($i++);
            $chr3 = $input.charcodeat($i++);
            $enc1 = $chr1 >> 2;
            $enc2 = (($chr1 & 3) << 4) | ($chr2 >> 4);
            $enc3 = (($chr2 & 15) << 2) | ($chr3 >> 6);
            $enc4 = $chr3 & 63;
            if (isnan($chr2)) $enc3 = $enc4 = 64;
            else if (isnan($chr3)) $enc4 = 64;
            $output += this.base64.charat($enc1) + this.base64.charat($enc2) + this.base64.charat($enc3) + this.base64.charat($enc4);
        } while ($i < $input.length);
        return $output;
    },
    decode: function($input) {
        if(!$input) return false;
        $input = $input.replace(/[^a-za-z0-9\+\/\=]/g, "");
        var $output = "";
        var $enc1, $enc2, $enc3, $enc4;
        var $i = 0;
        do {
            $enc1 = this.base64.indexof($input.charat($i++));
            $enc2 = this.base64.indexof($input.charat($i++));
            $enc3 = this.base64.indexof($input.charat($i++));
            $enc4 = this.base64.indexof($input.charat($i++));
            $output += string.fromcharcode(($enc1 << 2) | ($enc2 >> 4));
            if ($enc3 != 64) $output += string.fromcharcode((($enc2 & 15) << 4) | ($enc3 >> 2));
            if ($enc4 != 64) $output += string.fromcharcode((($enc3 & 3) << 6) | $enc4);
        } while ($i < $input.length);
        return $output;
    }
};
​
var hex = {
    hex: "0123456789abcdef",
    encode: function($input) {
        if(!$input) return false;
        var $output = "";
        var $k;
        var $i = 0;
        do {
            $k = $input.charcodeat($i++);
            $output += this.hex.charat(($k >> 4) &0xf) + this.hex.charat($k & 0xf);
        } while ($i < $input.length);
        return $output;
    },
    decode: function($input) {
        if(!$input) return false;
        $input = $input.replace(/[^0-9abcdef]/g, "");
        var $output = "";
        var $i = 0;
        do {
            $output += string.fromcharcode(((this.hex.indexof($input.charat($i++)) << 4) & 0xf0) | (this.hex.indexof($input.charat($i++)) & 0xf));
        } while ($i < $input.length);
        return $output;
    }
};
​
var rsa = {
​
    getpublickey: function( $modulus_hex, $exponent_hex ) {
        return new rsapublickey( $modulus_hex, $exponent_hex );
    },
​
    encrypt: function($data, $pubkey) {
        if (!$pubkey) return false;
        $data = this.pkcs1pad2($data,($pubkey.modulus.bitlength()+7)>>3);
        if(!$data) return false;
        $data = $data.modpowint($pubkey.encryptionexponent, $pubkey.modulus);
        if(!$data) return false;
        $data = $data.tostring(16);
        if(($data.length & 1) == 1)
            $data = "0" + $data;
        return base64.encode(hex.decode($data));
    },
​
    pkcs1pad2: function($data, $keysize) {
        if($keysize < $data.length + 11)
            return null;
        var $buffer = [];
        var $i = $data.length - 1;
        while($i >= 0 && $keysize > 0)
            $buffer[--$keysize] = $data.charcodeat($i--);
        $buffer[--$keysize] = 0;
        while($keysize > 2)
            $buffer[--$keysize] = math.floor(math.random()*254) + 1;
        $buffer[--$keysize] = 2;
        $buffer[--$keysize] = 0;
        return new biginteger($buffer);
    }
};
​
​
​
onauthcoderesponse = function(results, password) {
    // var form = this.m_$logonform[0];
    var pubkey = rsa.getpublickey(results.publickey_mod, results.publickey_exp);
    // var username = this.m_strusernamecanonical;
    // var password = form.elements['password'].value;
    password = password.replace(/[^\x00-\x7f]/g, '');
    // remove non-standard-ascii characters
    var encryptedpassword = rsa.encrypt(password, pubkey);
    return encryptedpassword
};
​
console.log(onauthcoderesponse({'success': 'true', 'publickey_mod': 'aef25caaaba051405eb6be0ee34e927aa7378248279345a5c9cdb4f873de605e81167608b3f8592b7692d592373dae0b3b8e878dbcb3c25dda0d83d8b0b5e5432e59d33210749537f596841b7bd989594e6109d2ab63aed23052b0667de72c22e64f2e09a55066bf861bcf24f79336e75caff55887409c695bdf232d846b9e73a89a2df20a28fb580a504188f4a9e16e759e7aa5f454ce6e03aebf998cbc6ed478c24069af6ee8e06954fb9748bc387d811bfb33bc8d00b5400134bcbb8e872be4e8e60924754c10c522539dd1feeebc71f36c3f1d0484a914b8cbfb9966b403923d98821f02de5ec5d3ffba0b022dbf7cbfcec3fb88278bee580fe8f40960f9', 'publickey_exp': '010001', 'timestamp': '133267600000', 'token_gid': '27ddf868c7def6b4'}, '12345'))
​
// gq8lwjwnpwjs438psvx7qnow0gggav7gzbzkmbqtvcww4wvqck0fpuyscf8iybz7dibnawhvrx4lshlcs2oopqxknv6iybkeskargxv4tqivhf36oxejbo89zfwop5jdbezl1nbv2y99fbsqax2p/oxt3lm33xebkwc42kjqk1sahk+dz8yvt1ji9j3jnetvzvoh/4i5orkb2ai5dsurllqkgvut3b9egx6msumctp0ycvgje4oe9wsq8gvq7sd7f8qnobfrgukk1tvcymeqwdtstgqwascbaic7+/ykv0ej2ayhyiq/nnumwji4hwdraqxyahkkb6mpflkkjziqlq==

简易源码分享

import time
​
import execjs
import requests
​
​
login_url = 'https://store.steampowered.com/login/dologin/'
get_rsa_key_url = 'https://store.steampowered.com/login/getrsakey/'
​
headers = {
    'host': 'store.steampowered.com',
    'origin': 'https://store.steampowered.com',
    'referer': 'https://store.steampowered.com/login/?redir=&redir_ssl=1&snr=1_4_4__global-header',
    'user-agent': 'mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/91.0.4472.124 safari/537.36mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/94.0.4606.71 safari/537.36'
}
session = requests.session()
​
def get_rsa_key(username):
    data = {
        'donotcache': str(int(time.time() * 1000)),
        'username': username
    }
    response = session.post(url=get_rsa_key_url, data=data, headers=headers).json()
    print(response)
    return response
​
​
def get_encrypted_password(password, rsa_key_dict):
    f = open('steam.js', 'r', encoding='utf-8')
    steampowered_js = f.read()
    f.close()
    encrypted_password = execjs.compile(steampowered_js).call('onauthcoderesponse', password, rsa_key_dict)
    return encrypted_password
​
​
def login(username, encrypted_password, rsa_key_dict):
    data = {
        'donotcache': str(int(time.time() * 1000)),
        'password': encrypted_password,
        'username': username,
        'twofactorcode': '',
        'emailauth': '',
        'loginfriendlyname': '',
        'emailsteamid': '',
        'rsatimestamp': rsa_key_dict['timestamp'],
        'remember_login': false,
        'tokentype': '-1'
    }
    print(data)
    response = session.post(url=login_url, data=data, headers=headers)
    print(response.text)
​
​
def main():
    username = input('请输入登录账号: ')
    password = input('请输入登录密码: ')
​
​
    # 获取 rsa 加密所需 key 等信息
    rsa_key_dict = get_rsa_key(username)
​
    # 获取加密后的密码
    encrypted_password = get_encrypted_password(password, rsa_key_dict)
    # print(encrypted_password)
    # 携带 用户名、加密后的密码、cookies、验证码等登录
    login(username, encrypted_password, rsa_key_dict)
​
​
if __name__ == '__main__':
    main()

到此这篇关于python干货实战之逆向登录世界上最大的游戏平台stream的文章就介绍到这了,更多相关python stream内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!