Converting a String to ROT13 for email obfuscator
- 24 February, 2010 -
- PHP Coding -
- Tags : development, JQuery, obfuscator, PHP, ROT13
- 0 Comments
A few days ago (weeks? nah) I posted about ROT13 encryption. Since then I’ve been implementing the JQuery ROT13 email obfuscator. I figured I would reuse my code and just add a string to Hex function.
Well it did work and here’s me sharing with the world.
<?php
function stringToHex( $dumbString ){
$teh_split = str_split( $dumbString , 1 );
$output = '';
foreach( $teh_split as $oneLetter ){
$output .= (string) dechex( ord( $oneLetter ));
}
return $output;
}
function HexROT13( $hexedROT13 = '' ){
$rot13_ref = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$rot13_translate = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
$teh_split = str_split( $hexedROT13 , 2 );
$teh_ref = str_split( $rot13_ref , 1 );
$teh_translate = str_split( $rot13_translate , 1 );
$output = '';
foreach( $teh_split as $letter ){
$rot13_char = chr( hexdec( $letter ));
$rot13_index = array_search( $rot13_char , $teh_ref );
if( $rot13_index > 0 ){
$output .= $rot13_translate[ $rot13_index ];
} else {
$output .= $rot13_char;
}
}
return $output;
}
echo HexROT13( stringToHex( "youremail@yourdomain.com" ));
?>
I know it may solve the problem of encoding into ROT13 from a string for a handful of you guys.
Enjoy!
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.