简体   繁体   English

Base64 到十进制

[英]Base64 to decimal

Playing around with conversions in base64 with Python but I have hit a roadblock with trying to convert b64 to decimal.在 base64 和 Python 中进行转换,但我在尝试将 b64 转换为十进制时遇到了障碍。

The following code is suggested on stackoverflow previously but doesn't seem to work for me.之前在 stackoverflow 上建议使用以下代码,但似乎对我不起作用。

I looked up the error and it appears that this means it can't decode b6 because it is already decoded...我查找了错误,这似乎意味着它无法解码 b6,因为它已经被解码了……

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

#expectedoutput = 22 22 
#'str' object has no attribute 'decode'

Bytes objects have decode function. Strings do not.字节对象有解码 function。字符串没有。 The leading b on the string matters.字符串中的前导b很重要。

b6 = b'FhY='

Then, decode('base64') is not correct and will return error saying the codec doesn't exist.然后, decode('base64')不正确,将返回错误,指出编解码器不存在。

Here is what you need, which returns a joined string of two decimal values这是您需要的,它返回由两个十进制值组成的连接字符串

>>> ' '.join(map(str, base64.decodebytes(b6)))
'22 22'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM