Advertisement
Guest User

OTAV

a guest
Dec 13th, 2009
144
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function _tr_pnum($s)
  2. {
  3.     /* sum the ascii values of each char */
  4.     $ret = 0;
  5.     for ( $i = 0; $i < strlen($s); $i++ )
  6.     {
  7.         $ret += ord($s[$i]) + $i;
  8.     }
  9.     /* bit shift ret 1 position to the left until ret exceeds PW_MIN_NUM */
  10.     while ($ret < PW_MIN_NUM)
  11.     {
  12.         $ret = $ret << 1;
  13.     }
  14.     return $ret;
  15. }
  16.  
  17. function _tr_crypt ( $instr, $pwstr, $len)
  18. {
  19.    $passnum = (int) ((((_tr_pnum($pwstr)/997) - 1) % 254 ) + 1);
  20.    $pwlen = strlen($pwstr);
  21.  
  22.    for ( $i = $j = 0; $i < $len; $i++ )               /* process whole string */
  23.    {
  24.        $passnum = (int) ((($passnum + ( $i - $len )) - 1 ) % 254) + 1;
  25.        $buff[0] = (ord($instr[$i]) ^ ($passnum ^ ord($pwstr[$j])) );      /* XOR 3 var's */
  26.        $saida[$i] = ($buff[0] ? chr($buff[0]) : $instr[$i]);   /* if NULL return char*/
  27.        $j = ( $j = $pwlen ? 0 : $j + 1 );    /* password que control variable */
  28.    }
  29.    $saida = implode("",$saida);
  30.  
  31.    return $saida;                      /* send back encrypted string */
  32. }
  33.  
  34. function encrypt($string,$pass)
  35. {
  36.     $strlen = strlen($string);
  37.     return _tr_crypt($string, $pass, $strlen);
  38. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement