RobThree\Auth\TwoFactorAuth::base32Decode PHP Method

base32Decode() private method

private base32Decode ( $value )
    private function base32Decode($value)
    {
        if (strlen($value) == 0) {
            return '';
        }
        if (preg_match('/[^' . preg_quote(self::$_base32dict) . ']/', $value) !== 0) {
            throw new TwoFactorAuthException('Invalid base32 string');
        }
        $buffer = '';
        foreach (str_split($value) as $char) {
            if ($char !== '=') {
                $buffer .= str_pad(decbin(self::$_base32lookup[$char]), 5, 0, STR_PAD_LEFT);
            }
        }
        $length = strlen($buffer);
        $blocks = trim(chunk_split(substr($buffer, 0, $length - $length % 8), 8, ' '));
        $output = '';
        foreach (explode(' ', $blocks) as $block) {
            $output .= chr(bindec(str_pad($block, 8, 0, STR_PAD_RIGHT)));
        }
        return $output;
    }