• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/crypt.php
  • Класс: CCryptblowfish
  • Вызов: CCryptblowfish::__Init
function __Init($key)
{
	$key = array_values(unpack("C*", $key));
	$keyLength = count($key);

	// XOR P[0] with the first 32 bits of the key, 
	// XOR P[1] with the second 32-bits of the key,
	// and so on for all bits of the key. Repeatedly cycle through the key bits until 
	// the entire P-array has been XORed with key bits.
	$j = 0;
	for ($i = 0; $i < 18; $i++)
	{
		$data = 0;
		for ($k = 0; $k < 4; $k++)
		{
			$data = ($data << 8) | $key[$j];
			$j++;
			if ($j >= $keyLength)
				$j = 0;
		}
		$this->arSubkeys["P"][$i] = $this->arrP[$i] ^ $data;
	}

	// Encrypt the all-zero string with the Blowfish algorithm,
	// replace P1 and P2 with the encrypted data,
	// encrypt P3 and P4 with the new P1 and P2, 
	// continue the process, replacing all entries of the P- array, and then all four 
	// S-boxes in order, with the output of the continuously-changing Blowfish algorithm
	$datal = 0;
	$datar = 0;
	for ($i = 0; $i < 18; $i += 2)
	{
		$this->__BlowfishCrypt($datal, $datar);
		$this->arSubkeys["P"][$i] = $datal;
		$this->arSubkeys["P"][$i + 1] = $datar;
	}

	for ($i = 0; $i < 4; $i++)
	{
		for ($j = 0; $j < 256; $j += 2)
		{
			 $this->__BlowfishCrypt($datal, $datar);
			 $this->arSubkeys["S"][$i][$j] = $datal;
			 $this->arSubkeys["S"][$i][$j + 1] = $datar;
		}
	}
}