Create your blog and photo album with postbit
Create your blog and photo album

Create new post

Content:

Upload a picture:
Tags (keywords separated by comma)

Save Cancel
webtools:   Followers: 10 ; Following: 2

Explore webtools's photo albums:
Photos from posts (2)
Photos from posts (2)

Base64 encoder/decoder


How to encode to Base 64 or decode from Base 64 characters?

If you need to encode to or decode from Base64 you can use an online Base64 converter tool:
http://www.centralinternet.com.br/base64

You just need to paste the text or the Base 64 code in the form and it will do online instant conversion.

Base64 is mainly used to encode email attachments, URL, and multi-part files.
It is also possible to download the decoded result as an attachment binary file using this online Base64 conversion tool.

This is the Perl code used by this online decoder function to encode to (and decode from) Base64:


package Template;
sub Encode_Base64 { # Upper Case to not conflict with MIME::Base64

# Hello World = SGVsbG8gV29ybGQ=

# my $encoded = Encode_Base64 Template($content);
# my $encoded = Encode_Base64 Template($content, "\n");

my $self = shift;

my $encoded = "";
my $end_of_line = $_[1];
$end_of_line = "\n" unless defined $end_of_line;
pos($_[0]) = 0; # ensure start at the beginning

my $i=0;
my $l=length($_[0]);
for ($i=0;$i<$l;$i+=45) {
my $a = substr($_[0],$i,45);
$encoded .= substr(pack('u', $a), 1);
chop($encoded);
}

$encoded =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs

# fix padding at the end
my $padding = (3 - length($_[0]) % 3) % 3;

$encoded =~ s/.{$padding}$/'=' x $padding/e if $padding;

# break encoded string into lines of no more than 76 characters each (word wrap)
if (length $end_of_line) {
$encoded =~ s/(.{1,76})/$1$end_of_line/g;
}

return $encoded;
}


sub Decode_Base64 {

my $self = shift;

my $str = shift;
my $decoded = "";

$str =~ tr|A-Za-z0-9+=/||cd; # remove non-base64 chars
if (length($str) % 4) {
print STDERR "Base64 decoder requires string length to be a multiple of 4\n";
}
$str =~ s/=+$//; # remove padding
$str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format
while ($str =~ /(.{1,60})/gs) {
my $len = chr(32 + length($1)*3/4); # compute length byte
$decoded .= unpack("u", $len . $1 ); # uudecode
}

return $decoded;
}

####

Post by webtools (2011-09-20 17:26)

From: rick
Would love an offline version of this decoder its the only one i have found works 100% 2011-12-09 10:55

Post your comment:

Name: Email: Site:




| Explore users | New posts | Create your blog | Create your photo album |
| About Postbit | Our blog | Terms of use | Contact Postbit |


Copyright © 2018 - postbit.com