Skip to content

Instantly share code, notes, and snippets.

@Xvezda

Xvezda/decode_cfemail.py

Last active May 22, 2020
Embed
What would you like to do?
CloudFlare email protection encoding, decoding with python.
# -*- 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&#160;protected]</span>`
>>> decode_cfemail('ee96988b948a8fae808f988b9cc08d8183')
'xvezda@naver.com'
"""
# -*- 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'
"""
@Xvezda

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.