6

I must decode the following data:

b'E\x00\x00 <\xed\x00\x00>\x01\x15\xe2\xac\x140f\xa1C\xacP\x00\x00\xf8V\x00\x07\x00\x07\x00\x01\x07\x9a' 

into an understandable string. For that, we were told to use hashlib and md5. But I don't know how to use it to decypher this message.

I've tried something like this:

message.hashlib().md5().decode() 

But I do not obtain any result

4
  • 4
    A hash is a one way scrambling and shortening of the data. For instance, I could take an md5 hash of a long document to have a short string proving the document has not later been changed. But it doesn't go backwards. You can't get the original string back. You'll notice there is no decode on an md5 object. Commented Apr 21, 2018 at 16:53
  • Then how could I use hashlib to decode the data? Cause I've been told to do using that. Commented Apr 21, 2018 at 16:58
  • Get some clarification on that! Is there more to the task, perhaps a list of possible message and you have to choose which one? You can reverse encrypted messages but not hashes. Either this person doesn't know what they are talking about or there is more to the task. Commented Apr 21, 2018 at 17:02
  • As an example, suppose I gave you the first 5 characters of a message and told you to decrypt the entire message from there. You'd rightly tell me no way! Commented Apr 21, 2018 at 17:02

2 Answers 2

10

You can't get there from here. A hash is a small refactoring of data that destroys virtually all of the information in the data. It is used to identify a revision of the data and can be used later to see if the data has changed. A good hash algorithm changes its output dramatically with even a 1 character change in the data. Consider a Midsummer Night's Dream on gutenberg.org. Its about 100,000 characters and its md5 hash is 16 bytes. You are not going to get the original back from that!

>>> import hashlib >>> import requests >>> night = requests.get("http://www.gutenberg.org/ebooks/1514.txt.utf-8") >>> len(night.text) 112127 >>> print(night.text[20000:20200]) h power to say, Behold! The jaws of darkness do devour it up: So quick bright things come to confusion. HERMIA If then true lovers have ever cross'd, It stands as an edict in destiny: Then let >>> print(night.text[20000:20300]) h power to say, Behold! The jaws of darkness do devour it up: So quick bright things come to confusion. HERMIA If then true lovers have ever cross'd, It stands as an edict in destiny: Then let us teach our trial patience, Because it is a customary cross; As due to love as thoughts, and dre >>> hash = hashlib.md5(night.text.encode("utf-8")).hexdigest() >>> print(hash) cce0d35b8b2c4dafcbde3deb983fec0a 

The hash can be very useful to see if the text has changed:

>>> hash2 = hashlib.md5(requests.get("http://www.gutenberg.org/ebooks/1514.txt.utf-8").text.encode("utf-8")).hexdigest() >>> hash == hash2 True 
Sign up to request clarification or add additional context in comments.

Comments

4

I suggest you to read The Official Documentation of hashlib Documentation.

Simple example:

import hashlib text = 'Some text 2' m = hashlib.md5() m.update(b"Some text") # OR m.update(text.encode('UTF-8')) print(m.hexdigest()) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.