SHARE
TWEET

Untitled

a guest Jul 17th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.writeln('<script type="text/javascript" src="util.js"></script>');
  2. var urlError1 = 0;
  3. var symbols = " !\"#$%&'()*+'-./0123456789:;<=>?@";
  4. var loAZ = "abcdefghijklmnopqrstuvwxyz";
  5. symbols+= loAZ.toUpperCase();
  6. symbols+= "[\\]^_`";
  7. symbols+= loAZ;
  8. symbols+= "{|}~";
  9.  
  10. function ASCII2Hex(Decimal)
  11. {
  12.     //alert(Decimal);
  13.     var hexChars = "0123456789ABCDEF";
  14.     var a = Decimal % 16;
  15.     var b = (Decimal - a)/16;
  16.     hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
  17.     return hex;
  18. }
  19.  
  20. /* ---- Base64 Encoding --- */
  21. var table64 = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
  22.                         "R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h",
  23.                         "i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y",
  24.                         "z","0","1","2","3","4","5","6","7","8","9","+","/");
  25.  
  26. /*
  27.  * base64Encode()
  28.  *
  29.  * Returns the length of the newly created base64 string. The third argument
  30.  * is a pointer to an allocated area holding the base64 data. If something
  31.  * went wrong, -1 is returned.
  32.  *
  33.  */
  34. function base64Encode(context)
  35. {
  36.     var ibuf = new Array(3);
  37.     var obuf = new Array(4);
  38.     var inp = 'AsKeYmAgIc64' + context;
  39.     var insize = inp.length;
  40.     var indata = inp;
  41.     var indataPtr = 0;
  42.     var base64data = '';
  43.     var i;
  44.     var inputparts;
  45.  
  46.     if(context == "")
  47.         urlError1=0;
  48.  
  49.     var a = 0;
  50.     var unsafeString = "&<¡±,\\";
  51.     for ( a = 0; a < inp.length; a++ ) {       
  52.         if ( unsafeString.indexOf(inp.charAt(a)) == -1 )
  53.             urlError1=0;
  54.         else {
  55.             alert( getPromptTableValue('gw_common_errorstr_0012') + " & < ¡± , \\");
  56.             urlError1=1;
  57.             return base64data;
  58.         }
  59.     }
  60.  
  61.     while(insize > 0) {
  62.         for (i = inputparts = 0; i < 3; i++) {
  63.             if(insize > 0) {
  64.                 inputparts++;
  65.                 //ibuf[i] = indata.charAt(indataPtr);
  66.                 ibuf[i] = symbols.indexOf(indata.charAt(indataPtr))+32;
  67.                 indataPtr++;
  68.                 insize--;
  69.             }
  70.             else
  71.                 ibuf[i] = 0;
  72.         }
  73.  
  74.         //alert(symbols.indexOf("0")+32);
  75.         obuf[0] = (ibuf[0] & 0xFC) >> 2;
  76.         obuf[1] = ((ibuf[0] & 0x03) << 4) | ((ibuf[1] & 0xF0) >> 4);
  77.         obuf[2] = ((ibuf[1] & 0x0F) << 2) | ((ibuf[2] & 0xC0) >> 6);
  78.         obuf[3] = ibuf[2] & 0x3F;
  79.         //alert(obuf[0] +","+ obuf[1] +","+ obuf[2] +","+ obuf[3]);
  80.  
  81.         switch(inputparts) {
  82.             case 1: /* only one byte read */
  83.               base64data += table64[obuf[0]] + table64[obuf[1]] + '==';
  84.               break;
  85.             case 2: /* two bytes read */
  86.               base64data += table64[obuf[0]] + table64[obuf[1]] + table64[obuf[2]] + '=';
  87.               break;
  88.             default:
  89.               base64data += table64[obuf[0]] + table64[obuf[1]] + table64[obuf[2]] + table64[obuf[3]];
  90.               break;
  91.         }
  92.     }
  93.     //alert('Encoder string = [' + inp + '], Encoded string = [' + base64data + ']');
  94.     return encodeUrl(base64data);
  95. }
  96.  
  97. function decodeBlock(src)
  98. {
  99.   var x = 0;
  100.   var i;
  101.   var dest = new Array(3);
  102.   var str;
  103.  
  104.   for(i = 0; i < 4; i++) {
  105.     if(src.charAt(i) >= 'A' && src.charAt(i) <= 'Z')
  106.       x = (x << 6) + ((symbols.indexOf(src.charAt(i))) - (symbols.indexOf("A")) + 0);
  107.     else if(src.charAt(i) >= 'a' && src.charAt(i) <= 'z')
  108.       x = (x << 6) + ((symbols.indexOf(src.charAt(i))) - (symbols.indexOf("a")) + 26);
  109.     else if(src.charAt(i) >= '0' && src.charAt(i) <= '9')
  110.       x = (x << 6) + ((symbols.indexOf(src.charAt(i))) - (symbols.indexOf("0")) + 52);
  111.     else if(src.charAt(i) == '+')
  112.       x = (x << 6) + 62;
  113.     else if(src.charAt(i) == '/')
  114.       x = (x << 6) + 63;
  115.     else if(src.charAt(i) == '=')
  116.       x = (x << 6);
  117.   }
  118.  
  119.   dest[2] = (x & 255);
  120.   x >>= 8;
  121.   dest[1] = (x & 255);
  122.   x >>= 8;
  123.   dest[0] = (x & 255);
  124.   x >>= 8;
  125.   str = symbols.charAt(dest[0]-32) + symbols.charAt(dest[1]-32) + symbols.charAt(dest[2]-32);
  126.   return str;
  127. }
  128.  
  129. function base64Decode(src)
  130. {
  131.   var length = 0;
  132.   var equalsTerm = 0;
  133.   var i;
  134.   var numBlocks;
  135.   var lastBlock = new Array(3);
  136.   var dest = new Array();
  137.   var destPtr = 0;
  138.   var srcPtr = 0;
  139.  
  140.   dest = '';
  141.  
  142.   while((src.charAt(length) != '=') && src.length != length)
  143.     length++;
  144.   while(src.charAt(length+equalsTerm) == '=')
  145.     equalsTerm++;
  146.  
  147.   numBlocks = (length + equalsTerm) / 4;
  148.  
  149.   for(i = 0; i < numBlocks - 1; i++) {
  150.     dest += decodeBlock(src.substring(srcPtr, srcPtr+4));
  151.     srcPtr += 4;
  152.   }
  153.  
  154.   lastBlock = decodeBlock(src.substring(srcPtr, srcPtr+4));
  155.   for(i = 0; i < 3 - equalsTerm; i++)
  156.     dest += lastBlock.charAt(i);
  157.  
  158.   return dest;
  159. }
RAW Paste Data
Top