Zend - The PHP Company




Text

Add Code


ROT13 Encoding Function  

Type: code fragment
Added by: brettb
Entered: 17/07/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 5881
ROT13 is a useful method of encoding text so that it cannot easily be read. The method originated on USENET, where it was commonly used to hide answers to jokes and spoilers for forthcoming TV show episodes.


<?php
/*ROT13 function - a function to encode and decode text strings
  using the popular ROT13 method.

  Brett Burridge (brett@brettb.com)

  The function is called using something like:

  print ROT13("Hello World");
  
  Note that ROT13 does not encrypt strings, so do not use it if security is an issue

  An ASP and JavaScript version of the function is available from:
  http://www.aspwatch.com/c/199934/d5D41863A588511D3ADCA00A0C9E95208.asp

*/

Function ROT13($rot13text) {

    
$rot13text_rotated "";

    for (
$i 0$i <= strlen($rot13text); $i++) {
           
      
$k ord(substr($rot13text$i1));
      
      if (
$k >= 97 and $k <= 109) {
        
$k $k 13;
      } elseif (
$k >= 110 and $k <= 122) {
        
$k $k 13;
      } elseif (
$k >= 65 and $k <= 77) {
        
$k $k 13;
      } elseif (
$k >= 78 and $k <= 90) {
        
$k $k 13;
      }

        
$rot13text_rotated $rot13text_rotated Chr($k);
    }
     
     return 
$rot13text_rotated;
  
}


?>


Usage Example


print ROT13("Hello World");


Rate This Script





Search



This Category All Categories