Пример #1
0
 public function hash($string)
 {
     $seed1 = 0x7fed7fed;
     $seed2 = 0xeeeeeeee;
     $strLen = strlen($string);
     for ($i = 0; $i < $strLen; $i++) {
         $next = ord(strtoupper(substr($string, $i, 1)));
         $seed1 = CryptoUtils::$cryptTable[($this->hashType << 8) + $next] ^ CryptoUtils::uPlus($seed1, $seed2) & 0xffffffff;
         $seed2 = CryptoUtils::uPlus(CryptoUtils::uPlus(CryptoUtils::uPlus(CryptoUtils::uPlus($next, $seed1), $seed2), $seed2 << 5), 3) & 0xffffffff;
     }
     return $seed1;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function encrypt($string, $length)
 {
     if ($length % 4 != 0) {
         throw new InvalidBlockSizeException(sprintf('The block size is invalid. Input expected to be a multiple of 4, %s given', $length));
     }
     $data = $this->createBlockArray($string, $length);
     $blocks = $length / 4;
     for ($block = 0; $block < $blocks; $block++) {
         $this->seed = CryptoUtils::uPlus($this->seed, CryptoUtils::$cryptTable[0x400 + ($this->key & 0xff)]);
         $ch = $data[$block] ^ CryptoUtils::uPlus($this->key, $this->seed);
         $this->key = CryptoUtils::uPlus(~$this->key << 0x15, 0x11111111) | CryptoUtils::rShift($this->key, 0xb);
         $this->seed = CryptoUtils::uPlus(CryptoUtils::uPlus(CryptoUtils::uPlus($data[$block], $this->seed), $this->seed << 5), 3);
         $data[$block] = $ch & (0xffff << 16 | 0xffff);
     }
     return $this->createDataStream($data, $length);
 }