Decodes a base64-string to a block of numbers

@param string|string[] $based
the base64-string or the array of characters
@return int[]
@throws \axy\codecs\base64vlq\errors\InvalidBase64
964075
public function decode($based)
    {
        if (!is_array($based)) {
            $based = str_split($based);
        }
        $numbers = [];
        $char2int = $this->char2int;
        foreach ($based as $char) {
            if (isset($char2int[$char])) {
                $numbers[] = $char2int[$char];
            } else {
                throw new InvalidBase64($based);
            }
        }
        return $numbers;
    }
1108430
public function decodeBytes($count = 1)
    {
        if (!is_int($count) || $count < 0) {
            throw new \InvalidArgumentException();
        }

        if (!$count) {
            return '';
        }

        return $this->buffer->get($count);
    }
581850
public function base($binary)
	{
		$base = new Base2n($this->hash_alphabet_bits_per_char,
			$this->hash_alphabet, true, true, true);

		return $base->encode($binary);
	}
727904
public function getBase($length, $base = 62)
    {
        $str = '';

        $bytes = $this->getByte($length);
        /** @noinspection ForeachInvariantsInspection */
        for ($i = 0; $i < $length; $i++) {
            $r = ord($bytes[$i]) % $base;

            if ($r < 10) {
                $str .= chr(ord('0') + $r);
            } elseif ($r < 36) {
                $str .= chr(ord('a') + $r - 10);
            } else {
                $str .= chr(ord('A') + $r - 36);
            }
        }

        return $str;
    }
438994
public static function base64Decode($char)
    {
        if (!array_key_exists($char, self::$CHAR_TO_INT)) {
            throw new Exception("Not a valid base 64 digit: ".$char);
        }
        return self::$CHAR_TO_INT[$char];
    }
584300
public static function decode($data)
    {
        if (!is_string($data)) {
            throw new InvalidArgumentException('data must be string');
        }

        // undo the URL safe replacement
        $convertedData = strtr($data, '-_', '+/');

        // restore the padding
        switch (strlen($convertedData) % 4) {
            case 0:
                break;
            case 2:
                $convertedData .= '==';
                break;
            case 3:
                $convertedData .= '=';
                break;
            default:
                throw new InvalidArgumentException('invalid base64url string length');
        }

        return parent::decode($convertedData);
    }
869601
public function fromBase64(string $base64):ByteArray{
		$base64 = \trim($base64);

		if(!$this->isAllowedBase64($base64)){
			throw new TraitException('invalid base64 string');
		}

		return $this->fromString(\base64_decode($base64));
	}
1315547
public static function unserializePublicKey(string $data): array
    {
        $data = bin2hex($data);
        if (mb_substr($data, 0, 2, '8bit') !== '04') {
            throw new \InvalidArgumentException('Invalid data: only uncompressed keys are supported.');
        }
        $data = mb_substr($data, 2, null, '8bit');
        $dataLength = self::safeStrlen($data);

        return [
            hex2bin(mb_substr($data, 0, $dataLength / 2, '8bit')),
            hex2bin(mb_substr($data, $dataLength / 2, null, '8bit')),
        ];
    }
82704
public static function extendedKeyBase58Decode($key)
    {
        // The base58-decoded extended key must consist of a serialized payload
        // plus an additional 4 bytes for the checksum.
        $decoded = static::base58()->decode($key);

        if (strlen($decoded) !== 82) {
            throw new \InvalidArgumentException('Wrong key length.');
        }

        // Split the payload and checksum up and ensure the checksum matches.
        $payload = substr($decoded, 0, 78);
        $expected = substr($decoded, -4);

        // Verify checksum of provided key
        $network = NetworkFactory::fromExtendedKeyVersion(substr($payload, 0, 4));
        $checksum = substr($network->base58Checksum($payload), 0, 4);

        if ($expected !== $checksum) {
            throw new \InvalidArgumentException('Wrong checksum on encoding extended key!');
        }

        return $decoded;
    }
13844
public function fromBase64URL($data)
    {
        if ($remainder = strlen($data) % 4) {
            $data .= str_repeat('=', 4 - $remainder);
        }

        return base64_decode(strtr($data, '-_', '+/'));
    }
592606
public static function encode($decoded)
    {
        switch(gettype($decoded))
        {
            case "integer":
                return self::encodeInteger($decoded);

            case "double":
                return self::encodeDouble($decoded);

            case "boolean":
                return self::encodeBoolean($decoded);

            case "string":
                return self::encodeString($decoded);

            case "array":
                // If the array doesn't have sequential keys from 0 to n then assume we are dealing with a map
                if (array_keys($decoded) !== range (0, count($decoded) - 1))
                {
                    return self::encodeMap($decoded);
                }
                // Otherwise it's a sequence
                else
                {
                    return self::encodeSequence($decoded);
                }

            case "NULL":
                return self::encodeNull();

            case "unknown type":
                return self::encodeUndefined();

            case "object":
                return self::encode(self::objectToMap($decoded));
        }

        // Unknown type, just return null
        return null;
    }
1114920
public static function decode($octets)
    {
        $bitsPerOctet = 7;
        $value = gmp_init(0, 10);
        $i = 0;

        $leftShift = function ($number, $positions) {
            return gmp_mul($number, gmp_pow(2, $positions));
        };

        while (true) {
            if (!isset($octets[$i])) {
                throw new InvalidArgumentException(sprintf('Malformed base-128 encoded value (0x%s).', strtoupper(bin2hex($octets)) ?: '0'));
            }

            $octet = gmp_init(ord($octets[$i++]), 10);

            $l1 = $leftShift($value, $bitsPerOctet);
            $r1 = gmp_and($octet, 0x7f);
            $value = gmp_add($l1, $r1);

            if (0 === gmp_cmp(gmp_and($octet, 0x80), 0)) {
                break;
            }
        }

        return gmp_strval($value);
    }
759166
public static function decode($data)
    {
        $rData = strtr($data, '-_', '+/');
        $rMod4 = strlen($rData) % 4;
        if ($rMod4) {
            $rData .= substr('====', $rMod4);
        }
        return base64_decode($rData);
    }
953972
public static function decode(array $headers = []): array
    {
        $encodedHeaders = [];
        $encodedProperties = [];
        $prefixLength = strlen(self::PROPERTY_PREFIX);

        // separate headers/properties
        foreach ($headers as $key => $value) {
            if (0 === strpos($key, self::PROPERTY_PREFIX)) {
                $encodedProperties[substr($key, $prefixLength)] = $value;
            } else {
                $encodedHeaders[$key] = $value;
            }
        }

        $decodedHeaders = self::doDecode($encodedHeaders);
        $decodedProperties = self::doDecode($encodedProperties);

        return [$decodedHeaders, $decodedProperties];
    }
161375
public function encode($numbers)
    {
        if (!is_array($numbers)) {
            $numbers = [$numbers];
        }
        if ($this->signed) {
            $numbers = Signed::encodeBlock($numbers);
        }
        $digits = [];
        $bits = $this->bits;
        $cBit = $this->cBit;
        foreach ($numbers as $number) {
            do {
                $digit = ($number % $this->cBit);
                $number >>= $bits;
                $continue = ($number > 0);
                if ($continue) {
                    $digit += $cBit;
                }
                $digits[] = $digit;
            } while ($continue);
        }
        return $digits;
    }
609054
public static function decode($json)
    {
        $flags = 0;
        if (PHP_INT_SIZE === 4) {
            $flags |= JSON_BIGINT_AS_STRING;
        }
        $data = json_decode($json, false, 512, $flags);
        $error = json_last_error();
        if ($error !== JSON_ERROR_NONE) {
            throw new \InvalidArgumentException(sprintf('Failed to decode JSON (%d): %s.', $error, json_last_error_msg()));
        }

        return $data;
    }
248899
public function base64Decode($char)
    {
        if (! array_key_exists($char, $this->charToIntMap)) {
            throw new \Exception(sprintf('Invalid base 64 digit "%s" given.', $char));
        }

        return $this->charToIntMap[$char];
    }