tkguifan has asked for the wisdom of the Perl Monks concerning the following question:
prints:my $string="foobar"; my $base32; my $bin=unpack 'B*',$string; print "string: $string\nbin: $bin\n"; print "original length of bin: ",length($bin),"\n"; my $bm5=length($bin) % 5; $bin=($bm5?('0'x(5-$bm5)):'').$bin; print "corrected length of bin: ",length($bin),"\n"; while($bin=~s/(.....)//) { my $dec=oct('0b'.$1); $base32.=$dec<26?chr(ord('a')+$dec):chr(ord('0')+$dec-26); } print "base32: $base32\n"; print "length of base32: ",length($base32),"\n";
string: foobar bin: 011001100110111101101111011000100110000101110010 original length of bin: 48 corrected length of bin: 50 base32: dgn3xweyls length of base32: 10
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can I encode a string using only lower case letters and numbers?
by Perlbotics (Archbishop) on Feb 15, 2015 at 19:25 UTC | |
|
Re: How can I encode a string using only lower case letters and numbers?
by Corion (Patriarch) on Feb 15, 2015 at 19:35 UTC | |
|
Re: How can I encode a string using only lower case letters and numbers?
by BrowserUk (Patriarch) on Feb 15, 2015 at 19:23 UTC | |
by tkguifan (Scribe) on Feb 15, 2015 at 19:47 UTC | |
by BrowserUk (Patriarch) on Feb 15, 2015 at 21:43 UTC | |
|
Re: How can I encode a string using only lower case letters and numbers?
by ikegami (Patriarch) on Feb 16, 2015 at 02:11 UTC | |
|
Re: How can I encode a string using only lower case letters and numbers?
by Anonymous Monk on Feb 16, 2015 at 04:08 UTC |