-
-
Save ladaposamuel/50bd94569accf24128aa7d35d7275c7a to your computer and use it in GitHub Desktop.
decodeBase58.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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