#native_company# #native_desc#
#native_cta#

ROT13 Encoding Function

By David Tilbrook
on December 22, 2007

Version: 3.0

Type: Function

Category: Algorithms

License: GNU General Public License

Description: 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
/*
* By: David Tilbrook      Date: 12/22/2007
*
* This will use the existing encryption method described in earlier
* versions but add numeric conversion as well.
* After all, many codes are letters and numbers.
*
*/
function rot13_5( $string ) {
	$convertedString = "";
	$len = strlen($string);

	for ( $i=0; $i < $len; $i++ ) {
		$a = ord($string[$i]);
		// 65-77 to 78-90 and 97-109 to 110-122
		if ( ($a >= 65 && $a <= 77) || ($a >= 97 && $a <= 109) ) {
			$convertedString .= chr($a+13);
			// 78-90 to 65-77 and 110-122 to 97-109
		} elseif ( ($a >= 78 && $a <= 90) || ($a >= 110 && $a <= 122) ) {
			$convertedString .= chr($a-13);
			// 48-52 to 53-57
		} elseif ( $a >= 48 && $a <= 52 ) {
			$convertedString .= chr($a+5);
			// 53-57 to 48-52
		} elseif ( $a >= 53 && $a <= 57 ) {
			$convertedString .= chr($a-5);
			// all other characters
		} else 	{
			$convertedString .= chr($a);
		}
	}
	return $convertedString;
}
?>