@@ -58,28 +58,21 @@ public static function decode(string $chars, array $table = self::base32_decode_
58
58
{
59
59
if (empty ($ chars )) return '' ;
60
60
$ length = strlen ($ chars );
61
- while ($ chars [$ length - 1 ] === '= ' ) {
62
- $ length --;
63
- }
61
+ while ($ chars [$ length - 1 ] === '= ' ) $ length --;
62
+
64
63
$ padding_length = 8 - $ length % 8 ;
65
64
if ($ padding_length === 8 ) $ padding_length = 0 ;
66
65
67
- if ($ padding_length > 0 ) {
68
- for ($ i = 0 ; $ i < $ padding_length ; $ i ++) $ chars .= '= ' ;
69
- $ length += $ padding_length ;
70
- }
71
-
72
-
73
66
$ result = [];
74
67
for ($ i = 0 ; $ i < $ length ; $ i += 8 ) {
75
68
$ a = $ table [$ chars [$ i ]];
76
69
$ b = $ table [$ chars [$ i + 1 ]];
77
- $ c = $ table [$ chars [$ i + 2 ]] & 0x1f ;
78
- $ d = $ table [$ chars [$ i + 3 ]] & 0x1f ;
79
- $ e = $ table [$ chars [$ i + 4 ]] & 0x1f ;
80
- $ f = $ table [$ chars [$ i + 5 ]] & 0x1f ;
81
- $ g = $ table [$ chars [$ i + 6 ]] & 0x1f ;
82
- $ h = $ table [$ chars [$ i + 7 ]] & 0x1f ;
70
+ $ c = $ table [$ chars [$ i + 2 ] ?? ' = ' ] & 0x1f ;
71
+ $ d = $ table [$ chars [$ i + 3 ] ?? ' = ' ] & 0x1f ;
72
+ $ e = $ table [$ chars [$ i + 4 ] ?? ' = ' ] & 0x1f ;
73
+ $ f = $ table [$ chars [$ i + 5 ] ?? ' = ' ] & 0x1f ;
74
+ $ g = $ table [$ chars [$ i + 6 ] ?? ' = ' ] & 0x1f ;
75
+ $ h = $ table [$ chars [$ i + 7 ] ?? ' = ' ] & 0x1f ;
83
76
84
77
85
78
$ x = (($ a << 5 ) | $ b ) >> 2 ;
0 commit comments