diff options
author | erdgeist <> | 2008-06-11 17:02:12 +0000 |
---|---|---|
committer | erdgeist <> | 2008-06-11 17:02:12 +0000 |
commit | 69e14b3ab269cd1dd853ed31f5a5bbca8982381b (patch) | |
tree | 1776d8921aba87696f8e6da233a2abe9ce1cdbb9 /encoding.js | |
parent | 86bf4cac3b64b4e7c146f95e207cce4044befcf0 (diff) |
Simplify base64 decoding
Diffstat (limited to 'encoding.js')
-rw-r--r-- | encoding.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/encoding.js b/encoding.js index 52265de..6c641df 100644 --- a/encoding.js +++ b/encoding.js | |||
@@ -118,12 +118,12 @@ function decode_quotedprintable( str ) { | |||
118 | } | 118 | } |
119 | 119 | ||
120 | function dec(x) { | 120 | function dec(x) { |
121 | if (x>='A' && x<='Z') return ( x.charCodeAt(0) & 0xff ) - 65; | 121 | if (x>=65 && x<=90 ) return x - 65; |
122 | if (x>='a' && x<='z') return ( x.charCodeAt(0) & 0xff ) - 97 + 26; | 122 | if (x>=97 && x<=122) return x - 97 + 26; |
123 | if (x>='0' && x<='9') return ( x.charCodeAt(0) & 0xff ) - 48 + 26 + 26; | 123 | if (x>=48 && x<=57 ) return x - 48 + 26 + 26; |
124 | switch (x) { | 124 | switch (x) { |
125 | case '+': return 62; | 125 | case 43: return 62; |
126 | case '/': return 63; | 126 | case 47: return 63; |
127 | default: return -1; | 127 | default: return -1; |
128 | } | 128 | } |
129 | } | 129 | } |
@@ -133,7 +133,8 @@ function decode_base64( str ) { | |||
133 | var outstring = ""; | 133 | var outstring = ""; |
134 | 134 | ||
135 | for( var i=0; i<str.length; ++i) { | 135 | for( var i=0; i<str.length; ++i) { |
136 | var a=dec(str[i]); | 136 | var x = str.charCodeAt(i); |
137 | var a = dec( x & 0xff ); | ||
137 | if(a<0) { | 138 | if(a<0) { |
138 | return outstring; | 139 | return outstring; |
139 | } | 140 | } |