+/**
+ * Convert base 16 to base 64
+ * @returns A string based on 64 characters (0-9, a-z, A-Z, "-" and "_")
+ */
+function
+base_16_to_64 ($num)
+{
+ $o = '';
+ $m = implode ('', array_merge (range (0,9),
+ range ('a', 'z'),
+ range ('A', 'Z'),
+ ['-', '_']));
+ $i = 0;
+ $size = strlen ($num);
+ $b='';
+ for ($i = 0; $i < $size; $i++)
+ $b .= base_convert ($num{$i}, 16, 2);
+ $size = strlen ($b);
+ for ($i = $size - 6; $i >= 0; $i -= 6)
+ $o = $m{bindec (substr ($b, $i, 6))} . $o;
+ if ($i < 0 && $i > -6)
+ $o = $m{bindec (substr ($b, 0, $i + 6))} . $o;
+ return $o;
+}
+