home *** CD-ROM | disk | FTP | other *** search
- /*** http://www.webtoolkit.info/javascript-base64.html***/
- var PhProxy_Base64 = {
- // private property
- _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
-
- _modifications_before_decode_for_phproxy : function (input) {
- try {
- var temp = decodeURIComponent(decodeURIComponent(input));
- } catch(e) {
- temp = input;
- }
- //Remove beginning; http://www.libanonchat.org/proxy/index.php?q=aHR0cDovL3d3dy5nb29nbGUuY29tL3dlYmhwP2dsPXVz--&hl=2e9 >> aHR0cDovL3d3dy5nb29nbGUuY29tL3dlYmhwP2dsPXVz--&hl=2e9
- try {
- temp = (/\?q=.*/.exec(temp) || /\?____pgfa=.*/.exec(temp) || "").toString()
- .replace(/\?q=/, "").replace(/\?____pgfa=/, "");
- } catch (e) {
- //This case only happens on phproxy server example: http://www.libanonchat.org/proxy/
- temp = "";
- }
- //Remove end; aHR0cDovL3d3dy5nb29nbGUuY29tL3dlYmhwP2dsPXVz--&hl=2e9 >> aHR0cDovL3d3dy5nb29nbGUuY29tL3dlYmhwP2dsPXVz
- var extra = (/-*&hl.*/.exec(temp) || "").toString();
- extra = extra.replace(/-+&hl=.*/,"").replace(/^\&/, "?"); //Modify extra
- temp = unescape(temp).replace(/-*&hl.*/,"");
-
- return [temp, extra];
- },
- _modifications_before_decode_general : function (input) {
- //Remove rest of non-Base64 chars
- return input.replace(/[^A-Za-z0-9\+\/\=].*/, "");
- },
- // public method for encoding
- encode : function (input) {
- var output = "";
- var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
- var i = 0;
-
- input = PhProxy_Base64._utf8_encode(input);
-
- while (i < input.length) {
-
- chr1 = input.charCodeAt(i++);
- chr2 = input.charCodeAt(i++);
- chr3 = input.charCodeAt(i++);
-
- enc1 = chr1 >> 2;
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
- enc4 = chr3 & 63;
-
- if (isNaN(chr2)) {
- enc3 = enc4 = 64;
- } else if (isNaN(chr3)) {
- enc4 = 64;
- }
-
- output = output +
- this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
- this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
-
- }
-
- return output;
- },
-
- // public method for decoding
- decode : function (input, type) {
- var extra = "";
- if (type != "Glype")
- [input, extra] = this._modifications_before_decode_for_phproxy(input);
- input = this._modifications_before_decode_general(input);
- var output = "";
- var chr1, chr2, chr3;
- var enc1, enc2, enc3, enc4;
- var i = 0;
-
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
-
- while (i < input.length) {
-
- enc1 = this._keyStr.indexOf(input.charAt(i++));
- enc2 = this._keyStr.indexOf(input.charAt(i++));
- enc3 = this._keyStr.indexOf(input.charAt(i++));
- enc4 = this._keyStr.indexOf(input.charAt(i++));
-
- chr1 = (enc1 << 2) | (enc2 >> 4);
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
- chr3 = ((enc3 & 3) << 6) | enc4;
-
- output = output + String.fromCharCode(chr1);
-
- if (enc3 != 64) {
- output = output + String.fromCharCode(chr2);
- }
- if (enc4 != 64) {
- output = output + String.fromCharCode(chr3);
- }
-
- }
-
- output = PhProxy_Base64._utf8_decode(output);
-
- return output + extra;
-
- },
-
- // private method for UTF-8 encoding
- _utf8_encode : function (string) {
- string = string.replace(/\r\n/g,"\n");
- var utftext = "";
-
- for (var n = 0; n < string.length; n++) {
-
- var c = string.charCodeAt(n);
-
- if (c < 128) {
- utftext += String.fromCharCode(c);
- }
- else if((c > 127) && (c < 2048)) {
- utftext += String.fromCharCode((c >> 6) | 192);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- else {
- utftext += String.fromCharCode((c >> 12) | 224);
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
- utftext += String.fromCharCode((c & 63) | 128);
- }
-
- }
-
- return utftext;
- },
-
- // private method for UTF-8 decoding
- _utf8_decode : function (utftext) {
- var string = "";
- var i = 0;
- var c = c1 = c2 = 0;
-
- while ( i < utftext.length ) {
-
- c = utftext.charCodeAt(i);
-
- if (c < 128) {
- string += String.fromCharCode(c);
- i++;
- }
- else if((c > 191) && (c < 224)) {
- c2 = utftext.charCodeAt(i+1);
- string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
- i += 2;
- }
- else {
- c2 = utftext.charCodeAt(i+1);
- c3 = utftext.charCodeAt(i+2);
- string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- i += 3;
- }
-
- }
-
- return string;
- }
- }
- //Rotate13
- var PhProxy_Rot13 = {
- _rawurlencode : function (str) {
- return encodeURIComponent(str).replace(/!/g, '%21')
- .replace(/'/g, '%27').replace(/\(/g, '%28')
- .replace(/\)/g, '%29').replace(/\*/g, '%2A');
- },
-
- _rot13 : function (str) {
- return str.replace(/[a-zA-Z]/g, function(c){
- return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
- });
- },
-
- encode : function (input) {
- return this._rawurlencode(this._rot13(input));
- },
-
- decode : function (input) {
- [url, extra] = PhProxy_Base64._modifications_before_decode_for_phproxy (input)
-
- try {
- var temp = decodeURIComponent(decodeURIComponent(url));
- } catch(e) {
- temp = url;
- }
-
- var rm = extra.indexOf ("?hl=");
- if (rm != -1)
- extra = extra.substring(0, rm);
-
- return this._rot13(temp).replace('&', '&').replace('&', '&') + extra;
- }
- }
-
-
- // for glype
- var PhProxy_Glype_decode = {
- run : function(str){
- tSTR = "";
- for(i=0;i<str.length;){
- if(this.encodeURIbycharacter(str.substr(i,1))){
- tSTR += this.encodeURIbycharacter(str.substr(i,1));
- i++;
- }
- if(this.encodeURIbycharacter(str.substr(i,2))){
- tSTR += this.encodeURIbycharacter(str.substr(i,2));
- i+=2;
- }
- if(this.encodeURIbycharacter(str.substr(i,3))){
- tSTR += this.encodeURIbycharacter(str.substr(i,3));
- i+=3;
- }
- else{
- tSTR += str.substr(i,1);
- i++;
- }
- }
- return tSTR;
- },
-
- encodeURIbycharacter : function(ch) {
- if (ch == "+") { return "%20"; }
- if (ch == "%20") { return " "; }
- if (ch == "%21") { return "!"; }
- if (ch == "%23") { return "#"; }
- if (ch == "%24") { return "$"; }
- if (ch == "%26") { return "&"; }
- if (ch == "%27") { return "\""; }
- if (ch == "%28") { return "("; }
- if (ch == "%29") { return ")"; }
- if (ch == "%2A") { return "*"; }
- if (ch == "%2B") { return "+"; }
- if (ch == "%2C") { return ","; }
- if (ch == "%2F") { return "/"; }
- if (ch == "%3A") { return ":"; }
- if (ch == "%3B") { return ";"; }
- if (ch == "%3D") { return "="; }
- if (ch == "%3F") { return "?"; }
- if (ch == "%40") { return "@"; }
- if (ch == "%7E") { return "~"; }
- if (ch == "%80") { return "%E2%82%AC"; }
- if (ch == "%81") { return "%C2%81"; }
- if (ch == "%82") { return "%E2%80%9A"; }
- if (ch == "%83") { return "%C6%92"; }
- if (ch == "%84") { return "%E2%80%9E"; }
- if (ch == "%85") { return "%E2%80%A6"; }
- if (ch == "%86") { return "%E2%80%A0"; }
- if (ch == "%87") { return "%E2%80%A1"; }
- if (ch == "%88") { return "%CB%86"; }
- if (ch == "%89") { return "%E2%80%B0"; }
- if (ch == "%8A") { return "%C5%A0"; }
- if (ch == "%8B") { return "%E2%80%B9"; }
- if (ch == "%8C") { return "%C5%92"; }
- if (ch == "%8D") { return "%C2%8D"; }
- if (ch == "%8E") { return "%C5%BD"; }
- if (ch == "%8F") { return "%C2%8F"; }
- if (ch == "%90") { return "%C2%90"; }
- if (ch == "%91") { return "%E2%80%98"; }
- if (ch == "%92") { return "%E2%80%99"; }
- if (ch == "%93") { return "%E2%80%9C"; }
- if (ch == "%94") { return "%E2%80%9D"; }
- if (ch == "%95") { return "%E2%80%A2"; }
- if (ch == "%96") { return "%E2%80%93"; }
- if (ch == "%97") { return "%E2%80%94"; }
- if (ch == "%98") { return "%CB%9C"; }
- if (ch == "%99") { return "%E2%84%A2"; }
- if (ch == "%9A") { return "%C5%A1"; }
- if (ch == "%9B") { return "%E2%80%BA"; }
- if (ch == "%9C") { return "%C5%93"; }
- if (ch == "%9D") { return "%C2%9D"; }
- if (ch == "%9E") { return "%C5%BE"; }
- if (ch == "%9F") { return "%C5%B8"; }
- if (ch == "%A0") { return "%C2%A0"; }
- if (ch == "%A1") { return "%C2%A1"; }
- if (ch == "%A2") { return "%C2%A2"; }
- if (ch == "%A3") { return "%C2%A3"; }
- if (ch == "%A4") { return "%C2%A4"; }
- if (ch == "%A5") { return "%C2%A5"; }
- if (ch == "%A6") { return "%C2%A6"; }
- if (ch == "%A7") { return "%C2%A7"; }
- if (ch == "%A8") { return "%C2%A8"; }
- if (ch == "%A9") { return "%C2%A9"; }
- if (ch == "%AA") { return "%C2%AA"; }
- if (ch == "%AB") { return "%C2%AB"; }
- if (ch == "%AC") { return "%C2%AC"; }
- if (ch == "%AD") { return "%C2%AD"; }
- if (ch == "%AE") { return "%C2%AE"; }
- if (ch == "%AF") { return "%C2%AF"; }
- if (ch == "%B0") { return "%C2%B0"; }
- if (ch == "%B1") { return "%C2%B1"; }
- if (ch == "%B2") { return "%C2%B2"; }
- if (ch == "%B3") { return "%C2%B3"; }
- if (ch == "%B4") { return "%C2%B4"; }
- if (ch == "%B5") { return "%C2%B5"; }
- if (ch == "%B6") { return "%C2%B6"; }
- if (ch == "%B7") { return "%C2%B7"; }
- if (ch == "%B8") { return "%C2%B8"; }
- if (ch == "%B9") { return "%C2%B9"; }
- if (ch == "%BA") { return "%C2%BA"; }
- if (ch == "%BB") { return "%C2%BB"; }
- if (ch == "%BC") { return "%C2%BC"; }
- if (ch == "%BD") { return "%C2%BD"; }
- if (ch == "%BE") { return "%C2%BE"; }
- if (ch == "%BF") { return "%C2%BF"; }
- if (ch == "%C0") { return "%C3%80"; }
- if (ch == "%C1") { return "%C3%81"; }
- if (ch == "%C2") { return "%C3%82"; }
- if (ch == "%C3") { return "%C3%83"; }
- if (ch == "%C4") { return "%C3%84"; }
- if (ch == "%C5") { return "%C3%85"; }
- if (ch == "%C6") { return "%C3%86"; }
- if (ch == "%C7") { return "%C3%87"; }
- if (ch == "%C8") { return "%C3%88"; }
- if (ch == "%C9") { return "%C3%89"; }
- if (ch == "%CA") { return "%C3%8A"; }
- if (ch == "%CB") { return "%C3%8B"; }
- if (ch == "%CC") { return "%C3%8C"; }
- if (ch == "%CD") { return "%C3%8D"; }
- if (ch == "%CE") { return "%C3%8E"; }
- if (ch == "%CF") { return "%C3%8F"; }
- if (ch == "%D0") { return "%C3%90"; }
- if (ch == "%D1") { return "%C3%91"; }
- if (ch == "%D2") { return "%C3%92"; }
- if (ch == "%D3") { return "%C3%93"; }
- if (ch == "%D4") { return "%C3%94"; }
- if (ch == "%D5") { return "%C3%95"; }
- if (ch == "%D6") { return "%C3%96"; }
- if (ch == "%D7") { return "%C3%97"; }
- if (ch == "%D8") { return "%C3%98"; }
- if (ch == "%D9") { return "%C3%99"; }
- if (ch == "%DA") { return "%C3%9A"; }
- if (ch == "%DB") { return "%C3%9B"; }
- if (ch == "%DC") { return "%C3%9C"; }
- if (ch == "%DD") { return "%C3%9D"; }
- if (ch == "%DE") { return "%C3%9E"; }
- if (ch == "%DF") { return "%C3%9F"; }
- if (ch == "%E0") { return "%C3%A0"; }
- if (ch == "%E1") { return "%C3%A1"; }
- if (ch == "%E2") { return "%C3%A2"; }
- if (ch == "%E3") { return "%C3%A3"; }
- if (ch == "%E4") { return "%C3%A4"; }
- if (ch == "%E5") { return "%C3%A5"; }
- if (ch == "%E6") { return "%C3%A6"; }
- if (ch == "%E7") { return "%C3%A7"; }
- if (ch == "%E8") { return "%C3%A8"; }
- if (ch == "%E9") { return "%C3%A9"; }
- if (ch == "%EA") { return "%C3%AA"; }
- if (ch == "%EB") { return "%C3%AB"; }
- if (ch == "%EC") { return "%C3%AC"; }
- if (ch == "%ED") { return "%C3%AD"; }
- if (ch == "%EE") { return "%C3%AE"; }
- if (ch == "%EF") { return "%C3%AF"; }
- if (ch == "%F0") { return "%C3%B0"; }
- if (ch == "%F1") { return "%C3%B1"; }
- if (ch == "%F2") { return "%C3%B2"; }
- if (ch == "%F3") { return "%C3%B3"; }
- if (ch == "%F4") { return "%C3%B4"; }
- if (ch == "%F5") { return "%C3%B5"; }
- if (ch == "%F6") { return "%C3%B6"; }
- if (ch == "%F7") { return "%C3%B7"; }
- if (ch == "%F8") { return "%C3%B8"; }
- if (ch == "%F9") { return "%C3%B9"; }
- if (ch == "%FA") { return "%C3%BA"; }
- if (ch == "%FB") { return "%C3%BB"; }
- if (ch == "%FC") { return "%C3%BC"; }
- if (ch == "%FD") { return "%C3%BD"; }
- if (ch == "%FE") { return "%C3%BE"; }
- if (ch == "%FF") { return "%C3%BF"; }
- return "";
- }
- }