function validate($address){
        $decoded = decodeBase58($address);

        $d1 = hash(, substr($decoded,0,21), true);
        $d2 = hash(, $d1, true);

        if(substr_compare($decoded, $d2, 21, 4)){
                throw new \Exception();
        }
        return true;
}
function decodeBase58($input) {
        $alphabet = ;

        $out = array_fill(0, 25, 0);
        for($i=0;$i<strlen($input);$i++){
                if(($p=strpos($alphabet, $input[$i]))===false){
                        throw new \Exception();
                }
                $c = $p;
                for ($j = 25; $j--; ) {
                        $c += (int)(58 * $out[$j]);
                        $out[$j] = (int)($c % 256);
                        $c /= 256;
                        $c = (int)$c;
                }
                if($c != 0){
                    throw new \Exception();
                }
        }

        $result = ;
        foreach($out as $val){
                $result .= chr($val);
        }

        return $result;
}

function main () {
  $s = array(
                ,
                ,
                ,
                ,
        );
  foreach($s as $btc){
    $message = ;
    try{
        validate($btc);
    }catch(\Exception $e){ $message = $e->getMessage(); }
    echo ;
  }
}

main();