1
Showing
3 changed files
with
762 additions
and
6 deletions
public/js/unionrsa.js
0 → 100644
1 | var dbits; | ||
2 | var canary = 0xdeadbeefcafe; | ||
3 | var j_lm = ((canary&0xffffff)==0xefcafe); | ||
4 | function BigInteger(a,b,c) { | ||
5 | if(a != null) | ||
6 | if("number" == typeof a) this.fromNumber(a,b,c); | ||
7 | else if(b == null && "string" != typeof a) this.fromString(a,256); | ||
8 | else this.fromString(a,b); | ||
9 | } | ||
10 | function nbi() { return new BigInteger(null); } | ||
11 | function am1(i,x,w,j,c,n) { | ||
12 | while(--n >= 0) { | ||
13 | var v = x*this[i++]+w[j]+c; | ||
14 | c = Math.floor(v/0x4000000); | ||
15 | w[j++] = v&0x3ffffff; | ||
16 | } | ||
17 | return c; | ||
18 | } | ||
19 | function am2(i,x,w,j,c,n) { | ||
20 | var xl = x&0x7fff, xh = x>>15; | ||
21 | while(--n >= 0) { | ||
22 | var l = this[i]&0x7fff; | ||
23 | var h = this[i++]>>15; | ||
24 | var m = xh*l+h*xl; | ||
25 | l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff); | ||
26 | c = (l>>>30)+(m>>>15)+xh*h+(c>>>30); | ||
27 | w[j++] = l&0x3fffffff; | ||
28 | } | ||
29 | return c; | ||
30 | } | ||
31 | function am3(i,x,w,j,c,n) { | ||
32 | var xl = x&0x3fff, xh = x>>14; | ||
33 | while(--n >= 0) { | ||
34 | var l = this[i]&0x3fff; | ||
35 | var h = this[i++]>>14; | ||
36 | var m = xh*l+h*xl; | ||
37 | l = xl*l+((m&0x3fff)<<14)+w[j]+c; | ||
38 | c = (l>>28)+(m>>14)+xh*h; | ||
39 | w[j++] = l&0xfffffff; | ||
40 | } | ||
41 | return c; | ||
42 | } | ||
43 | if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) { | ||
44 | BigInteger.prototype.am = am2; | ||
45 | dbits = 30; | ||
46 | } | ||
47 | else if(j_lm && (navigator.appName != "Netscape")) { | ||
48 | BigInteger.prototype.am = am1; | ||
49 | dbits = 26; | ||
50 | } | ||
51 | else { | ||
52 | BigInteger.prototype.am = am3; | ||
53 | dbits = 28; | ||
54 | } | ||
55 | BigInteger.prototype.DB = dbits; | ||
56 | BigInteger.prototype.DM = ((1<<dbits)-1); | ||
57 | BigInteger.prototype.DV = (1<<dbits); | ||
58 | var BI_FP = 52; | ||
59 | BigInteger.prototype.FV = Math.pow(2,BI_FP); | ||
60 | BigInteger.prototype.F1 = BI_FP-dbits; | ||
61 | BigInteger.prototype.F2 = 2*dbits-BI_FP; | ||
62 | var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"; | ||
63 | var BI_RC = new Array(); | ||
64 | var rr,vv; | ||
65 | rr = "0".charCodeAt(0); | ||
66 | for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv; | ||
67 | rr = "a".charCodeAt(0); | ||
68 | for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv; | ||
69 | rr = "A".charCodeAt(0); | ||
70 | for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv; | ||
71 | function int2char(n) { return BI_RM.charAt(n); } | ||
72 | function intAt(s,i) { | ||
73 | var c = BI_RC[s.charCodeAt(i)]; | ||
74 | return (c==null)?-1:c; | ||
75 | } | ||
76 | function bnpCopyTo(r) { | ||
77 | for(var i = this.t-1; i >= 0; --i) r[i] = this[i]; | ||
78 | r.t = this.t; | ||
79 | r.s = this.s; | ||
80 | } | ||
81 | function bnpFromInt(x) { | ||
82 | this.t = 1; | ||
83 | this.s = (x<0)?-1:0; | ||
84 | if(x > 0) this[0] = x; | ||
85 | else if(x < -1) this[0] = x+DV; | ||
86 | else this.t = 0; | ||
87 | } | ||
88 | function nbv(i) { var r = nbi(); r.fromInt(i); return r; } | ||
89 | function bnpFromString(s,b) { | ||
90 | var k; | ||
91 | if(b == 16) k = 4; | ||
92 | else if(b == 8) k = 3; | ||
93 | else if(b == 256) k = 8; | ||
94 | else if(b == 2) k = 1; | ||
95 | else if(b == 32) k = 5; | ||
96 | else if(b == 4) k = 2; | ||
97 | else { this.fromRadix(s,b); return; } | ||
98 | this.t = 0; | ||
99 | this.s = 0; | ||
100 | var i = s.length, mi = false, sh = 0; | ||
101 | while(--i >= 0) { | ||
102 | var x = (k==8)?s[i]&0xff:intAt(s,i); | ||
103 | if(x < 0) { | ||
104 | if(s.charAt(i) == "-") mi = true; | ||
105 | continue; | ||
106 | } | ||
107 | mi = false; | ||
108 | if(sh == 0) | ||
109 | this[this.t++] = x; | ||
110 | else if(sh+k > this.DB) { | ||
111 | this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh; | ||
112 | this[this.t++] = (x>>(this.DB-sh)); | ||
113 | } | ||
114 | else | ||
115 | this[this.t-1] |= x<<sh; | ||
116 | sh += k; | ||
117 | if(sh >= this.DB) sh -= this.DB; | ||
118 | } | ||
119 | if(k == 8 && (s[0]&0x80) != 0) { | ||
120 | this.s = -1; | ||
121 | if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh; | ||
122 | } | ||
123 | this.clamp(); | ||
124 | if(mi) BigInteger.ZERO.subTo(this,this); | ||
125 | } | ||
126 | function bnpClamp() { | ||
127 | var c = this.s&this.DM; | ||
128 | while(this.t > 0 && this[this.t-1] == c) --this.t; | ||
129 | } | ||
130 | function bnToString(b) { | ||
131 | if(this.s < 0) return "-"+this.negate().toString(b); | ||
132 | var k; | ||
133 | if(b == 16) k = 4; | ||
134 | else if(b == 8) k = 3; | ||
135 | else if(b == 2) k = 1; | ||
136 | else if(b == 32) k = 5; | ||
137 | else if(b == 4) k = 2; | ||
138 | else return this.toRadix(b); | ||
139 | var km = (1<<k)-1, d, m = false, r = "", i = this.t; | ||
140 | var p = this.DB-(i*this.DB)%k; | ||
141 | if(i-- > 0) { | ||
142 | if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); } | ||
143 | while(i >= 0) { | ||
144 | if(p < k) { | ||
145 | d = (this[i]&((1<<p)-1))<<(k-p); | ||
146 | d |= this[--i]>>(p+=this.DB-k); | ||
147 | } | ||
148 | else { | ||
149 | d = (this[i]>>(p-=k))&km; | ||
150 | if(p <= 0) { p += this.DB; --i; } | ||
151 | } | ||
152 | if(d > 0) m = true; | ||
153 | if(m) r += int2char(d); | ||
154 | } | ||
155 | } | ||
156 | return m?r:"0"; | ||
157 | } | ||
158 | function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; } | ||
159 | function bnAbs() { return (this.s<0)?this.negate():this; } | ||
160 | function bnCompareTo(a) { | ||
161 | var r = this.s-a.s; | ||
162 | if(r != 0) return r; | ||
163 | var i = this.t; | ||
164 | r = i-a.t; | ||
165 | if(r != 0) return r; | ||
166 | while(--i >= 0) if((r=this[i]-a[i]) != 0) return r; | ||
167 | return 0; | ||
168 | } | ||
169 | function nbits(x) { | ||
170 | var r = 1, t; | ||
171 | if((t=x>>>16) != 0) { x = t; r += 16; } | ||
172 | if((t=x>>8) != 0) { x = t; r += 8; } | ||
173 | if((t=x>>4) != 0) { x = t; r += 4; } | ||
174 | if((t=x>>2) != 0) { x = t; r += 2; } | ||
175 | if((t=x>>1) != 0) { x = t; r += 1; } | ||
176 | return r; | ||
177 | } | ||
178 | function bnBitLength() { | ||
179 | if(this.t <= 0) return 0; | ||
180 | return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM)); | ||
181 | } | ||
182 | function bnpDLShiftTo(n,r) { | ||
183 | var i; | ||
184 | for(i = this.t-1; i >= 0; --i) r[i+n] = this[i]; | ||
185 | for(i = n-1; i >= 0; --i) r[i] = 0; | ||
186 | r.t = this.t+n; | ||
187 | r.s = this.s; | ||
188 | } | ||
189 | function bnpDRShiftTo(n,r) { | ||
190 | for(var i = n; i < this.t; ++i) r[i-n] = this[i]; | ||
191 | r.t = Math.max(this.t-n,0); | ||
192 | r.s = this.s; | ||
193 | } | ||
194 | function bnpLShiftTo(n,r) { | ||
195 | var bs = n%this.DB; | ||
196 | var cbs = this.DB-bs; | ||
197 | var bm = (1<<cbs)-1; | ||
198 | var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i; | ||
199 | for(i = this.t-1; i >= 0; --i) { | ||
200 | r[i+ds+1] = (this[i]>>cbs)|c; | ||
201 | c = (this[i]&bm)<<bs; | ||
202 | } | ||
203 | for(i = ds-1; i >= 0; --i) r[i] = 0; | ||
204 | r[ds] = c; | ||
205 | r.t = this.t+ds+1; | ||
206 | r.s = this.s; | ||
207 | r.clamp(); | ||
208 | } | ||
209 | function bnpRShiftTo(n,r) { | ||
210 | r.s = this.s; | ||
211 | var ds = Math.floor(n/this.DB); | ||
212 | if(ds >= this.t) { r.t = 0; return; } | ||
213 | var bs = n%this.DB; | ||
214 | var cbs = this.DB-bs; | ||
215 | var bm = (1<<bs)-1; | ||
216 | r[0] = this[ds]>>bs; | ||
217 | for(var i = ds+1; i < this.t; ++i) { | ||
218 | r[i-ds-1] |= (this[i]&bm)<<cbs; | ||
219 | r[i-ds] = this[i]>>bs; | ||
220 | } | ||
221 | if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs; | ||
222 | r.t = this.t-ds; | ||
223 | r.clamp(); | ||
224 | } | ||
225 | function bnpSubTo(a,r) { | ||
226 | var i = 0, c = 0, m = Math.min(a.t,this.t); | ||
227 | while(i < m) { | ||
228 | c += this[i]-a[i]; | ||
229 | r[i++] = c&this.DM; | ||
230 | c >>= this.DB; | ||
231 | } | ||
232 | if(a.t < this.t) { | ||
233 | c -= a.s; | ||
234 | while(i < this.t) { | ||
235 | c += this[i]; | ||
236 | r[i++] = c&this.DM; | ||
237 | c >>= this.DB; | ||
238 | } | ||
239 | c += this.s; | ||
240 | } | ||
241 | else { | ||
242 | c += this.s; | ||
243 | while(i < a.t) { | ||
244 | c -= a[i]; | ||
245 | r[i++] = c&this.DM; | ||
246 | c >>= this.DB; | ||
247 | } | ||
248 | c -= a.s; | ||
249 | } | ||
250 | r.s = (c<0)?-1:0; | ||
251 | if(c < -1) r[i++] = this.DV+c; | ||
252 | else if(c > 0) r[i++] = c; | ||
253 | r.t = i; | ||
254 | r.clamp(); | ||
255 | } | ||
256 | function bnpMultiplyTo(a,r) { | ||
257 | var x = this.abs(), y = a.abs(); | ||
258 | var i = x.t; | ||
259 | r.t = i+y.t; | ||
260 | while(--i >= 0) r[i] = 0; | ||
261 | for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t); | ||
262 | r.s = 0; | ||
263 | r.clamp(); | ||
264 | if(this.s != a.s) BigInteger.ZERO.subTo(r,r); | ||
265 | } | ||
266 | function bnpSquareTo(r) { | ||
267 | var x = this.abs(); | ||
268 | var i = r.t = 2*x.t; | ||
269 | while(--i >= 0) r[i] = 0; | ||
270 | for(i = 0; i < x.t-1; ++i) { | ||
271 | var c = x.am(i,x[i],r,2*i,0,1); | ||
272 | if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) { | ||
273 | r[i+x.t] -= x.DV; | ||
274 | r[i+x.t+1] = 1; | ||
275 | } | ||
276 | } | ||
277 | if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1); | ||
278 | r.s = 0; | ||
279 | r.clamp(); | ||
280 | } | ||
281 | function bnpDivRemTo(m,q,r) { | ||
282 | var pm = m.abs(); | ||
283 | if(pm.t <= 0) return; | ||
284 | var pt = this.abs(); | ||
285 | if(pt.t < pm.t) { | ||
286 | if(q != null) q.fromInt(0); | ||
287 | if(r != null) this.copyTo(r); | ||
288 | return; | ||
289 | } | ||
290 | if(r == null) r = nbi(); | ||
291 | var y = nbi(), ts = this.s, ms = m.s; | ||
292 | var nsh = this.DB-nbits(pm[pm.t-1]); | ||
293 | if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } | ||
294 | else { pm.copyTo(y); pt.copyTo(r); } | ||
295 | var ys = y.t; | ||
296 | var y0 = y[ys-1]; | ||
297 | if(y0 == 0) return; | ||
298 | var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0); | ||
299 | var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2; | ||
300 | var i = r.t, j = i-ys, t = (q==null)?nbi():q; | ||
301 | y.dlShiftTo(j,t); | ||
302 | if(r.compareTo(t) >= 0) { | ||
303 | r[r.t++] = 1; | ||
304 | r.subTo(t,r); | ||
305 | } | ||
306 | BigInteger.ONE.dlShiftTo(ys,t); | ||
307 | t.subTo(y,y); | ||
308 | while(y.t < ys) y[y.t++] = 0; | ||
309 | while(--j >= 0) { | ||
310 | |||
311 | var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2); | ||
312 | if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { | ||
313 | y.dlShiftTo(j,t); | ||
314 | r.subTo(t,r); | ||
315 | while(r[i] < --qd) r.subTo(t,r); | ||
316 | } | ||
317 | } | ||
318 | if(q != null) { | ||
319 | r.drShiftTo(ys,q); | ||
320 | if(ts != ms) BigInteger.ZERO.subTo(q,q); | ||
321 | } | ||
322 | r.t = ys; | ||
323 | r.clamp(); | ||
324 | if(nsh > 0) r.rShiftTo(nsh,r); | ||
325 | if(ts < 0) BigInteger.ZERO.subTo(r,r); | ||
326 | } | ||
327 | function bnMod(a) { | ||
328 | var r = nbi(); | ||
329 | this.abs().divRemTo(a,null,r); | ||
330 | if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r); | ||
331 | return r; | ||
332 | } | ||
333 | function Classic(m) { this.m = m; } | ||
334 | function cConvert(x) { | ||
335 | if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); | ||
336 | else return x; | ||
337 | } | ||
338 | function cRevert(x) { return x; } | ||
339 | function cReduce(x) { x.divRemTo(this.m,null,x); } | ||
340 | function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } | ||
341 | function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); } | ||
342 | Classic.prototype.convert = cConvert; | ||
343 | Classic.prototype.revert = cRevert; | ||
344 | Classic.prototype.reduce = cReduce; | ||
345 | Classic.prototype.mulTo = cMulTo; | ||
346 | Classic.prototype.sqrTo = cSqrTo; | ||
347 | function bnpInvDigit() { | ||
348 | if(this.t < 1) return 0; | ||
349 | var x = this[0]; | ||
350 | if((x&1) == 0) return 0; | ||
351 | var y = x&3; | ||
352 | y = (y*(2-(x&0xf)*y))&0xf; | ||
353 | y = (y*(2-(x&0xff)*y))&0xff; | ||
354 | y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; | ||
355 | |||
356 | |||
357 | y = (y*(2-x*y%this.DV))%this.DV; | ||
358 | |||
359 | return (y>0)?this.DV-y:-y; | ||
360 | } | ||
361 | function Montgomery(m) { | ||
362 | this.m = m; | ||
363 | this.mp = m.invDigit(); | ||
364 | this.mpl = this.mp&0x7fff; | ||
365 | this.mph = this.mp>>15; | ||
366 | this.um = (1<<(m.DB-15))-1; | ||
367 | this.mt2 = 2*m.t; | ||
368 | } | ||
369 | function montConvert(x) { | ||
370 | var r = nbi(); | ||
371 | x.abs().dlShiftTo(this.m.t,r); | ||
372 | r.divRemTo(this.m,null,r); | ||
373 | if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r); | ||
374 | return r; | ||
375 | } | ||
376 | function montRevert(x) { | ||
377 | var r = nbi(); | ||
378 | x.copyTo(r); | ||
379 | this.reduce(r); | ||
380 | return r; | ||
381 | } | ||
382 | function montReduce(x) { | ||
383 | while(x.t <= this.mt2) | ||
384 | x[x.t++] = 0; | ||
385 | for(var i = 0; i < this.m.t; ++i) { | ||
386 | |||
387 | var j = x[i]&0x7fff; | ||
388 | var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM; | ||
389 | |||
390 | j = i+this.m.t; | ||
391 | x[j] += this.m.am(0,u0,x,i,0,this.m.t); | ||
392 | |||
393 | while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; } | ||
394 | } | ||
395 | x.clamp(); | ||
396 | x.drShiftTo(this.m.t,x); | ||
397 | if(x.compareTo(this.m) >= 0) x.subTo(this.m,x); | ||
398 | } | ||
399 | function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); } | ||
400 | function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } | ||
401 | Montgomery.prototype.convert = montConvert; | ||
402 | Montgomery.prototype.revert = montRevert; | ||
403 | Montgomery.prototype.reduce = montReduce; | ||
404 | Montgomery.prototype.mulTo = montMulTo; | ||
405 | Montgomery.prototype.sqrTo = montSqrTo; | ||
406 | function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; } | ||
407 | function bnpExp(e,z) { | ||
408 | if(e > 0xffffffff || e < 1) return BigInteger.ONE; | ||
409 | var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; | ||
410 | g.copyTo(r); | ||
411 | while(--i >= 0) { | ||
412 | z.sqrTo(r,r2); | ||
413 | if((e&(1<<i)) > 0) z.mulTo(r2,g,r); | ||
414 | else { var t = r; r = r2; r2 = t; } | ||
415 | } | ||
416 | return z.revert(r); | ||
417 | } | ||
418 | function bnModPowInt(e,m) { | ||
419 | var z; | ||
420 | if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); | ||
421 | return this.exp(e,z); | ||
422 | } | ||
423 | BigInteger.prototype.copyTo = bnpCopyTo; | ||
424 | BigInteger.prototype.fromInt = bnpFromInt; | ||
425 | BigInteger.prototype.fromString = bnpFromString; | ||
426 | BigInteger.prototype.clamp = bnpClamp; | ||
427 | BigInteger.prototype.dlShiftTo = bnpDLShiftTo; | ||
428 | BigInteger.prototype.drShiftTo = bnpDRShiftTo; | ||
429 | BigInteger.prototype.lShiftTo = bnpLShiftTo; | ||
430 | BigInteger.prototype.rShiftTo = bnpRShiftTo; | ||
431 | BigInteger.prototype.subTo = bnpSubTo; | ||
432 | BigInteger.prototype.multiplyTo = bnpMultiplyTo; | ||
433 | BigInteger.prototype.squareTo = bnpSquareTo; | ||
434 | BigInteger.prototype.divRemTo = bnpDivRemTo; | ||
435 | BigInteger.prototype.invDigit = bnpInvDigit; | ||
436 | BigInteger.prototype.isEven = bnpIsEven; | ||
437 | BigInteger.prototype.exp = bnpExp; | ||
438 | BigInteger.prototype.toString = bnToString; | ||
439 | BigInteger.prototype.negate = bnNegate; | ||
440 | BigInteger.prototype.abs = bnAbs; | ||
441 | BigInteger.prototype.compareTo = bnCompareTo; | ||
442 | BigInteger.prototype.bitLength = bnBitLength; | ||
443 | BigInteger.prototype.mod = bnMod; | ||
444 | BigInteger.prototype.modPowInt = bnModPowInt; | ||
445 | BigInteger.ZERO = nbv(0); | ||
446 | BigInteger.ONE = nbv(1); | ||
447 | function Arcfour() { | ||
448 | this.i = 0; | ||
449 | this.j = 0; | ||
450 | this.S = new Array(); | ||
451 | } | ||
452 | function ARC4init(key) { | ||
453 | var i, j, t; | ||
454 | for(i = 0; i < 256; ++i) | ||
455 | this.S[i] = i; | ||
456 | j = 0; | ||
457 | for(i = 0; i < 256; ++i) { | ||
458 | j = (j + this.S[i] + key[i % key.length]) & 255; | ||
459 | t = this.S[i]; | ||
460 | this.S[i] = this.S[j]; | ||
461 | this.S[j] = t; | ||
462 | } | ||
463 | this.i = 0; | ||
464 | this.j = 0; | ||
465 | } | ||
466 | function ARC4next() { | ||
467 | var t; | ||
468 | this.i = (this.i + 1) & 255; | ||
469 | this.j = (this.j + this.S[this.i]) & 255; | ||
470 | t = this.S[this.i]; | ||
471 | this.S[this.i] = this.S[this.j]; | ||
472 | this.S[this.j] = t; | ||
473 | return this.S[(t + this.S[this.i]) & 255]; | ||
474 | } | ||
475 | Arcfour.prototype.init = ARC4init; | ||
476 | Arcfour.prototype.next = ARC4next; | ||
477 | function prng_newstate() { | ||
478 | return new Arcfour(); | ||
479 | } | ||
480 | var rng_psize = 256; | ||
481 | var rng_state; | ||
482 | var rng_pool; | ||
483 | var rng_pptr; | ||
484 | function rng_seed_int(x) { | ||
485 | rng_pool[rng_pptr++] ^= x & 255; | ||
486 | rng_pool[rng_pptr++] ^= (x >> 8) & 255; | ||
487 | rng_pool[rng_pptr++] ^= (x >> 16) & 255; | ||
488 | rng_pool[rng_pptr++] ^= (x >> 24) & 255; | ||
489 | if(rng_pptr >= rng_psize) rng_pptr -= rng_psize; | ||
490 | } | ||
491 | function rng_seed_time() { | ||
492 | rng_seed_int(new Date().getTime()); | ||
493 | } | ||
494 | if(rng_pool == null) { | ||
495 | rng_pool = new Array(); | ||
496 | rng_pptr = 0; | ||
497 | var t; | ||
498 | if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) { | ||
499 | |||
500 | var z = window.crypto.random(32); | ||
501 | for(t = 0; t < z.length; ++t) | ||
502 | rng_pool[rng_pptr++] = z.charCodeAt(t) & 255; | ||
503 | } | ||
504 | while(rng_pptr < rng_psize) { | ||
505 | t = Math.floor(65536 * Math.random()); | ||
506 | rng_pool[rng_pptr++] = t >>> 8; | ||
507 | rng_pool[rng_pptr++] = t & 255; | ||
508 | } | ||
509 | rng_pptr = 0; | ||
510 | rng_seed_time(); | ||
511 | |||
512 | |||
513 | } | ||
514 | function rng_get_byte() { | ||
515 | if(rng_state == null) { | ||
516 | rng_seed_time(); | ||
517 | rng_state = prng_newstate(); | ||
518 | rng_state.init(rng_pool); | ||
519 | for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) | ||
520 | rng_pool[rng_pptr] = 0; | ||
521 | rng_pptr = 0; | ||
522 | |||
523 | } | ||
524 | |||
525 | return rng_state.next(); | ||
526 | } | ||
527 | function rng_get_bytes(ba) { | ||
528 | var i; | ||
529 | for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte(); | ||
530 | } | ||
531 | function SecureRandom() {} | ||
532 | SecureRandom.prototype.nextBytes = rng_get_bytes; | ||
533 | function parseBigInt(str,r) { | ||
534 | return new BigInteger(str,r); | ||
535 | } | ||
536 | function linebrk(s,n) { | ||
537 | var ret = ""; | ||
538 | var i = 0; | ||
539 | while(i + n < s.length) { | ||
540 | ret += s.substring(i,i+n) + "\n"; | ||
541 | i += n; | ||
542 | } | ||
543 | return ret + s.substring(i,s.length); | ||
544 | } | ||
545 | function byte2Hex(b) { | ||
546 | if(b < 0x10) | ||
547 | return "0" + b.toString(16); | ||
548 | else | ||
549 | return b.toString(16); | ||
550 | } | ||
551 | function pkcs1pad2(s,n) { | ||
552 | if(n < s.length + 11) { | ||
553 | alert("Message too long for RSA"); | ||
554 | return null; | ||
555 | } | ||
556 | var ba = new Array(); | ||
557 | var i = s.length - 1; | ||
558 | while(i >= 0 && n > 0) { | ||
559 | var c = s.charCodeAt(i--); | ||
560 | if(c < 128) { | ||
561 | ba[--n] = c; | ||
562 | } | ||
563 | else if((c > 127) && (c < 2048)) { | ||
564 | ba[--n] = (c & 63) | 128; | ||
565 | ba[--n] = (c >> 6) | 192; | ||
566 | } | ||
567 | else { | ||
568 | ba[--n] = (c & 63) | 128; | ||
569 | ba[--n] = ((c >> 6) & 63) | 128; | ||
570 | ba[--n] = (c >> 12) | 224; | ||
571 | } | ||
572 | } | ||
573 | ba[--n] = 0; | ||
574 | var rng = new SecureRandom(); | ||
575 | var x = new Array(); | ||
576 | while(n > 2) { | ||
577 | x[0] = 0; | ||
578 | while(x[0] == 0) rng.nextBytes(x); | ||
579 | ba[--n] = x[0]; | ||
580 | } | ||
581 | ba[--n] = 2; | ||
582 | ba[--n] = 0; | ||
583 | return new BigInteger(ba); | ||
584 | } | ||
585 | |||
586 | function pkcs1pad2Bank(s,n) { | ||
587 | //2位长度+pin+rnd | ||
588 | if(n < s.length + 2) { | ||
589 | alert("密码太长!"); | ||
590 | return null; | ||
591 | } | ||
592 | |||
593 | var ba = new Array(); | ||
594 | var i = s.length - 1; | ||
595 | |||
596 | var len = s.length; | ||
597 | if(len<100){ | ||
598 | ba[0]=0x30+len/10; | ||
599 | ba[1]=0x30+len%10; | ||
600 | }else{ | ||
601 | alert("密码太长!"); | ||
602 | return null; | ||
603 | } | ||
604 | |||
605 | var j=2; | ||
606 | i=0; | ||
607 | while(i < len && n > 0) { | ||
608 | ba[j++] = s.charCodeAt(i++); | ||
609 | } | ||
610 | |||
611 | var rng = new SecureRandom(); | ||
612 | var x = new Array(); | ||
613 | while(j<n) { | ||
614 | x[0] = 0; | ||
615 | while(x[0] == 0) | ||
616 | rng.nextBytes(x); | ||
617 | ba[j++] = x[0]; | ||
618 | } | ||
619 | |||
620 | return new BigInteger(ba); | ||
621 | } | ||
622 | |||
623 | function RSAKey() { | ||
624 | this.n = null; | ||
625 | this.e = 0; | ||
626 | this.d = null; | ||
627 | this.p = null; | ||
628 | this.q = null; | ||
629 | this.dmp1 = null; | ||
630 | this.dmq1 = null; | ||
631 | this.coeff = null; | ||
632 | } | ||
633 | function RSASetPublic(N,E) { | ||
634 | if(N != null && E != null && N.length > 0 && E.length > 0) { | ||
635 | this.n = parseBigInt(N,16); | ||
636 | this.e = parseInt(E,16); | ||
637 | } | ||
638 | else{ | ||
639 | alert("Invalid RSA public key"); | ||
640 | } | ||
641 | } | ||
642 | function RSADoPublic(x) { | ||
643 | return x.modPowInt(this.e, this.n); | ||
644 | } | ||
645 | function RSAEncrypt(text) { | ||
646 | var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3); | ||
647 | if(m == null) return null; | ||
648 | var c = this.doPublic(m); | ||
649 | if(c == null) return null; | ||
650 | var h = c.toString(16).toUpperCase(); | ||
651 | var gapLen = 256 - h.length; | ||
652 | for(var i = 0; i < gapLen; i = i + 1){ | ||
653 | h = "0" + h; | ||
654 | } | ||
655 | return h; | ||
656 | } | ||
657 | function RSAEncryptPama(text) { | ||
658 | var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3); | ||
659 | if(m == null) return null; | ||
660 | var c = this.doPublic(m); | ||
661 | if(c == null) return null; | ||
662 | var h = c.toString(16).toUpperCase(); | ||
663 | var gapLen = 512 - h.length; | ||
664 | for(var i = 0; i < gapLen; i = i + 1){ | ||
665 | h = "0" + h; | ||
666 | } | ||
667 | return "PAMA" + h; | ||
668 | } | ||
669 | function RSAEncryptBank(text) { | ||
670 | var m = pkcs1pad2Bank(text,(this.n.bitLength()+7)>>3); | ||
671 | if(m == null) return null; | ||
672 | var c = this.doPublic(m); | ||
673 | if(c == null) return null; | ||
674 | var h = c.toString(16).toUpperCase(); | ||
675 | var gapLen = 256 - h.length; | ||
676 | for(var i = 0; i < gapLen; i = i + 1){ | ||
677 | h = "0" + h; | ||
678 | } | ||
679 | return h; | ||
680 | } | ||
681 | RSAKey.prototype.doPublic = RSADoPublic; | ||
682 | RSAKey.prototype.setPublic = RSASetPublic; | ||
683 | RSAKey.prototype.encrypt = RSAEncrypt;/*通用RSA加密*/ | ||
684 | RSAKey.prototype.encryptPama = RSAEncryptPama;/*PAMA RSA加密*/ | ||
685 | RSAKey.prototype.encryptBank = RSAEncryptBank;/*银行RSA加密*/ | ||
686 | var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
687 | var b64pad="="; | ||
688 | function hex2b64(h) { | ||
689 | var i; | ||
690 | var c; | ||
691 | var ret = ""; | ||
692 | for(i = 0; i+3 <= h.length; i+=3) { | ||
693 | c = parseInt(h.substring(i,i+3),16); | ||
694 | ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63); | ||
695 | } | ||
696 | if(i+1 == h.length) { | ||
697 | c = parseInt(h.substring(i,i+1),16); | ||
698 | ret += b64map.charAt(c << 2); | ||
699 | } | ||
700 | else if(i+2 == h.length) { | ||
701 | c = parseInt(h.substring(i,i+2),16); | ||
702 | ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4); | ||
703 | } | ||
704 | while((ret.length & 3) > 0) ret += b64pad; | ||
705 | return ret; | ||
706 | } | ||
707 | function b64tohex(s) { | ||
708 | var ret = "" | ||
709 | var i; | ||
710 | var k = 0; | ||
711 | var slop; | ||
712 | for(i = 0; i < s.length; ++i) { | ||
713 | if(s.charAt(i) == b64pad) break; | ||
714 | v = b64map.indexOf(s.charAt(i)); | ||
715 | if(v < 0) continue; | ||
716 | if(k == 0) { | ||
717 | ret += int2char(v >> 2); | ||
718 | slop = v & 3; | ||
719 | k = 1; | ||
720 | } | ||
721 | else if(k == 1) { | ||
722 | ret += int2char((slop << 2) | (v >> 4)); | ||
723 | slop = v & 0xf; | ||
724 | k = 2; | ||
725 | } | ||
726 | else if(k == 2) { | ||
727 | ret += int2char(slop); | ||
728 | ret += int2char(v >> 2); | ||
729 | slop = v & 3; | ||
730 | k = 3; | ||
731 | } | ||
732 | else { | ||
733 | ret += int2char((slop << 2) | (v >> 4)); | ||
734 | ret += int2char(v & 0xf); | ||
735 | k = 0; | ||
736 | } | ||
737 | } | ||
738 | if(k == 1) | ||
739 | ret += int2char(slop << 2); | ||
740 | return ret; | ||
741 | } | ||
742 | function b64toBA(s) { | ||
743 | |||
744 | var h = b64tohex(s); | ||
745 | var i; | ||
746 | var a = new Array(); | ||
747 | for(i = 0; 2*i < h.length; ++i) { | ||
748 | a[i] = parseInt(h.substring(2*i,2*i+2),16); | ||
749 | } | ||
750 | return a; | ||
751 | } |
... | @@ -11,10 +11,7 @@ function Toast(msg) { | ... | @@ -11,10 +11,7 @@ function Toast(msg) { |
11 | // axios.defaults.baseURL = "" | 11 | // axios.defaults.baseURL = "" |
12 | 12 | ||
13 | // 服务器地址 | 13 | // 服务器地址 |
14 | let base = "https://ow.go.qudone.com"; | 14 | let base = "http://localhost:9101"; |
15 | if (location.href.indexOf("//k.wxpai.cn") > 0) { | ||
16 | base = "https://api.k.wxpai.cn/bizproxy" | ||
17 | } | ||
18 | // let base = COM.baseUrl; | 15 | // let base = COM.baseUrl; |
19 | 16 | ||
20 | // 请求拦截器 | 17 | // 请求拦截器 | ... | ... |
... | @@ -8,7 +8,11 @@ export default { | ... | @@ -8,7 +8,11 @@ export default { |
8 | data() { | 8 | data() { |
9 | return { | 9 | return { |
10 | key: 'value', | 10 | key: 'value', |
11 | type: 1, // 1:帐密登陆 2:OTP登陆 | 11 | type: 1, // 1:帐密登陆 2:OTP登陆, |
12 | values : { | ||
13 | // 返回的token,串连整个流程,后台安全校验使用 | ||
14 | token : "", | ||
15 | } | ||
12 | } | 16 | } |
13 | }, | 17 | }, |
14 | components: {}, | 18 | components: {}, |
... | @@ -43,7 +47,11 @@ export default { | ... | @@ -43,7 +47,11 @@ export default { |
43 | onLoginTypeHandler(val) { | 47 | onLoginTypeHandler(val) { |
44 | this.type = val; | 48 | this.type = val; |
45 | }, | 49 | }, |
46 | initData() {} | 50 | initData() {}, |
51 | // 是否显示图形二维码 | ||
52 | handlerIsShowImageVcode(){ | ||
53 | |||
54 | } | ||
47 | }, | 55 | }, |
48 | mounted() {}, | 56 | mounted() {}, |
49 | created() {} | 57 | created() {} | ... | ... |
-
Please register or sign in to post a comment