home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / modules / webmail / classrc4crypt.php next >
Encoding:
PHP Script  |  2002-09-16  |  2.7 KB  |  81 lines

  1. <?php
  2.  
  3. /*************************************************************************/
  4.  #  Mailbox 0.9.2a   by Sivaprasad R.L (http://netlogger.net)             #
  5.  #  eMailBox 0.9.3   by Don Grabowski  (http://ecomjunk.com)              #
  6.  #          --  A pop3 client addon for phpnuked websites --              #
  7.  #                                                                        #
  8.  # This program is distributed in the hope that it will be useful,        #
  9.  # but WITHOUT ANY WARRANTY; without even the implied warranty of         #
  10.  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          #
  11.  # GNU General Public License for more details.                           #
  12.  #                                                                        #
  13.  # You should have received a copy of the GNU General Public License      #
  14.  # along with this program; if not, write to the Free Software            #
  15.  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              #
  16.  #                                                                        #
  17.  #             Copyright (C) by Sivaprasad R.L                            #
  18.  #            Script completed by Ecomjunk.com 2001                       #
  19. /*************************************************************************/
  20.  
  21. if (!eregi("modules.php", $PHP_SELF)) {
  22.     die ("You can't access this file directly...");
  23. }
  24.  
  25. require_once("mainfile.php");
  26. $module_name = basename(dirname(__FILE__));
  27. get_lang($module_name);
  28.  
  29. // Class Made By Mukul Sabharwal [mukulsabharwal@yahoo.com]
  30. // http://www.devhome.net/php/
  31. // On October 21, 2000
  32.  
  33. class rc4crypt {
  34.  
  35. function endecrypt ($pwd, $data, $case) {
  36.     if ($case == 'de') {
  37.     $data = urldecode($data);
  38.     }
  39.     $key[] = "";
  40.     $box[] = "";
  41.     $temp_swap = "";
  42.     $pwd_length = 0;
  43.     $pwd_length = strlen($pwd);
  44.     for ($i = 0; $i < 255; $i++) {
  45.     $key[$i] = ord(substr($pwd, ($i % $pwd_length)+1, 1));
  46.         $box[$i] = $i;
  47.     }
  48.     $x = 0;
  49.     for ($i = 0; $i < 255; $i++) {
  50.     $x = ($x + $box[$i] + $key[$i]) % 256;
  51.         $temp_swap = $box[$i];
  52.         $box[$i] = $box[$x];
  53.         $box[$x] = $temp_swap;
  54.     }
  55.     $temp = "";
  56.     $k = "";
  57.     $cipherby = "";
  58.     $cipher = "";
  59.     $a = 0;
  60.     $j = 0;
  61.     for ($i = 0; $i < strlen($data); $i++) {
  62.     $a = ($a + 1) % 256;
  63.         $j = ($j + $box[$a]) % 256;
  64.         $temp = $box[$a];
  65.         $box[$a] = $box[$j];
  66.         $box[$j] = $temp;
  67.         $k = $box[(($box[$a] + $box[$j]) % 256)];
  68.         $cipherby = ord(substr($data, $i, 1)) ^ $k;
  69.         $cipher .= chr($cipherby);
  70.     }
  71.     if ($case == 'de') {
  72.         $cipher = urldecode(urlencode($cipher));
  73.     } else {
  74.         $cipher = urlencode($cipher);
  75.     }
  76.     return $cipher;
  77. }
  78.  
  79. }
  80.  
  81. ?>