p = $p; $this->s = $s; } function sec_add($a, $b) { $higha = ($a >> 16) & 0xffff; $lowa = $a & 0xffff; $highb = ($b >> 16) & 0xffff; $lowb = $b & 0xffff; $highsum = $higha + $highb; $lowsum = $lowa + $lowb; # overflow low-addition add high-addition $highsum += ($lowsum & 0x00010000) >> 16; $highsum &= 0xffff; $lowsum &= 0xffff; return ($highsum << 16) | $lowsum; } function bf_enc($ll, $r, $n) { $ll ^= $this->pk[$n]; $b1 = $this->sk[($r >> 24) & 0xff]; $b2 = $this->sk[256 + (($r >> 16) & 0xff)]; $b3 = $this->sk[512 + (($r >> 8) & 0xff)]; $b4 = $this->sk[768 + ($r & 0xff)]; return $ll ^ $this->sec_add(($this->sec_add($b1, $b2) ^ $b3), $b4); } function bf_encrypt($l, $r) { $l ^= $this->pk[0]; for ($i = 1; $i < 17; $i += 2) { $r = $this->bf_enc($r, $l, $i); $l = $this->bf_enc($l, $r, $i + 1); } $r ^= $this->pk[17]; return array($r, $l); } function bf_decrypt($l, $r) { $l ^= $this->pk[17]; for ($i = 16; $i > 0; $i -= 2) { $r = $this->bf_enc($r, $l, $i); $l = $this->bf_enc($l, $r, $i - 1); } $r ^= $this->pk[0]; return array($r, $l); } function asc2int($asc) { return (ord($asc[0]) << 24) | (ord($asc[1]) << 16) | (ord($asc[2]) << 8) | (ord($asc[3])); } function int2asc($int) { return chr($int >> 24) . chr(($int >> 16) & 0xff) . chr(($int >> 8) & 0xff) . chr($int & 0xff); } function bf_set_key($key) { if (strlen($key) <= 0) $key = ' '; while (strlen($key) < 72) $key .= $key; $key = substr($key, 0, 72); $this->pk = $this->p; $this->sk = $this->s; $l = 0; $r = 0; for ($i = 0; $i < 18; $i ++) $this->pk[$i] ^= $this->asc2int(substr( $key, $i * 4, 4)); for ($i = 0; $i < 18; $i += 2) { list($l, $r) = $this->bf_encrypt($l, $r); $this->pk[$i ] = $l; $this->pk[$i + 1] = $r; } for ($i = 0; $i < 1024; $i += 2) { list($l, $r) = $this->bf_encrypt($l, $r); $this->sk[$i ] = $l; $this->sk[$i + 1] = $r; } } function expand($text) { while (strlen($text) % 8 != 0) $text .= 'x'; return $text; } function encrypt($text) { $len = strlen($text); $plain = ''; for ($i = 0; $i < $len; $i += 8) { $l = $this->asc2int(substr($text, $i, 4)); $r = $this->asc2int(substr($text, $i + 4, 4)); list($l, $r) = $this->bf_encrypt($l, $r); $plain .= $this->int2asc($l) . $this->int2asc($r); } return $plain; } function decrypt($text) { $len = strlen($text); $plain = ''; for ($i = 0; $i < $len; $i += 8) { $a = $this->asc2int(substr($text, $i, 4)); $b = $this->asc2int(substr($text, $i + 4, 4)); list($a, $b) = $this->bf_decrypt($a, $b); $plain .= $this->int2asc($a) . $this->int2asc($b); } return $plain; } function ctEncrypt($plaintext, $len, $password) { if (strlen($password) <= 0) $password = ' '; if (strlen($plaintext) != $len) { echo 'Length mismatch. The parameter len differs from actual length.'; return false; } $plaintext = $this->expand($plaintext); $this->bf_set_key($password); return bin2hex($this->encrypt($plaintext)); } function ctDecrypt($cipher, $len, $password) { if (strlen($password) <= 0) $password = ' '; # converts hex to bin $cipher = pack('H' . strlen($cipher), $cipher); if ($len > strlen($cipher)) { echo 'Length mismatch. The parameter len is too large.'; return false; } $this->bf_set_key($password); return substr($this->decrypt($cipher), 0, $len); } } class ctPayGate extends ctBlowfish { /* class initialize parent ctBlowfish @access private */ function ctPayGate() { ctBlowfish::ctBlowfish(); global $text; $this->text = $text; // error messages } /* search @param string searchstring @return string realstatus @access public */ function ctRealstatus($sStatus){ // string ctRealstatus(string $sStatus(searchstring)) switch($sStatus){ case "OK": $rs = $this->text['paymentsuccessful']; // correct response case "AUTHORIZED": $rs = $this->text['paymentsuccessful']; // correct response break; case "FAILED": $rs = $this->text['paymentfailed']; // correct response break; case "": $rs = $this->text['nodata']; // no data available break; default: $rs = $this->text['unknownstatus']; // different status } return $rs; } /* split and maybe search @param array haystack @param string needle @param string search @return string realstatus @access public */ function ctSplit($arText, $sSplit, $sArg = ""){ // string ctSplit(array $arText(haystack), string $sSplit(needle), [string sArg(search for)]) $b = "" ; $i = 0; while($i < count ($arText)){ $b = split ($sSplit, $arText [$i++]); if($b[0] == $sArg){ // check for $sArg $info = $b[1]; $b = 0; break; } else { $info .= ''.$b[0].'"'.$b[1].'"'; } } if((strlen($sArg) > 0) & ($b != 0)){ // $sArg not found $info = ""; } return $info; } } ?>