Hex and HTML entities
Hex and HTML entities
Hex & HTML-entity encode / decode
Hexadecimal encoding represents each byte as two characters from 0-9a-f. bytes.fromhex() and binascii.unhexlify() both convert that text back into bytes, after which .decode() can interpret the bytes as text.
HTML entity encoding represents syntax characters with forms such as < and >. html.escape() creates those representations and html.unescape() reverses them. Python’s unicode_escape codec represents non-printable or non-ASCII characters with Python-style escape sequences where required.
import binascii
import html
plain_text = "hello"
plain_bytes = plain_text.encode()
hex_text = plain_bytes.hex()
decoded_hex_bytes = bytes.fromhex(hex_text)
decoded_hex_text = decoded_hex_bytes.decode()
unhexlified_bytes = binascii.unhexlify(hex_text)
unhexlified_text = unhexlified_bytes.decode()
html_source = "<script>"
escaped_html = html.escape(html_source)
unescaped_html = html.unescape("<b>")
unicode_text = "A"
unicode_escape_bytes = unicode_text.encode("unicode_escape")Find by: hex, hexlify, bytes fromhex, binascii, unhexlify, xxd, exfil decode, oob output, html entities, html escape, unescape, ampersand, encode, decode, xss, unicode escape