Base64 decoding (Python vs Flash)
#1
I'm trying to decode a Base64 file and running into some issues. It will decode fine using Adobe's Base64Decoder Flex class (open source, can be found here), but using Python's Base64 decoder it fails. So I can either try to figure out why it's failing or port Adobe's decoder to Python. I've chosen to port Adobe's decoder, since the code is pretty tiny. Unfortunately, Python 2.4 doesn't have ByteArrays, so I've just been using regular lists and ord() to create a pseudo-ByteArray. However, I can't seem to figure out how the following AS3 code would translate to Python:

Code:
if (count == 4)
    {
        count = 0;
        data.writeByte((work[0] << 2) | ((work[1] & 0xFF) >> 4));
        filled++;

        if (work[2] == -1)
            break;

        data.writeByte((work[1] << 4) | ((work[2] & 0xFF) >> 2));
        filled++;

        if (work[3] == -1)
            break;

        data.writeByte((work[2] << 6) | work[3]);
        filled++;
    }

Particularly the data.writeByte calls. I'm not very familiar with bitwise logic, so any advice is much appreciated. Smile

EDIT: Nevermind, I got it Wink Mods, feel free to delete.
Reply
#2
(2010-09-28, 03:26)maruchan Wrote: I'm trying to decode a Base64 file and running into some issues. It will decode fine using Adobe's Base64Decoder Flex class (open source, can be found here), but using Python's Base64 decoder it fails. So I can either try to figure out why it's failing or port Adobe's decoder to Python. I've chosen to port Adobe's decoder, since the code is pretty tiny. Unfortunately, Python 2.4 doesn't have ByteArrays, so I've just been using regular lists and ord() to create a pseudo-ByteArray. However, I can't seem to figure out how the following AS3 code would translate to Python:

Code:
if (count == 4)
    {
        count = 0;
        data.writeByte((work[0] << 2) | ((work[1] & 0xFF) >> 4));
        filled++;

        if (work[2] == -1)
            break;

        data.writeByte((work[1] << 4) | ((work[2] & 0xFF) >> 2));
        filled++;

        if (work[3] == -1)
            break;

        data.writeByte((work[2] << 6) | work[3]);
        filled++;
    }

Particularly the data.writeByte calls. I'm not very familiar with bitwise logic, so any advice is much appreciated. Smile

EDIT: Nevermind, I got it Wink Mods, feel free to delete.

Weel, care to share resolution ?

I need this as well to decode f4m tags Big Grin
Reply
#3
Take a look at the date of the original thread...

Python should have a lib to decode base64.
Reply

Logout Mark Read Team Forum Stats Members Help
Base64 decoding (Python vs Flash)0