Helper method converting input data to binary string.

@param string $input
@param string $base

@return string
963762
private function _convertToBin($input, $base)
    {
        switch ($base) {
            case 2:
                return DataConverter::pad($input, $this->binSize);
            case 10:
                return DataConverter::decToBin($input, $this->binSize);
            case 16:
                return DataConverter::hexToBin($input, $this->binSize);
        }
    }
57141
public static function humanReadableToBytes($input)
    {
        $number = (int)$input;
        $units = array(
            'b' => 1,
            'k' => 1024,
            'm' => 1048576,
            'g' => 1073741824
        );
        $unit = strtolower(substr($input, -1));
        if (isset($units[$unit])) {
            $number = $number * $units[$unit];
        }

        return $number;
    }
760039
public static function base64url_decode($input)
  {
    $remainder = strlen($input) % 4;
    if ($remainder) {
        $padlen = 4 - $remainder;
        $input .= str_repeat('=', $padlen);
    }

    return base64_decode(strtr($input, '-_', '+/'));
  }
40451
public static function baseToDec($input, $Chars)
    {
        if (preg_match('/^[' . $Chars . ']+$/', $input)){
            $Result = (string)'0';

            for ($i=0; $i<strlen($input); $i++){
                if ($i != 0) $Result = bcmul($Result, strlen($Chars),0);
                $Result = bcadd($Result, strpos($Chars, $input[$i]),0);
            }
            return $Result;
        }
        return false;
    }
1027659
public static function huffmanDecode(string $input) { /* : ?string */
        $lookup = self::$huffmanLookup;
        $len = \strlen($input);
        $out = \str_repeat("\0", $len / 5 * 8 + 1); // max length

        for ($off = $i = 0; $i < $len; $i++) {
            list($lookup, $chr) = $lookup[$input[$i]];

            if ($chr != null) {
                $out[$off++] = $chr;
                if (isset($chr[1])) {
                    $out[$off++] = $chr[1];
                    continue;
                }
                continue;
            }

            if ($chr === "") {
                return null;
            }
        }

        return \substr($out, 0, $off);
    }
1069957
public static function encryptPassword($input)
    {
        $rndStr=strtolower(self::getRandomString(32));
        $mixedStr=$rndStr.$input;
        return $rndStr.md5($mixedStr);
    }
233136
public function decode($input)
    {
        $parts = explode('.', $input);

        foreach ($parts as &$part) {
            if (strpos($part, static::PREFIX) === 0) {
                $part = $this->_decodePart(
                    substr($part, strlen(static::PREFIX))
                );
            }
        }

        return implode('.', $parts);
    }
442934
public static function isBase64Encoded($input)
    {
        if ($input && @base64_encode(@base64_decode($input, true)) === $input) {
            return true;
        }

        return false;
    }
542571
public function relativeToAbsolute($string, $base)
    {
        $matches = preg_split('#(<(a|img)\b[^>]+>)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
        $old     = $matches;

        foreach ($matches as &$match) {
            if (preg_match('/<(a|img)\b/', $match) && !preg_match('/(?:http|#|mailto)/', $match)) {
                $match = preg_replace('/^([^"]+")([^"]+)/', '$1' . $base . '$2', $match);
            }
        }

        $string = str_replace($old, $matches, $string);
        return $string;
    }
417149
protected static function fromBase10(
        /*# string */ $input,
        /*# string */ $toBase
    )/*# string */ {
        $len = strlen($toBase);
        $res = '';
        do {
            $digit = bcmod($input, $len);
            $res = $toBase[(int) $digit] . $res;
            $input = bcdiv($input, $len, 0);
        } while ($input != '0');
        return $res;
    }
1370375
public function decode(string $input)
    {
        // if (!is_string($input)) {
        //     throw new InvalidArgumentException('Input must be string when call decode.');
        // }
        $input = $this->toBuffer($input);
        $decoded = $this->decodeData($input);

        return $decoded['data'];
    }
720957
public function toBase($base)
    {
        if ($this->normalize()->hasDecimals()) {
            throw new \InvalidArgumentException('Argument number is not an integer');
        }

        // do not mutate, only support positive integers
        $number = ltrim((string) $this, '-');
        if (static::$gmpSupport && $base <= 62) {
            return static::baseConvert($number, 10, $base);
        }

        $result   = '';
        $baseChar = static::getBaseChar($base);
        while (bccomp($number, 0) != 0) { // still data to process
            $rem    = bcmod($number, $base); // calc the remainder
            $number = bcdiv(bcsub($number, $rem), $base);
            $result = $baseChar[$rem] . $result;
        }

        $result = $result ? $result : $baseChar[0];

        return (string) $result;
    }
1177690
protected function transformWalletPassword($input = '')
    {
        if (!\Genesis\Utils\Common::isBase64Encoded($input)) {
            return base64_encode($input);
        }

        return $input;
    }
599813
public function decode($input)
    {
        $this->value = trim(
            mcrypt_decrypt(
                MCRYPT_RIJNDAEL_256,
                $this->secureKey,
                base64_decode($input),
                MCRYPT_MODE_ECB,
                $this->iv
            )
        );

        return $this->value;
    }
676704
public static function decode($input, $encoding = '7bit')
    {
        switch (strtolower($encoding)) {
        case 'quoted-printable':
            return quoted_printable_decode($input);
        case 'base64':
            return base64_decode($input);
        case 'x-uuencode':
        case 'x-uue':
        case 'uue':
        case 'uuencode':
            return convert_uudecode($input);
        case '7bit':
        default:
            return $input;
        }
    }
163825
protected function _encodePart($input)
    {
        $codePoints = $this->_codePoints($input);

        $n = static::INITIAL_N;
        $bias = static::INITIAL_BIAS;
        $delta = 0;
        $h = $b = count($codePoints['basic']);

        $output = '';
        foreach ($codePoints['basic'] as $code) {
            $output .= $this->_codePointToChar($code);
        }
        if ($input === $output) {
            return $output;
        }
        if ($b > 0) {
            $output .= static::DELIMITER;
        }

        $codePoints['nonBasic'] = array_unique($codePoints['nonBasic']);
        sort($codePoints['nonBasic']);

        $i = 0;
        $length = Horde_String::length($input, 'UTF-8');

        while ($h < $length) {
            $m = $codePoints['nonBasic'][$i++];
            $delta = $delta + ($m - $n) * ($h + 1);
            $n = $m;

            foreach ($codePoints['all'] as $c) {
                if (($c < $n) || ($c < static::INITIAL_N)) {
                    ++$delta;
                }

                if ($c === $n) {
                    $q = $delta;
                    for ($k = static::BASE; ; $k += static::BASE) {
                        $t = $this->_calculateThreshold($k, $bias);
                        if ($q < $t) {
                            break;
                        }

                        $code = $t + (($q - $t) % (static::BASE - $t));
                        $output .= static::$_encodeTable[$code];

                        $q = ($q - $t) / (static::BASE - $t);
                    }

                    $output .= static::$_encodeTable[$q];
                    $bias = $this->_adapt($delta, $h + 1, ($h === $b));
                    $delta = 0;
                    ++$h;
                }
            }

            ++$delta;
            ++$n;
        }

        return static::PREFIX . $output;
    }
980271
public function toBase(int $base) : string
    {
        if ($base === 10) {
            return $this->value;
        }

        if ($base < 2 || $base > 36) {
            throw new \InvalidArgumentException(\sprintf('Base %d is out of range [2, 36]', $base));
        }

        return Calculator::get()->toBase($this->value, $base);
    }