Skip to content

Instantly share code, notes, and snippets.

@ladaposamuel
Last active October 26, 2017 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ladaposamuel/50bd94569accf24128aa7d35d7275c7a to your computer and use it in GitHub Desktop.
Save ladaposamuel/50bd94569accf24128aa7d35d7275c7a to your computer and use it in GitHub Desktop.
decodeBase58.php
function decodeBase58($input) {
$alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
$out = array_fill(0, 25, 0);
for($i=0;$i<strlen($input);$i++){
if(($p=strpos($alphabet, $input[$i]))===false){
return false;
}
$c = $p;
for ($j = 25; $j--; ) {
$c += (int)(58 * $out[$j]);
$out[$j] = (int)($c % 256);
$c /= 256;
$c = (int)$c;
}
if($c != 0){
return false;
}
}
$result = "";
foreach($out as $val){
$result .= chr($val);
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment