From 24c736fa715a5943e4233462d56dbec8d4ab2639 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Wed, 27 Mar 2024 06:20:26 +0100 Subject: [PATCH] Improve implementation --- src/Base32/Base32.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Base32/Base32.php b/src/Base32/Base32.php index 043e528..6b854ca 100644 --- a/src/Base32/Base32.php +++ b/src/Base32/Base32.php @@ -7,6 +7,18 @@ use RuntimeException; use ValueError; +use function array_key_exists; +use function chr; +use function rtrim; +use function str_replace; +use function str_split; +use function strcspn; +use function strlen; +use function strpos; +use function strtoupper; +use function substr; +use function unpack; + final class Base32 { private const ALPHABET_SIZE = 32; @@ -125,9 +137,12 @@ public function decode(string $encoded, bool $strict = false): string throw new RuntimeException('The encoded data length is invalid.'); } + $remainderStr = ''; for ($index = 0; $index < $remainder; $index++) { - $encoded .= $padding; + $remainderStr .= $padding; } + + $encoded .= $remainderStr; } $chars = [];