bank_card.js

Posted xiaodebing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bank_card.js相关的知识,希望对你有一定的参考价值。

  1 function init() {
  2     undefined = "undefined";
  3     mkCClist();
  4 }
  5 
  6 function ccchk(cdi) {
  7     output1 = "";
  8     if (cdi != "" && cdi != null) {
  9         output1 = "Processing...";
 10         var cf = sbtString(cdi, " -/abcdefghijklmnopqrstuvwyzABCDEFGHIJLMNOPQRSTUVWYZ|#()[]{}?%&=!?+*.,;:‘");
 11         var cn = chkCard(cf);
 12         var clcd = chkLCD(cf);
 13         var clcdt = "NOT PASSED";
 14         if (clcd) {
 15             clcdt = "PASSED";
 16         }
 17         var ccck = chkCCCksum(cf, cn);
 18         var ccckt = "NOT PASSED";
 19         if (ccck) {
 20             ccckt = "PASSED";
 21         }
 22         var cjd = "INVALID CARD NUMBER";
 23         if (clcd && ccck) {
 24             cjd = "This card number appears to be valid.";
 25         }
 26         var out = "";
 27         out += "Card type       : " + cn + "
";
 28         out += "CCChecksum      : " + ccckt + "
";
 29         out += "Luhn Check Digit: " + clcdt + "
";
 30         out += cjd;
 31         output1 = out;
 32     }
 33 }
 34 
 35 function ccngen(p, tr) {
 36     tr *= 1.0;
 37     if (tr < 1 || tr == null) {
 38         tr = 1;
 39     }
 40     output2 = "";
 41     if (p != "" && p != null) {
 42         var cn = chkCard(p);//去掉非数字
 43         for (var i = tr; i >= 1; i--) {
 44             output2 = "Processing... " + i;
 45             var cdi = sbtStringSpRnd(p, "x", "0123456789");  //非x保留,x替换为一个0-9的随机数
 46             var cf = sbtString(cdi, " -/abcdefghijklmnopqrstuvwyzABCDEFGHIJLMNOPQRSTUVWYZ");
 47             var clcd = chkLCD(cf);
 48             var ccck = chkCCCksum(cf, cn);
 49             if (clcd && ccck) {
 50                 break;
 51             }
 52         }
 53         var out = "Couldn‘t find any valid number for given pattern";
 54         if (clcd && ccck) {
 55             var cn = chkCard(cdi);
 56             var ccnspc = "";
 57             for (var j = 0; j <= 3; j++) {
 58                 if (document.console.ccnsp.options[j].selected) {
 59                     break;
 60                 }
 61             }
 62             if (j == 1) {
 63                 ccnspc = " ";
 64             }
 65             if (j == 2) {
 66                 ccnspc = "-";
 67             }
 68             var cdif = "";
 69             for (var i = 1; i <= cdi.length; i++) {
 70                 var aS = midS(cdi, i, 1);
 71                 if (aS == " ") {
 72                     aS = ccnspc;
 73                 }
 74                 cdif += aS;
 75             }
 76             var out = "Valid " + cn + " # found:
" + cdif;
 77         }
 78         output2 = out;
 79     }
 80 }
 81 
 82 function chgccp() {
 83     mkCClist();
 84     for (var j = 0; j <= tw - 1; j++) {
 85         if (document.console.ccpp.options[j].selected) {
 86             break;
 87         }
 88     }
 89     document.console.ccp.value = c[j + 1];
 90 }
 91 
 92 function chkCard(cdi) {
 93     cdi += "";
 94     if (c[1] == undefined || c[1] == null || c[1] == "") {
 95         mkCClist();
 96     }
 97     var ccn = 0;
 98     var cn = "unknown"
 99     var cf = sbtString(cdi, " -/abcdefghijklmnopqrstuvwyzABCDEFGHIJLMNOPQRSTUVWYZ");
100     if (leftS(cf, 1) == "4") {
101         cf = leftS(cf, 8);
102     }
103     for (var i = 1; i <= tw; i++) {
104         var cct = sbtString(c[i], " -/abcdefghijklmnopqrstuvwyzABCDEFGHIJLMNOPQRSTUVWYZ");
105         if (leftS(cf, 1) == "4") {
106             cct = leftS(cct, 8);
107         }
108         var ccc = cmpPattern(cf, cct);
109         if (ccc) {
110             ccn = i;
111             break;
112         }
113     }
114     if (ccn > 0) {
115         cn = cd[i];
116     }
117     return cn;
118 }
119 
120 function chkCCCksum(cf, cn) {
121     var r = false;
122     var w = "21";
123     // if (linstr(cn,"AmEx") || linstr(cn,"Diner")) {var w="12";}
124     var ml = "";
125     var j = 1;
126     for (var i = 1; i <= cf.length - 1; i++) {
127         var m = midS(cf, i, 1) * midS(w, j, 1);
128         m = sumDigits(m);
129         ml += "" + m;
130         j++;
131         if (j > w.length) {
132             j = 1;
133         }
134     }
135     var ml2 = sumDigits(ml, -1);
136     var ml1 = (sumDigits(ml2, -1) * 10 - ml2) % 10;
137     if (ml1 == rightS(cf, 1)) {
138         r = true;
139     }
140     return r;
141 }
142 
143 function chkLCD(cf) {
144     var r = false;
145     cf += "";
146     var bl = isdiv(cf.length, 2);
147     var ctd = 0;
148     for (var i = 1; i <= cf.length; i++) {
149         var cdg = midS(cf, i, 1);
150         if (isdiv(i, 2) != bl) {
151             cdg *= 2;
152             if (cdg > 9) {
153                 cdg -= 9;
154             }
155         }
156         ctd += cdg * 1.0;
157     }
158     if (isdiv(ctd, 10)) {
159         r = true;
160     }
161     return r;
162 }
163 
164 function mkCClist() {
165     tw = 2;
166     c = new makeArray(tw);
167     cd = new makeArray(tw);
168     var i = 1;
169     c[i] = "622202360547xxxxxxx";
170     cd[i] = "工商银行";
171     i++;
172     c[i] = "622617310xxxxxxx";
173     cd[i] = "民生银行";
174     i++;
175 }
176 
177 // Powered by MilkieX - http://www.ElfQrin.com
178 function leftS(aS, n) {
179     aS += "";
180     var rS = "";
181     if (n >= 1) {
182         rS = aS.substring(0, n);
183     }
184     return rS;
185 }
186 
187 function rightS(aS, n) {
188     aS += "";
189     var rS = "";
190     if (n >= 1) {
191         rS = aS.substring(aS.length - n, aS.length);
192     }
193     return rS;
194 }
195 
196 function midS(aS, n, n2) {
197     aS += "";
198     var rS = "";
199     if (n2 == null || n2 == "") {
200         n2 = aS.length;
201     }
202     n *= 1;
203     n2 *= 1;
204     if (n < 0) {
205         n++;
206     }
207     rS = aS.substring(n - 1, n - 1 + n2);
208     return rS;
209 }
210 
211 function linstr(aS, bS) {
212     aS += "";
213     bS += "";
214     var r = false;
215     if (leftS(aS, bS.length) == bS) {
216         r = true;
217     }
218     return r;
219 }
220 
221 function sbtString(s1, s2) {
222     var ous = "";
223     s1 += "";
224     s2 += "";
225     for (var i = 1; i <= s1.length; i++) {
226         var c1 = s1.substring(i - 1, i);
227         var c2 = s2.indexOf(c1);
228         if (c2 == -1) {
229             ous += c1;
230         }
231     }
232     return ous;
233 }
234 
235 
236 function sbtStringSpRnd(s1, s2, bS) {
237     if (bS == null || bS == "") {
238         bS = "0123456789";
239     }
240     var ous = "";
241     bS += "";
242     for (var i = 1; i <= s1.length; i++) {
243         var c1 = s1.substring(i - 1, i);//从头开始截取参数1
244         var c2 = s2.indexOf(c1);//从参数一中截取的字符在参数二中的位置
245         if (c2 == -1) {
246             ous += c1;//如果参数二中没有参数1中截取的字符则将该字符存入ous,否则存入mids(‘0123456789‘,random(1,9),1)
247             //mids取参数1的第参数二位到参数二加参数三位,这他妈不就是0-9随便取一个数吗?
248         } else {
249             ous += midS(bS, Math.floor(Math.random() * (bS.length - 1)) + 1, 1);
250         }
251     }
252     return ous;
253 }
254 
255 function cmpPattern(a, p, x) {
256     if (x == "" || x == null) {
257         x = "x";
258     }
259     x = "" + x.substring(0, 1);
260     a += "";
261     p += "";
262     r = false;
263     mc = 0;
264     if (a.length == p.length) {
265         for (var i = 1; i <= a.length; i++) {
266             a1 = midS(a, i, 1);
267             p1 = midS(p, i, 1);
268             if (a1 == p1 || p1 == x) {
269                 mc++;
270             }
271         }
272     }
273     if (mc == a.length) {
274         r = true;
275     }
276     return r;
277 }
278 
279 function isdiv(a, b) {
280     if (b == null) {
281         b = 2;
282     }
283     a *= 1.0;
284     b *= 1.0;
285     var r = false;
286     if (a / b == Math.floor(a / b)) {
287         r = true;
288     }
289     return r;
290 }
291 
292 function sumDigits(n, m) {
293     if (m == 0 || m == null) {
294         m = 1;
295     }
296     n += "";
297     if (m > 0) {
298         while (n.length > m) {
299             var r = 0;
300             for (var i = 1; i <= n.length; i++) {
301                 r += 1.0 * midS(n, i, 1);
302             }
303             n = "" + r;
304         }
305     } else {
306         for (var j = 1; j <= Math.abs(m); j++) {
307             var r = 0;
308             for (var i = 1; i <= n.length; i++) {
309                 r += 1.0 * midS(n, i, 1);
310             }
311             n = "" + r;
312         }
313     }
314     r = n;
315     return r;
316 }
317 
318 function makeArray(n) {
319     this.length = n;
320     for (var i = 1; i <= n; i++) {
321         this[i] = 0;
322     }
323     return this;
324 }
325 
326 // End of MilkieX
327 //var dl=""+document.location; dl=dl.toLowerCase(); if (dl.substring(0,22)!="http://www.elfqrin.com" && dl.substring(0,16)!="file:///c|/data/") {window.location="/";}
328 init();
329 
330 ccngen("622617310xxxxxxx","1000");

 

以上是关于bank_card.js的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段——声明函数