#!Lua-5.0.exe -- Obfuscate an e-mail address, to avoid spam. -- -- I use the three possible encodings: in HTML text, -- numerical entities (decimal (of random length) and hexa), -- in link (href) both previous and URL-encoded chars. -- -- by Philippe Lhoste http://Phi.Lho.free.fr -- -- v. 1.3 -- 2005/08/01 -- Evenly split the three encodings, add bForLink parameter -- v. 1.2 -- 2005/07/27 -- Also use hex values in %XX form -- v. 1.1 -- 2004/07/19 -- Also use hex values -- v. 1.0 -- 2003/11/12 -- First version local email = "Philippe-Lhoste@Example.com?subject=" -- bForLink: true if result is in an href: can use URL-encoded %XX. -- False if must be used in HTML plain text (eg. between the and the ). function Obfuscate(email, bForLink) --~ if bForLink then --~ email = "mailto:" .. email ---- Works if mailto: is encoded using entities only, eg.: mailto: --~ end return (string.gsub(email, "[-?=@._emailto:]", function (char) local b = string.byte(char); --print(b) if bForLink then r = math.random(3) else r = math.random(2) end if r == 1 then return string.format("&#%0" .. math.random(7) .. "d;", b) elseif r == 2 then return string.format("&#x%02X;", b) else return string.format("%%%02X", b) end end )) end print(Obfuscate(email, true)) print(Obfuscate(email, false))