0

What encoding do I need to use to encode the string document.write('website%40site.com'); so that it will look like the string below?

%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%63%68%75%6d%61%6b%73%68%6c%69%61%68%40%6d%61%69%6c%2e%72%75%5c%22%3e%63%68%75%6d%61%6b%73%68%6c%69%61%68%40%6d%61%69%6c%2e%72%75%3c%5c%2f%61%3e%27%29%3b

2
  • 1
    your string decodes to document.write('<a href=\"mailto:[email protected]\">[email protected]<\/a>'); see meyerweb.com/eric/tools/dencoder Commented Jun 29, 2011 at 14:01
  • except, now you just now how the bytes are encoded - is this ascii? or some other encoding? it is hard to tell. in fact, only heuristics are really possible... Commented Jun 29, 2011 at 14:03

4 Answers 4

2

This is normal encoded ASCII:

%3c%5c%2f%61%3e = <\/a>

and it is rare to see ASCII encoded like this, Unicode on the other hand is not.

Sign up to request clarification or add additional context in comments.

Comments

1

That is the same type of encoding as URL encoding, except that all characters are encoded instead of only the ones that actually need encoding. Each byte is converted into a two digit hexadecimal number, prefixed with %.

You can encode the string using UTF-8, then convert each byte to a hex code:

string encoded = String.Concat(
  Encoding.UTF8.GetBytes("document.write('website%40site.com');")
  .Select(b => "%" + b.ToString("x2"))
  .ToArray()
);

4 Comments

thanks a lot, that's what I needed! string xxx = string.Empty; Encoding.UTF8.GetBytes("document.write('" + Page.Company.EMail + "');").Select(b => "%" + b.ToString("x2")).ToList().ForEach(d => { xxx += d; });
How can you tell it is UTF8 rather than ASCII or one of the ISO 8859 encodings? I can't discern that.
@throbbing salami: Don't use += to concatenate strings in a loop, I corrected my example to use String.Concat.
David Heffeman: The string doesn't contain any characters where the encoding differs, so it doesn't matter which encoding is used.
1

That's either ASCII or UTF-8 or one of the 8 bit supersets of ASCII. Impossible to say for sure.

Your best bet is to read the documentation of whatever function or program you are trying to pass it to.

Comments

1

Here is an online encoder/decoder which does what you want.

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.