python base64 string decoding
Asked Answered
C

1

12

I've got what's supposed to be a UCS-2 encoded xml document that I've managed to build a DOM based on minidom after some tweaking.

The issue is that I'm supposed to have some data encoded on base64. I know for a fact that:

AME= (or \x00A\x00M\x00E\x00=) is base64 code for Á

How would I decode that?

http://www.fileformat.info/info/unicode/char/00c1/index.htm shows that the unicode representation for Á is: u"\u00C1" and in UTF-16: 0x00C1

base64.b64decode('AME=').decode('UTF-16')

shows

u'\uc100'

as the unicode representation for the character, but it looks byte-swapped.

Any idea on how to decode it?

Carnal answered 3/8, 2011 at 7:42 Comment(0)
V
17

Check this out

>>> import base64
>>> base64.b64decode('AME=').decode('UTF-16')
u'\uc100'
>>> base64.b64decode('AME=').decode('UTF-16LE')  
u'\uc100'
>>> base64.b64decode('AME=').decode('UTF-16BE')
u'\xc1'

Perhaps you are looking for big endian decoding?

Villalobos answered 3/8, 2011 at 7:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.