JRS: In article <11**********************@c74g2000cwc.googlegroups .com>
, dated Tue, 13 Jun 2006 23:26:09 remote, seen in
news:comp.lang.javascript, Christian Blackburn <christian.Blackburn@Yaho
o.com> posted :
Hi Gang,
I would like to use a caesar cipher on the mailto: links in my website
to prevent crawlers from farming the e-mails off my site. Can someone
tell me the equivalents to Chr() and Asc() from Visual Basic, but for
JavaScript? Chr(n) returns the character based on the numeric ASCII
code. For example
Chr(34) --> "
Asc(") --> 34
The following, from <URL:http://www.merlyn.demon.co.uk/problems.htm>,
implements a specific Caesar cipher.
function R13(A) {
if (A> 96 && A<110) return A+13
if (A>109 && A<123) return A-13
if (A> 64 && A< 78) return A+13
if (A> 77 && A< 91) return A-13
return A }
function Rot13(X) { var j, Y = ""
for (j=0 ; j < X.length ; j++)
Y += String.fromCharCode(R13(X.charCodeAt(j)))
return Y }
Another approach, for later browsers, could be to use
S1 = S0.replace(/[a-z]/gi, XXX)
where XXX is a function resembling R13.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.