Posted By

koncept on 04/29/08


Tagged

javascript php function encoder ROT13 Obfuscation


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

somedirection


PHP JavaScript ROT13 Encoder Function


 / Published in: PHP
 

This function was respectfully borrowed from TextMate and ported to PHP. Thanks to Allan Odgaard for the function! ;)

Obviously, this can be extended a lot more, but I wanted to keep it as simple as possible for the example.

  1. /**
  2.  * Returns a rot13 encrypted string as well as a JavaScript decoder function.
  3.  * @param string $inputString The string to encrypt
  4.  * @return string An encoded javascript function
  5.  */
  6.  
  7. function js_rot13_encode($inputString) {
  8. $rotated = str_replace('"','\"',str_rot13($inputString));
  9. return <<<EOF
  10. <script type="text/javascript">
  11. /*<![CDATA[*/
  12. document.write("$rotated".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
  13. /*]]>*/
  14. </script>
  15.  
  16. EOF;
  17. // N.B Make sure there are no whitespace or extra characters following the semicolon above!
  18. }
  19.  
  20. // ========
  21. // = Demo =
  22. // ========
  23.  
  24. echo js_rot13_encode('<a href="mailto:[email protected]">[email protected]</a>');
  25. echo js_rot13_encode('[email protected]');

Report this snippet  

You need to login to post a comment.