Wednesday, August 27, 2008

Perl: Base64 encoding decoding

There is a cpan provided Perl module MIME::Base64, using this, you can do the base64 decoding and encoding process easily.

Base64 is use exactly 64 character, and using the 64 characters one string converts into a totally different looks shape. The 64 characters are using at base64 are A-Z, a-z, 0-9, + and /

While any extra bit of padding requires, an equal(=) sign just used other than 64 characters. Below is a simple example that will just convert the timestamp integer into base64 string. And return it into integer form after decoding.
use MIME::Base64;

$base64_string = time();
$encoded = encode_base64($base64_string);
print "Encode $encoded";

## now decode this encoded data again.
$decoded = decode_base64($encoded);
print "Decode $decoded";

To learn more about base64 encoding and decoding, here is wikipedia

Also can take a look it at from cpan

If you like the article, then you must like my Perl articles, That's all for today.

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...