简体   繁体   English

将base64字符串解码为十进制字符串

[英]Decode a base64 string to a decimal string

I have a string say FhY= which has been encoded to hex. 我有一个字符串说FhY=已被编码为十六进制。 So when run 所以跑步的时候

>>> b6 = 'FhY='
>>> b6.decode('base64')
'\x16\x16'

This is a hex string that once converted should be 22 22 . 这是一个十六进制字符串,一旦转换应该是22 22 This result has been proven on the site https://conv.darkbyte.ru/ . 该结果已在网站https://conv.darkbyte.ru/上得到证实。 However, I cannot seem to do a proper conversion from base64 to decimal representation. 但是,我似乎无法从base64到十进制表示进行适当的转换。 Some of the challenges I am facing are 我面临的一些挑战是

  1. Expectation of decimal being an int. 十进制的期望是一个int。 I just want base 10 我只想要10号基地
  2. Incorrect values. 值不正确。 I have tried the following conversions base64 > base16 ( Convert a base64 encoded string to binary ), base64 > binary > decimal ( Convert hex string to int in Python ) both of which have failed. 我尝试了以下转换base64 > base16将base64编码的字符串转换为二进制 ), base64 > binary > decimal在Python中将十六进制字符串转换为int )两者都失败了。

Please assist. 请协助。

You need to convert each byte from the decoded string to its decimal value. 您需要将解码后的字符串中的每个字节转换为十进制值。 So this should solve it: 所以这应该解决它:

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

Results in 22 22 结果22 22

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

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