When browsing the source code of web pages, sometimes you will see obfuscated encoded strings or codes starting with backslash \x. Is this encrypted code or system garbled characters?
Not really, these characters are just normal text converted to hexadecimal.
\ sign means escape character
\x means only hexadecimal, followed by two hexadecimal characters, indicating the encoding of one byte. Value range: \x00 to \xff
\u is followed by four hexadecimal characters, indicating unicode code, the value range: \u0000 to \uffff
\x only represents a statement that the computer can understand, generally representing English characters, while \u is a character set equivalent to a string in different dictionary sets, generally representing Chinese
Example:
Start with \u: "\u5341\u516d\u8fdb\u5236"
Start of \x: "\x77\x71\x74\x6f\x6f\x6c"
They can also be mixed together.
For example: "\x77\x77\x77\u5341\u516d\u8fdb\u5236"
So how to convert these encoded texts into normal texts that we can easily read and understand?
In fact, it is very simple, no character tool software or the like is needed, we just need to create a blank notepad file.
Then copy and modify the following code, put the text that needs hexadecimal decoding in alert() or console.log.
<script type="text/javascript">
alert("\u5341\u516d\u8fdb\u5236");
alert("\x77\x71\x74\x6f\x6f\x6c");
console.log("\u5341\u516d\u8fdb\u5236");
console.log("\x77\x71\x74\x6f\x6f\x6c");
</script>
Paste the code into Notepad, then select Save As from the File menu in turn, select all files as the save type, and change the name to New Text. Double-click to open it with a browser or drag it directly into the browser to view the normal identifiable text after hex code decoding.
In order to decrypt the hexadecimal encoding, the alert() method in js is mainly used to pop up a plain text dialog box or the console.log() method console outputs the original text information, and the hexadecimal decoding is viewed in the browser console. character of.
We only need to copy the code that needs to be decoded into the brackets of alert() or console.log() to view normal hexadecimal-encoded literal characters in the pop-up window or browser console information.
It should be noted that the English "" double quotation marks are required on the left and right sides of the words in the parentheses. If the copied code has a newline, you need to manually change the string to a line with the backspace delete key. When the code or text already exists in English When double quotes are used, we need to escape them, and avoid adding a backslash \ before each English " in the character to escape into a string instead of being recognized as a symbol in the js code.