- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/text/base32.php
- Класс: BitrixMainTextBase32
- Вызов: Base32::decode
static function decode($base32String)
{
if (!$base32String)
return '';
if (!is_string($base32String))
throw new ArgumentTypeException('base32String', 'string');
$base32String = mb_strtoupper($base32String);
$base32Array = str_split($base32String);
$string = '';
foreach ($base32Array as $str)
{
// skip padding
if ($str === '=')
continue;
if (!isset(self::$alphabet[$str]))
throw new DecodingException(sprintf('Illegal character: %s', $str));
$char = self::$alphabet[$str];
$char = decbin($char);
$string .= str_pad($char, 5, 0, STR_PAD_LEFT);
}
while (strlen($string) % 8 !== 0)
{
$string = substr($string, 0, -1);
}
$binaryArray = self::chunk($string, 8);
$realString = '';
foreach ($binaryArray as $bin)
{
// Pad each value to 8 bits
$bin = str_pad($bin, 8, 0, STR_PAD_RIGHT);
// Convert binary strings to ASCII
$realString .= chr(bindec($bin));
}
return $realString;
}