Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode a base64 string to a decimal string

I have a string say FhY= which has been encoded to hex. So when run

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

This is a hex string that once converted should be 22 22. This result has been proven on the site https://conv.darkbyte.ru/. However, I cannot seem to do a proper conversion from base64 to decimal representation. Some of the challenges I am facing are

  1. Expectation of decimal being an int. I just want base 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.

Please assist.

like image 518
Magondu Avatar asked Sep 05 '26 17:09

Magondu


1 Answers

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

like image 126
Marco Avatar answered Sep 07 '26 08:09

Marco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!