0

Playing around with conversions in base64 with Python but I have hit a roadblock with trying to convert b64 to decimal.

The following code is suggested on stackoverflow previously but doesn't seem to work for me.

I looked up the error and it appears that this means it can't decode b6 because it is already decoded...

b6 = 'FhY='
print(' '.join([ str(ord(c)) for c in b6.decode('base64') ]))

#expectedoutput = 22 22 
#'str' object has no attribute 'decode'
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

0

Bytes objects have decode function. Strings do not. The leading b on the string matters.

b6 = b'FhY='

Then, decode('base64') is not correct and will return error saying the codec doesn't exist.

Here is what you need, which returns a joined string of two decimal values

>>> ' '.join(map(str, base64.decodebytes(b6)))
'22 22'
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245