5) { $char = $encodes[$val >> ($pos -= 6)]; $result[] = ( $char == 'i' ? "ia" : $char == '+' ? "ib" : $char == '/' ? "ic" : $char ); $val &= ((1 << $pos) - 1); } } if ($pos > 0) { $char = $encodes[$val << (6 - $pos)]; $result[] = ( $char == 'i' ? "ia" : $char == '+' ? "ib" : $char == '/' ? "ic" : $char ); } return implode('', $result); } public static function decode($string, $decodes) { $decodes = self::getIndexChars(self::ENCODES); $chars = self::getCharArray($string); $pos = 0; $val = 0; $bytes = []; for ($i = 0; $i < count($chars); $i++) { $char = $chars[$i]; if ($char == 'i') { $char = $chars[++$i]; $char = $char == 'a' ? 'i' : $char == 'b' ? '+' : $char == 'c' ? '/' : $chars[--$i]; } $val = ($val << 6) | $decodes[$char]; $pos += 6; while ($pos > 7) { $bytes[] = $val >> ($pos -= 8); $val &= ((1 << $pos) - 1); } } return self::bytesToString($bytes); } private static function bytesToString($bytes) { $string = ''; foreach($bytes as $byte) { $string .= chr($byte); } return $string; } private static function stringToBytes($string) { $length = strlen($string); $bytes = array(); for($i = 0; $i < $length; $i++) { if(ord($string[$i]) >= 128){ $byte = ord($string[$i]) - 256; }else{ $byte = ord($string[$i]); } $bytes[] = $byte ; } return $bytes; } }