cf-email-decode
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

cf-email-decode

Description

Email addresses on some websites are obfuscated by Cloudflare's Email Address Obfuscation Technique to prevent bots from scraping them while keeping them visible to humans. Any text that has been obfuscated using this method may be deobfuscated and returned to a human-readable format with the use of the cf-email-decode module.

The encoded text is contained in HTML elements tagged with Cloudflare's email obfuscation attributes. Examples of encoded texts are shown below.

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8be8e4e5ecf9eafff8a7abf2e4feabede4fee5efabeae5abeeeaf8ffeef9abeeececaa">[email protected]</a>

<a href="/cdn-cgi/l/email-protection#43263b222e332f2603263b222e332f266d202c2e"></a>

Installation

To install the module, run the following command:

npm install cf-email-decode

or

yarn add cf-email-decode

Usage

To decode an encoded email address:

const { decode } = require("cf-email-decode");

const decodedEmail = decode("43263b222e332f2603263b222e332f266d202c2e");
console.log(decodedEmail);

To encode an email address:

const { encode } = require("cf-email-decode");

const encodedEmail = encode("email@example.com");
console.log(encodedEmail);

Encoding and Decoding Process

Caution: This algorithm is not suitable for cryptographic purposes as it is reversible.  It is a basic algorithm used for simple obfuscation and should not be relied upon for secure encryption.

Encoding

  • The first two characters of the encoded string represent the key in hexadecimal format.
  • Each subsequent pair of characters in the encoded string corresponds to a character in the input text, obtained by performing an XOR operation with the key.
  • The result of the XOR operation is converted to hexadecimal and then concatenated to form the encoded text.

Decoding

  • The first two characters of the encoded string represent the key in hexadecimal format, ranging from 1 to 256.
  • Starting from the third character, which is the first character containing data after separating the key, each pair of characters in the encoded string represents a character in the original text.
  • Each pair of characters is converted from hexadecimal to decimal, then an XOR operation is performed with the extracted key to obtain the original ASCII value.- The ASCII values obtained from decoding are concatenated to reconstruct the original text.

Package Sidebar

Install

npm i cf-email-decode

Weekly Downloads

3

Version

0.0.7

License

MIT

Unpacked Size

6.39 kB

Total Files

6

Last publish

Collaborators

  • axelnt