hex to ASCII decode

myndeswx

Client
Регистрация
15.05.2017
Сообщения
436
Благодарностей
104
Баллы
43
Hello, could someone help decoding hex string to ASCII ?))
We have hex like this

0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000144d6167696320496e7465726e6574204d6f6e65790000000000000000000000

Then we can trim all the crap so it becomes this -
4d6167696320496e7465726e6574204d6f6e6579

and if we convert it to ASCII using https://www.rapidtables.com/convert/number/hex-to-ascii.html for example , it becomes-
Magic Internet Money

Looking for a way to do in C#
 

Alexmd

Client
Регистрация
10.12.2018
Сообщения
1 022
Благодарностей
1 424
Баллы
113
C#:
string hex = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000144d6167696320496e7465726e6574204d6f6e65790000000000000000000000";
string str = string.Empty;
for(int i = 3; i < hex.Length; i += 2){
    int s = Convert.ToInt32(hex.Substring(i, 2), 16);
    if(s > 31){//crap trimming
        str += (char)s;
    }
}
return str;
 
  • Спасибо
Реакции: myndeswx

myndeswx

Client
Регистрация
15.05.2017
Сообщения
436
Благодарностей
104
Баллы
43
C#:
 string hex = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000144d6167696320496e7465726e6574204d6f6e65790000000000000000000000";
stringstr = string.Empty;
for(int i = 3; i < hex.Length; i += 2){
    int s = Convert.ToInt32(hex.Substring(i, 2), 16);
    if(s > 31){//crap trimming
        str += (char)s;
    }
}
return str;
thank you! It works with this example, but sometimes the text is in a different location
This is other encoded text example -
0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000085357585649534935000000000000000000000000000000000000000000000000
using regex I can parse the actual text data, in this example it becomes this-
5357585649534935
Could you please adjust the code to decode it from parsed text?
( from this = 5357585649534935 )

Thank you!! :bt:
 

Alexmd

Client
Регистрация
10.12.2018
Сообщения
1 022
Благодарностей
1 424
Баллы
113
try this
C#:
string hex = "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000085357585649534935000000000000000000000000000000000000000000000000";
string str = string.Empty;
for(int i = hex.Length % 2; i < hex.Length; i += 2){
    try{
        int s = Convert.ToInt32(hex.Substring(i, 2), 16);
           if(s > 31){//crap trimming
               str += (char)s;
        }
    }
    catch{}
}
return str;
1645012616063.png
it should work so fine with your's regexed result. just put the regexed result as hex string
 
Последнее редактирование:
  • Спасибо
Реакции: Greez и myndeswx

myndeswx

Client
Регистрация
15.05.2017
Сообщения
436
Благодарностей
104
Баллы
43
Working, thank you :bt:
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)