0

So here is my code

import codecs
m = 61626374667b7273345f69735f61773373306d337
print(m.decode("hex"))

And this is the error that I get, I'm not sure if it is a problem within the syntax or I didn't use the library well.

AttributeError: 'str' object has no attribute 'decode'

  • 1
    I'm not sure what your Python is doing. Don't you need "" around your string? `m = .......` should also be giving you an error. – Frank Yellin Mar 04 '22 at 19:35
  • Maybe try something like this https://www.kite.com/python/answers/how-to-convert-a-string-from-hex-to-ascii-in-python – Arson 0 Mar 04 '22 at 19:37

1 Answers1

0

This method is from python2.

If you want to decode a string using decode from codecs you need to use:

import codecs

string = "68656c6c6f" #Your string here, between quotation mark
binary_str = codecs.decode(string, "hex")
print(str(binary_str,'utf-8'))

This will still won't work because you provided an hex string with an ODD number of letters, and every ascii letter is represented by 2 hex digits, so recheck your string.

(The code is from here)

SuperDedo
  • 16
  • 4
  • What do you mean by "This method is from python2."? You're using Python 3 syntax, just like OP. – aaossa Mar 04 '22 at 20:10
  • Using simply decode on a hex string is a method that worked previously in version 2 of python but won't work on python 3, which will raise the error that is in the question. – SuperDedo Mar 04 '22 at 20:21