2010-09-28, 03:26
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:
Particularly the data.writeByte calls. I'm not very familiar with bitwise logic, so any advice is much appreciated.
EDIT: Nevermind, I got it Mods, feel free to delete.
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.
EDIT: Nevermind, I got it Mods, feel free to delete.