Last active
May 22, 2020 12:02
-
-
Save Xvezda/cdd889ff5200c828b0a5291e3396cd2f to your computer and use it in GitHub Desktop.
CloudFlare email protection encoding, decoding with python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def decode_cfemail(enc): | |
from textwrap import wrap | |
res = '' | |
key = int(enc[:2], 16) | |
for v in wrap(enc[2:], 2): | |
res += chr(int(v, 16) ^ key) | |
return res | |
""" | |
e.g. | |
`<span class="__cf_email__" data-cfemail="ee96988b948a8fae808f988b9cc08d8183">[email protected]</span>` | |
>>> decode_cfemail('ee96988b948a8fae808f988b9cc08d8183') | |
'xvezda@naver.com' | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
def encode_cfemail(email): | |
def hexpad(char): | |
return char[2:].zfill(2) | |
from random import random as rand | |
# Generate random key | |
key = int(rand() * (0xff+1) + 1) # 0x01 ~ 0xff | |
# Prefix key | |
enc = hexpad(hex(key)) | |
for c in email: | |
# Build string | |
enc += hexpad(hex(ord(c) ^ key)) | |
return enc | |
""" | |
e.g. | |
>>> encode_cfemail('xvezda@naver.com') | |
'cdb5bba8b7a9ac8da3acbba8bfe3aea2a0' | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://xvezda.com/analyzing-cloudflare-email-protection-algorithm.html