-1

i saw a code and that code had all string in a array.. And each array index was like: "\x31\x32\x33", etc..

How i can convert for example "hello" to that encode format?

if is possible, there a online encoder?

iZume
  • 119
  • 1
  • 11

3 Answers3

2

As the @nikjohn said, you can decoded the string by console.log.

And the following code I found from this question. And I made some changes, the output string will be in a \x48 \x65 form.

It will convert the string in a hex coding, and each character will be separated by a space:

String.prototype.hexEncode = function(){
    var hex, i;

    var result = "";
    for (i=0; i<this.length; i++) {
        hex = this.charCodeAt(i).toString(16);
        result += ("\\x"+hex).slice(-4) + " ";
    }

    return result;
};

var str = "Hello";
console.log(str.hexEncode());

The result of the above code is \x48 \x65 \x6c \x6c \x6f

Community
  • 1
  • 1
bwangel
  • 732
  • 1
  • 7
  • 12
1

It is an hex coding encoding.

www.unphp.net

http://ddecode.com/hexdecoder/

http://string-functions.com/hex-string.aspx

are the few sites that can give you encoding and decoding using hex coding.

Abhinav
  • 388
  • 4
  • 12
0

If you console log the string sequence, you get the decoded strings. So it's as simple as

console.log('\x31\x32\x33'); // 123

For encoding said string, you can extend the String prototype:

String.prototype.hexEncode = function(){
var hex, i;

var result = "";
 for (i=0; i<this.length; i++) {
    hex = this.charCodeAt(i).toString(16);
    result += ("\\x"+hex).slice(-4);
 }
 return result
}

Now,

var a = 'hello';
a.hexEncode(); //\x68\x65\x6c\x6c\x6f
Community
  • 1
  • 1
nikjohn
  • 20,026
  • 14
  • 50
  • 86