Menu

[r443]: / phprpc_3.0 / js / base64.js  Maximize  Restore  History

Download this file

148 lines (135 with data), 5.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| base64.js |
| |
| Release 3.0.0 |
| Copyright (c) 2005-2008 by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU Lesser General Public License (LGPL) |
| version 3.0 as published by the Free Software Foundation |
| and appearing in the included file LICENSE. |
| |
\**********************************************************/
/* Base64 library.
*
* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* 2005-2008 Ma Bingyao <andot@ujn.edu.cn>
* Version: 1.28
* LastModified: Mar 3, 2008
* This library is free. You can redistribute it and/or modify it.
*/
/*
* Interfaces:
* b64 = window.btoa(data);
* data = window.atob(b64);
*/
if (typeof(btoa) == "undefined") {
btoa = function() {
var base64EncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
return function(str) {
var out, i, j, len, r, l, c;
i = j = 0;
len = str.length;
r = len % 3;
len = len - r;
l = (len / 3) << 2;
if (r > 0) {
l += 4;
}
out = new Array(l);
while (i < len) {
c = str.charCodeAt(i++) << 16 |
str.charCodeAt(i++) << 8 |
str.charCodeAt(i++);
out[j++] = base64EncodeChars[c >> 18]
+ base64EncodeChars[c >> 12 & 0x3f]
+ base64EncodeChars[c >> 6 & 0x3f]
+ base64EncodeChars[c & 0x3f] ;
}
if (r == 1) {
c = str.charCodeAt(i++);
out[j++] = base64EncodeChars[c >> 2]
+ base64EncodeChars[(c & 0x03) << 4]
+ "==";
}
else if (r == 2) {
c = str.charCodeAt(i++) << 8 |
str.charCodeAt(i++);
out[j++] = base64EncodeChars[c >> 10]
+ base64EncodeChars[c >> 4 & 0x3f]
+ base64EncodeChars[(c & 0x0f) << 2]
+ "=";
}
return out.join('');
}
}();
}
if (typeof(atob) == "undefined") {
atob = function() {
var base64DecodeChars = [
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
];
return function(str) {
var c1, c2, c3, c4;
var i, j, len, r, l, out;
len = str.length;
if (len % 4 != 0) {
return '';
}
if (/[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\+\/\=]/.test(str)) {
return '';
}
if (str.charAt(len - 2) == '=') {
r = 1;
}
else if (str.charAt(len - 1) == '=') {
r = 2;
}
else {
r = 0;
}
l = len;
if (r > 0) {
l -= 4;
}
l = (l >> 2) * 3 + r;
out = new Array(l);
i = j = 0;
while (i < len) {
// c1
c1 = base64DecodeChars[str.charCodeAt(i++)];
if (c1 == -1) break;
// c2
c2 = base64DecodeChars[str.charCodeAt(i++)];
if (c2 == -1) break;
out[j++] = String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
// c3
c3 = base64DecodeChars[str.charCodeAt(i++)];
if (c3 == -1) break;
out[j++] = String.fromCharCode(((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2));
// c4
c4 = base64DecodeChars[str.charCodeAt(i++)];
if (c4 == -1) break;
out[j++] = String.fromCharCode(((c3 & 0x03) << 6) | c4);
}
return out.join('');
}
}();
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.