Skip to content

Instantly share code, notes, and snippets.

@zbskii
Created September 19, 2012 00:52
Show Gist options
  • Save zbskii/3746994 to your computer and use it in GitHub Desktop.
Save zbskii/3746994 to your computer and use it in GitHub Desktop.
function encode64($input, $count)
{
$output = '';
$i = 0;
do {
$value = ord($input[$i++]);
$output .= $this->itoa64[$value & 0x3f]; // % 64
if ($i < $count)
$value |= ord($input[$i]) << 8; // ord * 2^8
$output .= $this->itoa64[($value >> 6) & 0x3f]; // (ord div 64) % 64
if ($i++ >= $count)
break;
if ($i < $count)
$value |= ord($input[$i]) << 16;
$output .= $this->itoa64[($value >> 12) & 0x3f];
if ($i++ >= $count)
break;
$output .= $this->itoa64[($value >> 18) & 0x3f];
} while ($i < $count);
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment