@@ -78,17 +78,17 @@ public static function decode(string $chars, array $table = self::base32_decode_
7878 $ h = $ table [$ chars [$ i + 7 ]] & 0x1f ;
7979
8080
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 ;
8484
85- $ z = ((( $ d & 0xf ) << 5 ) | $ e ) >> 1 ;
85+ $ z = (($ d & 0xf ) << 5 | $ e ) >> 1 ;
8686
87- $ m = (( $ e & 0x1 ) << 5 ) | $ f ;
87+ $ m = ($ e & 0x1 ) << 5 | $ f ;
8888
89- $ m = (( $ m << 5 ) | $ g ) >> 3 ;
89+ $ m = ($ m << 5 | $ g ) >> 3 ;
9090
91- $ n = (( $ g & 0x7 ) << 5 ) | $ h ;
91+ $ n = ($ g & 0x7 ) << 5 | $ h ;
9292 array_push ($ result , $ x , $ y , $ z , $ m , $ n );
9393 }
9494
@@ -116,7 +116,7 @@ public static function encode(string $binary, array $table = self::base32_encode
116116
117117 if ($ remain_length > 0 ) $ binary = str_pad ($ binary , $ length + (5 - $ remain_length ), "\0" );
118118
119- $ result = [] ;
119+ $ result = '' ;
120120
121121 for ($ i = 0 ; $ i < $ length ; $ i += 5 ) {
122122 $ x = ord ($ binary [$ i ]);
@@ -127,25 +127,25 @@ public static function encode(string $binary, array $table = self::base32_encode
127127
128128
129129 $ 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 ;
134134
135- $ f = ( $ m >> 2 ) & 0x1f ;
135+ $ f = $ m >> 2 & 0x1f ;
136136
137- $ g = (($ m & 0x3 ) << 3 ) | ( $ n >> 5 ) ;
137+ $ g = (($ m & 0x3 ) << 8 | $ n ) >> 5 ;
138138
139139 $ h = $ n & 0x1f ;
140140
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 ]);
142142 }
143143 if ($ remain_length > 0 ) {
144144 $ 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 ] = '= ' ;
147147 }
148148
149- return implode ( '' , $ result) ;
149+ return $ result ;
150150 }
151151}
0 commit comments