Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 128.6k

function for Base64Decode unable to decode the character €

May 20 2019 8:27 AM
UTF8 Decode for € not working with the below method.
 
What changes needed to decode in UTF8 For Euro symbol (€). I have tried the escape method before decodeuricomponent. what changes need in the method with out use of escape???
  1. var Base64Decode = function (encoded, escapeChar) {    
  2.     try {    
  3.         var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";//èéêëàâùìîçò";    
  4.         var output = "";    
  5.         var chr1, chr2, chr3;    
  6.         var enc1, enc2, enc3, enc4;    
  7.         var i = 0;    
  8.     
  9.         do {    
  10.             enc1 = keyStr.indexOf(encoded.charAt(i++));    
  11.             enc2 = keyStr.indexOf(encoded.charAt(i++));    
  12.             enc3 = keyStr.indexOf(encoded.charAt(i++));    
  13.             enc4 = keyStr.indexOf(encoded.charAt(i++));    
  14.     
  15.             chr1 = (enc1 << 2) | (enc2 >> 4);    
  16.             chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);    
  17.             chr3 = ((enc3 & 3) << 6) | enc4;    
  18.     
  19.             output = output + String.fromCharCode(chr1);    
  20.     
  21.             if (enc3 != 64) {    
  22.                 output = output + String.fromCharCode(chr2);    
  23.             }    
  24.             if (enc4 != 64) {    
  25.                 output = output + String.fromCharCode(chr3);    
  26.             }    
  27.         } while (i < encoded.length);    
  28.     
  29.         if (escapeChar == undefined) {                    
  30.             return decodeURIComponent(output);    
  31.         }    
  32.         else {    
  33.             return output;    
  34.         }    
  35.     
  36.     } catch (ex) {    
  37.     }    
  38. };   
The output comes like â¬