Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

A Reversible Encryption Routine for PHP

By Tony Marston
2005-04-15


The CheckRange Function

This function checks that the value in $num can actually be used as a pointer to an entry in $scramble1.
      function _checkRange ($num) 

{
Indexing starts at 0, not 1, so we must subtract 1 from string length.
          $limit = strlen($this->scramble1)-1;
If the value is too high we must reduce it.
      while ($num > $limit) { 

$num = $num - $limit;
} // while
If the value is too low we must increase it.
      while ($num < 0) { 

$num = $num + $limit;
} // while
We can now return a valid pointer back to the calling process.
      return $num; 


} // _checkRange


Tutorial Pages:
» A Reversible Encryption Routine for PHP
» Rotating each character a fixed number of positions
» Swapping between two different character strings
» Manipulating the index number between the two strings
» Customising the Encryption Algorithm
» Class Variables
» Class Constructor
» The ConvertKey function
» The ApplyFudgeFactor function
» The CheckRange Function
» The Decrypt function
» Using the Encryption Class
» Summary


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1

Ask A Question
characters left.