Advertisement
Guest User

ZTE Blade Unlock HTML/JavaScript

a guest
May 25th, 2011
1,287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.  
  3. /* ZTE Blade unlock code generator */
  4.  
  5. function calculate_unlock_code(imei)
  6. {
  7.         /* Check IMEI */
  8.         if(imei.length != 15) return "Invalid IMEI length";
  9.         var check = 0;
  10.         for(var i = 0; i < 15; i++) {
  11.           if(imei[i] < '0' || imei[i] > '9') return "Invalid IMEI character";
  12.           if(i % 2 == 0) {
  13.             check += imei.charCodeAt(i) - 48;
  14.           } else {
  15.             var temp = imei.charCodeAt(i) - 48;
  16.             temp *= 2;
  17.             check += temp % 10;
  18.             check += Math.floor(temp / 10);
  19.           }
  20.         }
  21.         if((check % 10) != 0) return "Invalid IMEI checksum";
  22.  
  23.  
  24.         /* Get binary md5 hash of IMEI number */
  25.         var imeiMD5 = rstr_md5(imei);
  26.         var unlockCode = "";
  27.         for(var i = 0; i < 8; i++) {
  28.                 var magicalSum = (imeiMD5.charCodeAt(i) + imeiMD5.charCodeAt(i + 8)) & 0xff; // Get last byte of two md5 byte sum
  29.                 unlockCode += String.fromCharCode((magicalSum * 9) / 255 + 48); // We need to add 48 ('0') here to get readable digit in ASCII
  30.         }
  31.  
  32.         return unlockCode;
  33. }
  34.  
  35.  
  36.  
  37. /*
  38.  * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  39.  * Digest Algorithm, as defined in RFC 1321.
  40.  * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
  41.  * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  42.  * Distributed under the BSD License
  43.  * See http://pajhome.org.uk/crypt/md5 for more info.
  44.  */
  45.  
  46. /*
  47.  * Configurable variables. You may need to tweak these to be compatible with
  48.  * the server-side, but the defaults work in most cases.
  49.  */
  50. var hexcase = 0;   /* hex output format. 0 - lowercase; 1 - uppercase        */
  51. var b64pad  = "";  /* base-64 pad character. "=" for strict RFC compliance   */
  52.  
  53. /*
  54.  * These are the functions you'll usually want to call
  55.  * They take string arguments and return either hex or base-64 encoded strings
  56.  */
  57. function hex_md5(s)    { return rstr2hex(rstr_md5(str2rstr_utf8(s))); }
  58. function b64_md5(s)    { return rstr2b64(rstr_md5(str2rstr_utf8(s))); }
  59. function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); }
  60. function hex_hmac_md5(k, d)
  61.   { return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }
  62. function b64_hmac_md5(k, d)
  63.   { return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }
  64. function any_hmac_md5(k, d, e)
  65.   { return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
  66.  
  67. /*
  68.  * Perform a simple self-test to see if the VM is working
  69.  */
  70. function md5_vm_test()
  71. {
  72.   return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
  73. }
  74.  
  75. /*
  76.  * Calculate the MD5 of a raw string
  77.  */
  78. function rstr_md5(s)
  79. {
  80.   return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
  81. }
  82.  
  83. /*
  84.  * Calculate the HMAC-MD5, of a key and some data (raw strings)
  85.  */
  86. function rstr_hmac_md5(key, data)
  87. {
  88.   var bkey = rstr2binl(key);
  89.   if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);
  90.  
  91.   var ipad = Array(16), opad = Array(16);
  92.   for(var i = 0; i < 16; i++)
  93.   {
  94.     ipad[i] = bkey[i] ^ 0x36363636;
  95.     opad[i] = bkey[i] ^ 0x5C5C5C5C;
  96.   }
  97.  
  98.   var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
  99.   return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
  100. }
  101.  
  102. /*
  103.  * Convert a raw string to a hex string
  104.  */
  105. function rstr2hex(input)
  106. {
  107.   try { hexcase } catch(e) { hexcase=0; }
  108.   var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  109.   var output = "";
  110.   var x;
  111.   for(var i = 0; i < input.length; i++)
  112.   {
  113.     x = input.charCodeAt(i);
  114.     output += hex_tab.charAt((x >>> 4) & 0x0F)
  115.            +  hex_tab.charAt( x        & 0x0F);
  116.   }
  117.   return output;
  118. }
  119.  
  120. /*
  121.  * Convert a raw string to a base-64 string
  122.  */
  123. function rstr2b64(input)
  124. {
  125.   try { b64pad } catch(e) { b64pad=''; }
  126.   var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  127.   var output = "";
  128.   var len = input.length;
  129.   for(var i = 0; i < len; i += 3)
  130.   {
  131.     var triplet = (input.charCodeAt(i) << 16)
  132.                 | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
  133.                 | (i + 2 < len ? input.charCodeAt(i+2)      : 0);
  134.     for(var j = 0; j < 4; j++)
  135.     {
  136.       if(i * 8 + j * 6 > input.length * 8) output += b64pad;
  137.       else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
  138.     }
  139.   }
  140.   return output;
  141. }
  142.  
  143. /*
  144.  * Convert a raw string to an arbitrary string encoding
  145.  */
  146. function rstr2any(input, encoding)
  147. {
  148.   var divisor = encoding.length;
  149.   var i, j, q, x, quotient;
  150.  
  151.   /* Convert to an array of 16-bit big-endian values, forming the dividend */
  152.   var dividend = Array(Math.ceil(input.length / 2));
  153.   for(i = 0; i < dividend.length; i++)
  154.   {
  155.     dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
  156.   }
  157.  
  158.   /*
  159.    * Repeatedly perform a long division. The binary array forms the dividend,
  160.    * the length of the encoding is the divisor. Once computed, the quotient
  161.    * forms the dividend for the next step. All remainders are stored for later
  162.    * use.
  163.    */
  164.   var full_length = Math.ceil(input.length * 8 /
  165.                                     (Math.log(encoding.length) / Math.log(2)));
  166.   var remainders = Array(full_length);
  167.   for(j = 0; j < full_length; j++)
  168.   {
  169.     quotient = Array();
  170.     x = 0;
  171.     for(i = 0; i < dividend.length; i++)
  172.     {
  173.       x = (x << 16) + dividend[i];
  174.       q = Math.floor(x / divisor);
  175.       x -= q * divisor;
  176.       if(quotient.length > 0 || q > 0)
  177.         quotient[quotient.length] = q;
  178.     }
  179.     remainders[j] = x;
  180.     dividend = quotient;
  181.   }
  182.  
  183.   /* Convert the remainders to the output string */
  184.   var output = "";
  185.   for(i = remainders.length - 1; i >= 0; i--)
  186.     output += encoding.charAt(remainders[i]);
  187.  
  188.   return output;
  189. }
  190.  
  191. /*
  192.  * Encode a string as utf-8.
  193.  * For efficiency, this assumes the input is valid utf-16.
  194.  */
  195. function str2rstr_utf8(input)
  196. {
  197.   var output = "";
  198.   var i = -1;
  199.   var x, y;
  200.  
  201.   while(++i < input.length)
  202.   {
  203.     /* Decode utf-16 surrogate pairs */
  204.     x = input.charCodeAt(i);
  205.     y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
  206.     if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
  207.     {
  208.       x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
  209.       i++;
  210.     }
  211.  
  212.     /* Encode output as utf-8 */
  213.     if(x <= 0x7F)
  214.       output += String.fromCharCode(x);
  215.     else if(x <= 0x7FF)
  216.       output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
  217.                                     0x80 | ( x         & 0x3F));
  218.     else if(x <= 0xFFFF)
  219.       output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
  220.                                     0x80 | ((x >>> 6 ) & 0x3F),
  221.                                     0x80 | ( x         & 0x3F));
  222.     else if(x <= 0x1FFFFF)
  223.       output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
  224.                                     0x80 | ((x >>> 12) & 0x3F),
  225.                                     0x80 | ((x >>> 6 ) & 0x3F),
  226.                                     0x80 | ( x         & 0x3F));
  227.   }
  228.   return output;
  229. }
  230.  
  231. /*
  232.  * Encode a string as utf-16
  233.  */
  234. function str2rstr_utf16le(input)
  235. {
  236.   var output = "";
  237.   for(var i = 0; i < input.length; i++)
  238.     output += String.fromCharCode( input.charCodeAt(i)        & 0xFF,
  239.                                   (input.charCodeAt(i) >>> 8) & 0xFF);
  240.   return output;
  241. }
  242.  
  243. function str2rstr_utf16be(input)
  244. {
  245.   var output = "";
  246.   for(var i = 0; i < input.length; i++)
  247.     output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
  248.                                    input.charCodeAt(i)        & 0xFF);
  249.   return output;
  250. }
  251.  
  252. /*
  253.  * Convert a raw string to an array of little-endian words
  254.  * Characters >255 have their high-byte silently ignored.
  255.  */
  256. function rstr2binl(input)
  257. {
  258.   var output = Array(input.length >> 2);
  259.   for(var i = 0; i < output.length; i++)
  260.     output[i] = 0;
  261.   for(var i = 0; i < input.length * 8; i += 8)
  262.     output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
  263.   return output;
  264. }
  265.  
  266. /*
  267.  * Convert an array of little-endian words to a string
  268.  */
  269. function binl2rstr(input)
  270. {
  271.   var output = "";
  272.   for(var i = 0; i < input.length * 32; i += 8)
  273.     output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
  274.   return output;
  275. }
  276.  
  277. /*
  278.  * Calculate the MD5 of an array of little-endian words, and a bit length.
  279.  */
  280. function binl_md5(x, len)
  281. {
  282.   /* append padding */
  283.   x[len >> 5] |= 0x80 << ((len) % 32);
  284.   x[(((len + 64) >>> 9) << 4) + 14] = len;
  285.  
  286.   var a =  1732584193;
  287.   var b = -271733879;
  288.   var c = -1732584194;
  289.   var d =  271733878;
  290.  
  291.   for(var i = 0; i < x.length; i += 16)
  292.   {
  293.     var olda = a;
  294.     var oldb = b;
  295.     var oldc = c;
  296.     var oldd = d;
  297.  
  298.     a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  299.     d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  300.     c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
  301.     b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  302.     a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  303.     d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
  304.     c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  305.     b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  306.     a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
  307.     d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  308.     c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  309.     b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  310.     a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
  311.     d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  312.     c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  313.     b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);
  314.  
  315.     a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  316.     d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  317.     c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
  318.     b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  319.     a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  320.     d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
  321.     c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  322.     b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  323.     a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
  324.     d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  325.     c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  326.     b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
  327.     a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  328.     d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  329.     c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
  330.     b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  331.  
  332.     a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  333.     d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  334.     c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
  335.     b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  336.     a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  337.     d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
  338.     c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  339.     b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  340.     a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
  341.     d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  342.     c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  343.     b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
  344.     a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  345.     d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  346.     c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
  347.     b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  348.  
  349.     a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  350.     d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
  351.     c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  352.     b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  353.     a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
  354.     d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  355.     c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  356.     b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  357.     a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
  358.     d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  359.     c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  360.     b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
  361.     a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  362.     d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  363.     c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
  364.     b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  365.  
  366.     a = safe_add(a, olda);
  367.     b = safe_add(b, oldb);
  368.     c = safe_add(c, oldc);
  369.     d = safe_add(d, oldd);
  370.   }
  371.   return Array(a, b, c, d);
  372. }
  373.  
  374. /*
  375.  * These functions implement the four basic operations the algorithm uses.
  376.  */
  377. function md5_cmn(q, a, b, x, s, t)
  378. {
  379.   return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  380. }
  381. function md5_ff(a, b, c, d, x, s, t)
  382. {
  383.   return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  384. }
  385. function md5_gg(a, b, c, d, x, s, t)
  386. {
  387.   return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  388. }
  389. function md5_hh(a, b, c, d, x, s, t)
  390. {
  391.   return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  392. }
  393. function md5_ii(a, b, c, d, x, s, t)
  394. {
  395.   return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  396. }
  397.  
  398. /*
  399.  * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  400.  * to work around bugs in some JS interpreters.
  401.  */
  402. function safe_add(x, y)
  403. {
  404.   var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  405.   var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  406.   return (msw << 16) | (lsw & 0xFFFF);
  407. }
  408.  
  409. /*
  410.  * Bitwise rotate a 32-bit number to the left.
  411.  */
  412. function bit_rol(num, cnt)
  413. {
  414.   return (num << cnt) | (num >>> (32 - cnt));
  415. }
  416.  
  417. </script>
  418.  
  419. <table>
  420.   <tr><th>IMEI</th><td><input type="text" id="input" size="40"></td></tr>
  421.   <tr><th>&nbsp;</th>
  422.   <td style="text-align:center">
  423.   <input type="button" onclick="document.getElementById('hash').value = calculate_unlock_code(document.getElementById('input').value)" value="Generate Code"></td></tr>
  424.   <tr><th>NCK</th><td><input type="text" id="hash" size="40"></td></tr>
  425. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement