Skip to content

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
sometiny committed Aug 10, 2023
1 parent ea75b44 commit 5fd00a1
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Base32.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ public static function decode(string $chars, array $table = self::base32_decode_
$h = $table[$chars[$i + 7]] & 0x1f;


$x = (($a << 5) | $b) >> 2;
$y = (($b & 0x3) << 5) | $c;
$y = (($y << 5) | $d) >> 4;
$x = ($a << 5 | $b) >> 2;
$y = ($b & 0x3) << 5 | $c;
$y = ($y << 5 | $d) >> 4;

$z = ((($d & 0xf) << 5) | $e) >> 1;
$z = (($d & 0xf) << 5 | $e) >> 1;

$m = (($e & 0x1) << 5) | $f;
$m = ($e & 0x1) << 5 | $f;

$m = (($m << 5) | $g) >> 3;
$m = ($m << 5 | $g) >> 3;

$n = (($g & 0x7) << 5) | $h;
$n = ($g & 0x7) << 5 | $h;
array_push($result, $x, $y, $z, $m, $n);
}

Expand Down Expand Up @@ -116,7 +116,7 @@ public static function encode(string $binary, array $table = self::base32_encode

if ($remain_length > 0) $binary = str_pad($binary, $length + (5 - $remain_length), "\0");

$result = [];
$result = '';

for ($i = 0; $i < $length; $i += 5) {
$x = ord($binary[$i]);
Expand All @@ -127,25 +127,25 @@ public static function encode(string $binary, array $table = self::base32_encode


$a = $x >> 3;
$b = (($x & 0x7) << 2) | ($y >> 6);
$c = ($y >> 1) & (0x1f);
$d = (($y & 0x1) << 4) | ($z >> 4);
$e = (($z & 0xf) << 1) | ($m >> 7);
$b = (($x & 0x7) << 8 | $y ) >> 6;
$c = $y >> 1 & 0x1f;
$d = (($y & 0x1) << 8 | $z ) >> 4;
$e = (($z & 0xf) << 8 | $m ) >> 7;

$f = ($m >> 2) & 0x1f;
$f = $m >> 2 & 0x1f;

$g = (($m & 0x3) << 3) | ($n >> 5);
$g = (($m & 0x3) << 8 | $n ) >> 5;

$h = $n & 0x1f;

array_push($result, $table[$a], $table[$b], $table[$c], $table[$d], $table[$e], $table[$f], $table[$g], $table[$h]);
$result .= sprintf('%s%s%s%s%s%s%s%s', $table[$a], $table[$b], $table[$c], $table[$d], $table[$e], $table[$f], $table[$g], $table[$h]);
}
if ($remain_length > 0) {
$padding = self::encode_padding[$remain_length];
$length = count($result);
while ($padding-- > 0) $result[$length - $padding - 1] = '=';
$length = strlen($result);
while ($padding-- > 0) $result[--$length] = '=';
}

return implode('', $result);
return $result;
}
}

0 comments on commit 5fd00a1

Please sign in to comment.