Reduce spam with recaptcha and encryption.

Recently one of our clients was experiencing excessive amounts of spam due to poor captcha. Which I’m sure happens to anyone who thinks (2+8=) is going to stop spam bots. Anyway onto our solution!

[Demo] – Required: [ReCaptcha]

What it does »

No visible email addresses online. For example we take an email address like.
Email Normal: bluemans@live.com
Email Encrypted: Ag8bHRQKKxQOCQAYSQwEHg (sexy right?)


The visitor clicks “Contact Owner”. Then we are promoted with re-captcha human verification. If the visitor correctly answers the question the email address is then decrypted and the visitor can send a message.

How To »

I created the test file below “email-encrypt.php” for a quick demonstration.

function XOREncryption($InputString, $KeyPhrase){

$KeyPhraseLength = strlen($KeyPhrase);

// Loop trough input string
for ($i = 0; $i < strlen($InputString); $i++){

// Get key phrase character position
$rPos = $i % $KeyPhraseLength;

// Magic happens here:
$r = ord($InputString[$i]) ^ ord($KeyPhrase[$rPos]);

// Replace characters
$InputString[$i] = chr($r);
}

return $InputString;
}

// Helper functions, using base64 to
// create readable encrypted texts:

function ecrypt($InputString, $KeyPhrase){
$InputString = XOREncryption($InputString, $KeyPhrase);
$InputString = base64_encode($InputString);
$InputString = str_replace(array('=','+','/'),'',$InputString);
return $InputString;
}

function dcrypt($InputString, $KeyPhrase){
$InputString = base64_decode($InputString);
$InputString = strtr($InputString, '+/=', '-_-');
$InputString = XOREncryption($InputString, $KeyPhrase);
return $InputString;
}

$Str_Test=$_POST['email'];
$Str_Test = ecrypt($Str_Test, "keyphrase");

ECHO 'Email Normal: '.$_POST['email']."
"
;

ECHO 'Email Encrypted: '.$Str_Test."

"
;
$Str_Test2 = dcrypt($Str_Test, "keyphrase");

ECHO "Email Decrypted: ".$Str_Test2."
"
;

?>

<form id="form1" action="#" method="post"><label>Email:

<input id="email" name="email" type="text" />

</label>

<label>

<input id="submit" name="submit" type="submit" value="Submit" />

</label>

</form>

Conclusion

Easy to implement, and results are awesome.
- Install ReCaptcha
- Setup Encrypt
- Test and experiment