diff --git a/src/Compression/Gzip/GzipCompression.php b/src/Compression/Gzip/GzipCompression.php index b8c9901..6845e7d 100644 --- a/src/Compression/Gzip/GzipCompression.php +++ b/src/Compression/Gzip/GzipCompression.php @@ -2,64 +2,63 @@ namespace Mfonte\Base62x\Compression\Gzip; - use Mfonte\Base62x\Exception\CompressionException; +use Mfonte\Base62x\Exception\CompressionException; - class GzipCompression +class GzipCompression +{ + public static function encode($data, $encoding = null) { - public static function encode($data, $encoding = null) - { - if (!\function_exists('gzencode')) { - throw new CompressionException('gzip', 'Cannot use Gzip as compression algorithm: the current PHP installation does not support this module.'); - } - - $encoded = false; - switch ($encoding) { - case 'zlib': - $encoded = \gzcompress($data, 9); - break; - case 'deflate': - $encoded = \gzdeflate($data, 9); - break; - case 'gzip': - $encoded = \gzencode($data, 9); - break; - break; - default: - $encoded = \gzencode($data, 9); - } + if (!\function_exists('gzencode')) { + throw new CompressionException('gzip', 'Cannot use Gzip as compression algorithm: the current PHP installation does not support this module.'); + } - if ($encoded === false) { - throw new CompressionException('gzip', 'The gz compression function returned a false state while compressing the input data.'); - } + $encoded = false; + switch ($encoding) { + case 'zlib': + $encoded = \gzcompress($data, 9); + break; + case 'deflate': + $encoded = \gzdeflate($data, 9); + break; + case 'gzip': + $encoded = \gzencode($data, 9); + break; + default: + $encoded = \gzencode($data, 9); + } - return $encoded; + if ($encoded === false) { + throw new CompressionException('gzip', 'The gz compression function returned a false state while compressing the input data.'); } - public static function decode($data, $encoding = null) - { - if (!\function_exists('gzdecode')) { - throw new CompressionException('gzip', 'Cannot use Gzip as compression algorithm: the current PHP installation does not support this module.'); - } + return $encoded; + } - $decoded = false; - switch ($encoding) { - case 'zlib': - $decoded = \gzuncompress($data); - break; - case 'deflate': - $decoded = \gzinflate($data); - break; - case 'gzip': - $decoded = \gzdecode($data); - break; - default: - $decoded = \gzdecode($data); - } + public static function decode($data, $encoding = null) + { + if (!\function_exists('gzdecode')) { + throw new CompressionException('gzip', 'Cannot use Gzip as compression algorithm: the current PHP installation does not support this module.'); + } - if ($decoded === false) { - throw new CompressionException('gzip', 'The gz decompression function returned a false state while uncompressing the input data.'); - } + $decoded = false; + switch ($encoding) { + case 'zlib': + $decoded = \gzuncompress($data); + break; + case 'deflate': + $decoded = \gzinflate($data); + break; + case 'gzip': + $decoded = \gzdecode($data); + break; + default: + $decoded = \gzdecode($data); + } - return $decoded; + if ($decoded === false) { + throw new CompressionException('gzip', 'The gz decompression function returned a false state while uncompressing the input data.'); } + + return $decoded; } +} \ No newline at end of file diff --git a/src/Encoding/Base62x.php b/src/Encoding/Base62x.php index 3129a43..d2c1d3d 100644 --- a/src/Encoding/Base62x.php +++ b/src/Encoding/Base62x.php @@ -86,7 +86,7 @@ public static function encode($input, $ibase = null) // string $ascidx = []; $ascrlist = []; - $inputArr = \str_split($input); + $inputArr = \mb_str_split($input); $inputlen = \count($inputArr); //if(!isset($ascidx)){ $ascidx = array(); } //if(!isset($ascrlist)){ $ascrlist = array(); } @@ -235,7 +235,7 @@ public static function decode($input, $obase = null) // string $ascidx = []; $ascrlist = []; - $inputArr = \str_split($input); + $inputArr = \mb_str_split($input); $inputlen = \count($inputArr); $setResult = self::setAscii($codetype, $inputArr, $ascidx, $ascmax, $asclist, $ascrlist); $asctype = $setResult['asctype']; @@ -321,7 +321,7 @@ public static function xx2dec($inum, $ibase, $ridx) $ridx_in['z'] = 61; $ridx = $ridx_in; } - $iArr = \str_split($inum); + $iArr = \mb_str_split($inum); $iArr = \array_reverse($iArr); $arrLen = \count($iArr); $xnum = 0; @@ -338,7 +338,7 @@ public static function xx2dec($inum, $ibase, $ridx) \error_log(__FILE__.": xxdec found out of radix:$tmpi for base:$ibase.\n"); $tmpi = $ibase - 1; } - $onum = $onum + $tmpi * \pow($ibase, ($i - $xnum)); + $onum = $onum + $tmpi * $ibase ** ($i - $xnum); //error_log("\t".__FILE__.": xx2dec ibase:$ibase i:$i c:".$iArr[$i]." tmpi:$tmpi onum:$onum xnum:$xnum"); } if (\mb_strpos($onum, 'E') !== false) { @@ -504,4 +504,4 @@ private static function _decodeByLength($tmpArr, $op, $m) return [$rtn = $op, $m]; } -} +} \ No newline at end of file diff --git a/src/Encryption/Crypt.php b/src/Encryption/Crypt.php index 85b1989..07a9b16 100644 --- a/src/Encryption/Crypt.php +++ b/src/Encryption/Crypt.php @@ -3,12 +3,13 @@ namespace Mfonte\Base62x\Encryption; use Mfonte\Base62x\Exception\CryptException; -use Mfonte\Base62x\Encryption\Cipher\Decrypt; -use Mfonte\Base62x\Encryption\Cipher\Encrypt; +use Mfonte\Base62x\Encryption\Cypher\Decrypt; +use Mfonte\Base62x\Encryption\Cypher\Encrypt; class Crypt { - protected $method = 'aes-128-ctr'; // default cipher method if none supplied. see: http://php.net/openssl_get_cipher_methods for more. + // default cipher method if none supplied. see: http://php.net/openssl_get_cipher_methods for more. + protected $method = 'aes-128-ctr'; private $key; diff --git a/src/Encryption/Cypher/Bytes.php b/src/Encryption/Cypher/Bytes.php index 8b32897..59cc827 100644 --- a/src/Encryption/Cypher/Bytes.php +++ b/src/Encryption/Cypher/Bytes.php @@ -1,6 +1,6 @@