Pad data to 128 bit block boundary.

@param string $data
@return string
325374
private static function _pad128($data)
    {
        $padlen = 16 - strlen($data) % 16;
        if (16 != $padlen) {
            $data .= str_repeat("\0", $padlen);
        }
        return $data;
    }
1240560
public function encode($data) : string
    {
        $result = json_encode($data, $this->options, $this->maxDepth);

        $this->checkLastError();

        return $result;
    }
1195858
public static function seal(string $data): string
    {
        $publicKey = self::getPublicKey();
        
        // compute signature
        $sealed = null;
        $ekeys = array();
        
        $success = openssl_seal($data, $sealed, $ekeys, array(
            $publicKey
        ));
        if (!$success) {
            return $sealed;
        }
        
        $sealkey = $ekeys[0];
        
        // free the key from memory;
        openssl_free_key($publicKey);
        
        return self::base64UrlEncode($sealed) . '|' . self::base64UrlEncode($sealkey);
    }
624891
public function encode($data)
    {
        $result = '';
        foreach($data as $k => $v)
        {
            $result .= $k . '|' . serialize($v);
        }
        return $result;
    }
32494
private function safe_encode($data) {
    if (is_array($data)) {
      return array_map(array($this, 'safe_encode'), $data);
    } else if (is_scalar($data)) {
      return str_ireplace(
        array('+', '%7E'),
        array(' ', '~'),
        rawurlencode($data)
      );
    } else {
      return '';
    }
  }
265657
def pad(cls, data):
        
        if sys.version_info > (3, 0):
            try:
                data = data.encode("utf-8")
            except AttributeError:
                pass

            length = AES.block_size - (len(data) % AES.block_size)
            data += bytes([length]) * length
            return data
        else:
            return data + (AES.block_size - len(data) % AES.block_size) * chr(AES.block_size - len(data) % AES.block_size)
1159981
public function base64UrlDecode(string $data): string
    {
        return \base64_decode(\str_pad(\strtr($data, '-_', '+/'), \strlen($data)%4, '=', \STR_PAD_RIGHT));
    }
528809
protected function convertEncoding($data)
    {
        if ($this->getEncodingInput() == $this->getEncodingOutput()) {
            return $data;
        }

        if (is_null($data)) {
            return $data;
        }

        if (is_array($data)) {
            foreach ($data as $key => $value) {
                $data[$key] = $this->convertEncoding($value);
            }

            return $data;
        }

        if ($this->getEncodingOutput() == 'UTF-8') {
            return utf8_encode($data);
        }

        return utf8_decode($data);
    }
494977
public function encode(string $data): string
    {
        if (true === $this->options["check"]) {
            $data = chr($this->options["version"]) . $data;
            $hash = hash("sha256", $data, true);
            $hash = hash("sha256", $hash, true);
            $checksum = substr($hash, 0, 4);
            $data .= $checksum;
        }

        $data = str_split($data);
        $data = array_map("ord", $data);

        $leadingZeroes = 0;
        while (!empty($data) && 0 === $data[0]) {
            $leadingZeroes++;
            array_shift($data);
        }

        $converted = $this->baseConvert($data, 256, 58);

        if (0 < $leadingZeroes) {
            $converted = array_merge(
                array_fill(0, $leadingZeroes, 0),
                $converted
            );
        }

        return implode("", array_map(function ($index) {
            return $this->options["characters"][$index];
        }, $converted));
    }
633729
private function padISO10126($data, $blockSize)
    {
        if ($blockSize > 256) {
            throw new Exception('Block size higher than 256 not allowed');
        }
        $padChr = $blockSize - (strlen($data) % $blockSize);
        $pattern = chr($padChr);
        return $data . str_repeat($pattern, $padChr);
    }
611791
static function encode53($data)
	{
		return preg_replace_callback('/\\\\ud([89ab][0-9a-f]{2})\\\\ud([c-f][0-9a-f]{2})|\\\\u([0-9a-f]{4})/i', function($val)
		{
			return html_entity_decode(
				empty($val[3]) ?
					sprintf('&#x%x;', ((hexdec($val[1])&0x3FF)<<10)+(hexdec($val[2])&0x3FF)+0x10000)
				:
					'&#x'.$val[3].';', ENT_NOQUOTES, 'utf-8'
			);
		}, json_encode($data));
	}
1142273
public static function bit64(int $data, $endianness = false): string
    {
        // big-endian
        if (true === $endianness) {
            return pack('J', $data);
        }

        // little-endian
        if (false === $endianness) {
            return pack('P', $data);
        }

        // machine byte order
        if (null === $endianness) {
            return pack('Q', $data);
        }
    }
409386
public static function encode($bytes)
    {
        $i = 0; $index = 0;
        $base32 = '';
        $bytesLen = \strlen($bytes);

        while ($i < $bytesLen) {
            $currByte = \ord($bytes[$i]);

            /* Is the current digit going to span a byte boundary? */
            if ($index > 3) {
                if (($i + 1) < $bytesLen) {
                    $nextByte = \ord($bytes[$i+1]);
                } else {
                    $nextByte = 0;
                }

                $digit = $currByte & (0xFF >> $index);
                $index = ($index + 5) % 8;
                $digit <<= $index;
                $digit |= $nextByte >> (8 - $index);
                $i++;
            } else {
                $digit = ($currByte >> (8 - ($index + 5))) & 0x1F;
                $index = ($index + 5) % 8;
                if ($index === 0) {
                    $i++;
                }
            }

            $base32 .= self::$base32Chars[$digit];
        }
        return $base32;
    }
1171646
protected function mask($data)
    {
        $out    = '';
        $length = mb_strlen($data, '8bit');
        $j      = ($this->cursor - $this->headerLength) % 4;

        for ($i = 0; $i < $length; $i++) {
            $data_octet = $this->getChar($data, $i);
            $mask_octet = $this->getChar($this->mask, $j);
            $out .= pack('C', ($data_octet ^ $mask_octet));
            $j++;
            if ($j >= 4) {
                $j = 0;
            }
        }

        return $out;
    }
292090
public static function utf8Encode($data) {
		if (is_string($data)) {
			return utf8_encode($data);

		} else if (is_array($data)) {
			foreach ($data as $key => $value) {
				$data[utf8_encode($key)] = self::utf8Encode($value);
			}

		} else if (is_object($data)) {
			foreach ($data as $key => $value) {
				$data->{$key} = self::utf8Encode($value);
			}
		}

		return $data;
	}
333983
private function encode($data)
    {
        $rdm = $this->random();
        $data = base64_encode($data);
        $startIndex = rand(1, strlen($rdm));
        $params = base64_encode($startIndex).self::ENC_SEPARATOR;
        $params .= base64_encode(strlen($data)).self::ENC_SEPARATOR;

        return $params.substr_replace($rdm, $data, $startIndex, 0);
    }
914388
public static function decodeFilterLZWDecode($data) {
		// intialize string to return
		$decoded = '';
		// data length
		$data_length = strlen($data);
		// convert string to binary string
		$bitstring = '';
		for ($i = 0; $i < $data_length; ++$i) {
			$bitstring .= sprintf('%08b', ord($data{$i}));
		}
		// get the number of bits
		$data_length = strlen($bitstring);
		// initialize code length in bits
		$bitlen = 9;
		// initialize dictionary index
		$dix = 258;
		// initialize the dictionary (with the first 256 entries).
		$dictionary = array();
		for ($i = 0; $i < 256; ++$i) {
			$dictionary[$i] = chr($i);
		}
		// previous val
		$prev_index = 0;
		// while we encounter EOD marker (257), read code_length bits
		while (($data_length > 0) AND (($index = bindec(substr($bitstring, 0, $bitlen))) != 257)) {
			// remove read bits from string
			$bitstring = substr($bitstring, $bitlen);
			// update number of bits
			$data_length -= $bitlen;
			if ($index == 256) { // clear-table marker
				// reset code length in bits
				$bitlen = 9;
				// reset dictionary index
				$dix = 258;
				$prev_index = 256;
				// reset the dictionary (with the first 256 entries).
				$dictionary = array();
				for ($i = 0; $i < 256; ++$i) {
					$dictionary[$i] = chr($i);
				}
			} elseif ($prev_index == 256) {
				// first entry
				$decoded .= $dictionary[$index];
				$prev_index = $index;
			} else {
				// check if index exist in the dictionary
				if ($index < $dix) {
					// index exist on dictionary
					$decoded .= $dictionary[$index];
					$dic_val = $dictionary[$prev_index].$dictionary[$index][0];
					// store current index
					$prev_index = $index;
				} else {
					// index do not exist on dictionary
					$dic_val = $dictionary[$prev_index].$dictionary[$prev_index][0];
					$decoded .= $dic_val;
				}
				// update dictionary
				$dictionary[$dix] = $dic_val;
				++$dix;
				// change bit length by case
				if ($dix == 2047) {
					$bitlen = 12;
				} elseif ($dix == 1023) {
					$bitlen = 11;
				} elseif ($dix == 511) {
					$bitlen = 10;
				}
			}
		}