L
L
lolrofl012021-03-26 23:55:10
PHP
lolrofl01, 2021-03-26 23:55:10

How to decode string from hex? Who has experienced this?

Good afternoon.
It was required to pull out all articles from the table in a DB. There are a lot of articles, more than 20 thousand, dofig fields, I decided to upload everything in json format to a file, opened this file on a new site through file_get_contents, and went through the cycle, added all the articles to myself. I already did this before, so the code was ready, hence the solution. But if other tables were transferred perfectly, then here I ran into an encoding unknown to me. Instead of Russian titles and content - encoded text. I couldn't find anything on this topic.

Here's what the title of the article looks like:

0xd091d183d0bad0bcd0b5d0bad0b5d180d181d0bad0b8d0b520d0bad0bed0bdd182d0bed180d18b20d0b820d181d182d0b0d0b2d0bad0b820d0bdd0b020d181d0bfd0bed180d182


I am attaching a photo of a json file with all this.

The question is, how can I turn this hash into a normal Russian language?)

605e4a2c116b1642388318.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lolrofl01, 2021-03-27
@lolrofl01

In short, I figured it out, partly thanks to the answer of galaxy (dude below), but due to the fact that he did not say the main thing, I will mark my answer as the solution.
This hash is really from hex. And indeed it is converted using the hex2bin() function.
BUT!
For some reason it is hashed so that the first 2 characters are superfluous: "0x". They need to be removed. Until you remove them, the function will not work, it will give an error: "Input string must be hexadecimal string".
Therefore, we do this:

$s = "0xd091d183d0bad0bcd0b5d0bad0b5d180d181d0bad0b8d0b520d0bad0bed0bdd182d0bed180d18b20d0b820d181d182d0b0d0b2d0bad0b820d0bdd0b020d181d0bfd0bed180d182";
$s = substr($s, 2, strlen($s));
$s = hex2bin($s);

In that case, it will work. Once again I will explain that we delete the first 2 characters: "0x".

G
galaxy, 2021-03-27
@galaxy

This is not a hash, but plain text in UTF-8 encoded in hex.

print hex2bin("d091d183d0bad0bcd0b5d0bad0b5d180d181d0bad0b8d0b520d0bad0bed0bdd182d0bed180d18b20d0b820d181d182d0b0d0b2d0bad0b820d0bdd0b020d181d0bfd0bed180d182");

# Букмекерские конторы и ставки на спорт

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question