Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Base64 Decode issues

by tux402 (Acolyte)
on Dec 21, 2008 at 22:08 UTC ( [id://731930]=perlquestion: print w/replies, xml ) Need Help??

tux402 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks, I am taking in a string of a mixture of Base64 and normal characters. I'm not entirely sure how to decode it under Perl. An example of an encoded string would be

Georgia

or

Toni

The problem is that these strings will decode to a name, but some of the characters are randomly not encoded into base64. How would I go about decoding the string, and leave the non base64 characters alone? I will be taking in random names, so the length, and which characters are encoded will vary.

Replies are listed 'Best First'.
Re: Base64 Decode issues
by zwon (Abbot) on Dec 21, 2008 at 22:28 UTC
    It's not Base64, it's HTML encoding, you can use HTML::Entities to decode this stuff:
    use HTML::Entities; my $line="Toni"; print decode_entities($line);
      That did it! Thank you.
Re: Base64 Decode issues
by zentara (Archbishop) on Dec 21, 2008 at 22:25 UTC
    If you have random non-base64 chars in the string, maybe it isn't base64encoded? Or else it is a clever attempt at encryption by obfuscation? Anyways, this will do it.
    #!/usr/bin/perl use warnings; use strict; my $str = 'Ton&#x69'; print "$str\n"; $str =~ tr#A-Za-z0-9+/##cd; # remove non-base64 chars print "$str\n"; exit;

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Base64 Decode issues
by pKai (Priest) on Dec 21, 2008 at 22:31 UTC

    Locking at your example strings, I think you are wrong when you speak of "base64". The encoded characters in your strings are HTML::Entities and you can decode them like this:

    C:\>perl -MHTML::Entities -pe "$_=decode_entities($_)" Georgia Georgia Toni Toni ^Z
      You are right, I thought it was base64 because I was decoding it using this
      http://www.paulschou.com/tools/xlate/
      I guess I didn't recognize the encoding.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://731930]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found