0

I have a 40 character long SHA1 value that is stored in an indexed column in a InnoDB table. To shorten the index I want it to be "compressed" without increasing the risk for a collision.

<?php

$a = "875e5d6959da75400c837a79ecca23d79b40e7a5";

$b = base_convert($a, 16, 36);

echo $b; // ft92zicmcfks08088wk0oow44oso8gk

?>

It this solution ok? And why can't I convert to base64, it gives me the following warning:

Warning: base_convert(): Invalid "to base" (64) in...

Ravi
  • 30,829
  • 42
  • 119
  • 173
Julius S.
  • 664
  • 9
  • 21
  • Oh "Base64" encoding is not like the "base 10" we say when we mean decimal and "base 16" for hex or "base 2" for binary. Those kind of bases generally only go from 2 to 36 in most programming languages. – Ray Toal Dec 30 '17 at 09:00
  • Ok, I removed the additional topic. – Julius S. Dec 30 '17 at 09:14

1 Answers1

1

Because as per manual of base_convert

... tobase have to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35. The case of the letters doesn't matter, i.e. number is interpreted case-insensitively.

Ravi
  • 30,829
  • 42
  • 119
  • 173