HOTPSecret.php
protected function base32decode($data)
    {
        $alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";

        // stringify
        $data = (string) $data;
        if ($data === "") {
            return "";
        }
        // using only uppercase letters
        $data = strtoupper($data);
        // removing trailing "="
        $data = rtrim($data, "=");
        // removing everything that is not part of the alphabet
        $data = preg_replace("~[^{$alphabet}]~", "", $data);

        $binary = "";
        foreach (str_split($data) as $char) {
            $binary .= str_pad(decbin(strpos($alphabet, $char)), 5, 0, STR_PAD_LEFT);
        }
        $binary = substr($binary, 0, (floor(strlen($binary) / 8) * 8));

        $result = "";
        foreach (str_split($binary, 8) as $chunk) {
            $chunk = str_pad($chunk, 8, 0, STR_PAD_RIGHT);
            $result .= chr(bindec($chunk));
        }

        return $result;
    }
protected function base32decode($data)
    {
        $alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";

        // stringify
        $data = (string) $data;
        if ($data === "") {
            return "";
        }
        // using only uppercase letters
        $data = strtoupper($data);
        // removing trailing "="
        $data = rtrim($data, "=");
        // removing everything that is not part of the alphabet
        $data = preg_replace("~[^{$alphabet}]~", "", $data);

        $binary = "";
        foreach (str_split($data) as $char) {
            $binary .= str_pad(decbin(strpos($alphabet, $char)), 5, 0, STR_PAD_LEFT);
        }
        $binary = substr($binary, 0, (floor(strlen($binary) / 8) * 8));

        $result = "";
        foreach (str_split($binary, 8) as $chunk) {
            $chunk = str_pad($chunk, 8, 0, STR_PAD_RIGHT);
            $result .= chr(bindec($chunk));
        }

        return $result;
    }
Decodes base32 encoded string.
@see SugiPHP\Encode\Base32::decode()

@param  string $data
@return string