@@ -78,17 +78,17 @@ public static function decode(string $chars, array $table = self::base32_decode_
78
78
$ h = $ table [$ chars [$ i + 7 ]] & 0x1f ;
79
79
80
80
81
- $ x = (( $ a << 5 ) | $ b ) >> 2 ;
82
- $ y = (( $ b & 0x3 ) << 5 ) | $ c ;
83
- $ y = (( $ y << 5 ) | $ d ) >> 4 ;
81
+ $ x = ($ a << 5 | $ b ) >> 2 ;
82
+ $ y = ($ b & 0x3 ) << 5 | $ c ;
83
+ $ y = ($ y << 5 | $ d ) >> 4 ;
84
84
85
- $ z = ((( $ d & 0xf ) << 5 ) | $ e ) >> 1 ;
85
+ $ z = (($ d & 0xf ) << 5 | $ e ) >> 1 ;
86
86
87
- $ m = (( $ e & 0x1 ) << 5 ) | $ f ;
87
+ $ m = ($ e & 0x1 ) << 5 | $ f ;
88
88
89
- $ m = (( $ m << 5 ) | $ g ) >> 3 ;
89
+ $ m = ($ m << 5 | $ g ) >> 3 ;
90
90
91
- $ n = (( $ g & 0x7 ) << 5 ) | $ h ;
91
+ $ n = ($ g & 0x7 ) << 5 | $ h ;
92
92
array_push ($ result , $ x , $ y , $ z , $ m , $ n );
93
93
}
94
94
@@ -116,7 +116,7 @@ public static function encode(string $binary, array $table = self::base32_encode
116
116
117
117
if ($ remain_length > 0 ) $ binary = str_pad ($ binary , $ length + (5 - $ remain_length ), "\0" );
118
118
119
- $ result = [] ;
119
+ $ result = '' ;
120
120
121
121
for ($ i = 0 ; $ i < $ length ; $ i += 5 ) {
122
122
$ x = ord ($ binary [$ i ]);
@@ -127,25 +127,25 @@ public static function encode(string $binary, array $table = self::base32_encode
127
127
128
128
129
129
$ a = $ x >> 3 ;
130
- $ b = (($ x & 0x7 ) << 2 ) | ( $ y >> 6 ) ;
131
- $ c = ( $ y >> 1 ) & ( 0x1f ) ;
132
- $ d = (($ y & 0x1 ) << 4 ) | ( $ z >> 4 ) ;
133
- $ e = (($ z & 0xf ) << 1 ) | ( $ m >> 7 ) ;
130
+ $ b = (($ x & 0x7 ) << 8 | $ y ) >> 6 ;
131
+ $ c = $ y >> 1 & 0x1f ;
132
+ $ d = (($ y & 0x1 ) << 8 | $ z ) >> 4 ;
133
+ $ e = (($ z & 0xf ) << 8 | $ m ) >> 7 ;
134
134
135
- $ f = ( $ m >> 2 ) & 0x1f ;
135
+ $ f = $ m >> 2 & 0x1f ;
136
136
137
- $ g = (($ m & 0x3 ) << 3 ) | ( $ n >> 5 ) ;
137
+ $ g = (($ m & 0x3 ) << 8 | $ n ) >> 5 ;
138
138
139
139
$ h = $ n & 0x1f ;
140
140
141
- array_push ( $ result , $ table [$ a ], $ table [$ b ], $ table [$ c ], $ table [$ d ], $ table [$ e ], $ table [$ f ], $ table [$ g ], $ table [$ h ]);
141
+ $ 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 ]);
142
142
}
143
143
if ($ remain_length > 0 ) {
144
144
$ padding = self ::encode_padding[$ remain_length ];
145
- $ length = count ($ result );
146
- while ($ padding -- > 0 ) $ result [$ length - $ padding - 1 ] = '= ' ;
145
+ $ length = strlen ($ result );
146
+ while ($ padding -- > 0 ) $ result [-- $ length ] = '= ' ;
147
147
}
148
148
149
- return implode ( '' , $ result) ;
149
+ return $ result ;
150
150
}
151
151
}
0 commit comments