Skip to content

Instantly share code, notes, and snippets.

@shogo82148
Created September 24, 2012 13:10
Show Gist options
  • Save shogo82148/3775879 to your computer and use it in GitHub Desktop.
Save shogo82148/3775879 to your computer and use it in GitHub Desktop.
Base64エンコーダ
function base64(input) {
var i, length = input.length;
var x, y, z;
var s = '';
var table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
for(i = 0; i < length; i += 3) {
x = input[i];
y = i + 1 < length ? input[i+1] : 0;
z = i + 2 < length ? input[i+2] : 0;
s += table.charAt(x >> 2) +
table.charAt(((x&0x03) << 4) | (y >> 4)) +
(i + 1 < length ? table.charAt(((y&0x0F) << 2) | (z >> 6)) : '=') +
(i + 2 < length ? table.charAt(z & 0x3F) : '=');
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment