'Base64 to decimal
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'
Solution 1:[1]
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'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
