From: <wis...@us...> - 2012-09-08 03:27:07
|
Revision: 10154 http://xoops.svn.sourceforge.net/xoops/?rev=10154&view=rev Author: wishcraft Date: 2012-09-08 03:27:00 +0000 (Sat, 08 Sep 2012) Log Message: ----------- XoopsHash Class Modeller for Checksums call with xoops_load('hash'); then you can either use statically or instanciated ie. XoopsHash::md5($data), XoopsHash::sha1($data), XoopsHash::xoopscrc($data), XoopsHash::password($data) Added Paths: ----------- ThirdParty/checksums/xoopshash/ ThirdParty/checksums/xoopshash/htdocs/ ThirdParty/checksums/xoopshash/htdocs/class/ ThirdParty/checksums/xoopshash/htdocs/class/hash/ ThirdParty/checksums/xoopshash/htdocs/class/hash/md5/ ThirdParty/checksums/xoopshash/htdocs/class/hash/md5/md5.php ThirdParty/checksums/xoopshash/htdocs/class/hash/password/ ThirdParty/checksums/xoopshash/htdocs/class/hash/password/password.php ThirdParty/checksums/xoopshash/htdocs/class/hash/sha1/ ThirdParty/checksums/xoopshash/htdocs/class/hash/sha1/sha1.php ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/ ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.base.php ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.class.php ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.enumerator.php ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.leaver.php ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoopscrc.php ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopshash.php Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/md5/md5.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/md5/md5.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/md5/md5.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,93 @@ +<?php +/** + * A md5 checksum wrapper class for hashing data. + * + */ +class XoopsHashMd5 extends XoopsHash +{ + /** + * function name and class typecast + * + */ + var $_func = 'sha1'; + + /** + * method name for calculation of checksum + * + */ + var $_method = 'calc'; + + /** + * class name of this class + * + */ + var $_name = __CLASS__; + + /** + * parent object from XoopsHash ($this) + * + */ + var $_parent = ''; + + /** + * Constructor + * + * @param string $data + * @param array $options + * @param object $parent + */ + function __construct($data, $options, $parent, $mode = 'inhertit') { + switch ($mode) { + default: + $this->_parent = $parent; + if (empty($options)&&is_object($this->_parent)) + $options = $this->_parent->_options[$this->_func]; + if (!empty($data)) + $this->_crc = $this->calc($data, $options); + break; + case 'static': + return $this->calc($data, $options); + } + } + + /** + * function calc + * For Calculating an Checksum from Parent Class + * + * @param string $data + * @param array $options + */ + function calc($data, $options) { + if (empty($options)&&is_object($this->_parent)) + $options = $this->_parent->_options[$this->_func]; + return $this->md5($data, $options); + } + + /** + * private function md5 + * For calculating an MD5 Checksum + * + * @param string $data + * @param array $options + */ + private function md5($data, $options) { + if (isset($options['length'])) + return substr(md5($data), intval($options['start']), $options['length']); + else + return md5($data); + } +} + + +/** + * A md5 checksum wrapper class for hashing data statically. + * + * @abstract + */ +class XoopsHashMd5Static extends XoopsHashMd5 +{ + function __construct($data, $options, $parent, $mode = 'inhertit') { + return parent::__construct($data, $options, $parent, 'static'); + } +} +?> \ No newline at end of file Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/password/password.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/password/password.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/password/password.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,100 @@ +<?php +/** + * XOOPS password checksum handler + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package kernel + * @since 2.5.5 + * @author Simon Roberts (AKA wishcraft) http://www.chronolabs.com.au/ + * @version $Id: password.php 8066 2012-09-08 12:19:00Z wishcraft $ + */ + +include_once dirname(dirname(__FILE__)).'/xoopscrc/xoops.crc.base.php'; +include_once dirname(dirname(__FILE__)).'/xoopscrc/xoops.crc.enumerator.php'; +include_once dirname(dirname(__FILE__)).'/xoopscrc/xoops.crc.leaver.php'; +include_once dirname(dirname(__FILE__)).'/xoopscrc/xoops.crc.class.php'; +include_once dirname(dirname(__FILE__)).'/xoopscrc/xoopscrc.php'; + +/** + * A password checksum wrapper class for hashing data. + * + */ +class XoopsHashPassword extends XoopsHashXoopscrc +{ + + /** + * Constructor + * + * @param string $data + * @param array $options + * @param object $parent + */ + function __construct($data, $options, $parent, $mode = 'inhertit') { + $this->_func = 'password'; + $this->_name = __CLASS__; + return parent::__construct($data, $options, $parent, $mode); + } + + /** + * function calc + * For Calculating an Checksum from Parent Class + * + * @param string $data + * @param array $options + */ + function calc($data, $options) { + if (empty($options)&&is_object($this->_parent)) + $options = $this->_parent->_options[$this->_func]; + return $this->password($data, $options); + } + + /** + * private function password + * For calculating an Password Checksum + * + * @param string $data + * @param array $options + */ + private function password($data, $options) { + if (empty($options)&&is_object($this->_parent)) + $options = $this->_parent->_options[$this->_func]; + if (!isset($options['seed'])) { + if(is_numeric($this->_parent->_options[$this->_func]['seed'])&&$this->_parent->_options[$this->_func]['seed']<255) + $options['seed'] = $this->_parent->_options[$this->_func]['seed']; + else + $options['seed'] = ord(substr($data, 0, 1)); + } elseif (!is_numeric($options['seed'])) { + $options['seed'] = ord(substr($data, 0, 1)); + } + if (!isset($options['length'])) { + if(is_numeric($this->_parent->_options[$this->_func]['length'])&&$this->_parent->_options[$this->_func]['length']>1) + $options['length'] = $this->_parent->_options[$this->_func]['length']; + else + $options['length'] = 12; + } + set_time_limit(120); + $crc = new $this->_class($data, $options['seed'], $options['length']); + return $crc->crc; + } +} + +/** + * A password checksum wrapper class for hashing data statically. + * + * @abstract + */ +class XoopsHashPasswordStatic extends XoopsHashPassword +{ + function __construct($data, $options, $parent, $mode = 'inhertit') { + return parent::__construct($data, $options, $parent, 'static'); + } +} +?> \ No newline at end of file Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/sha1/sha1.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/sha1/sha1.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/sha1/sha1.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,109 @@ +<?php +/** + * XOOPS sha1 checksum handler + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package kernel + * @since 2.5.5 + * @author Simon Roberts (AKA wishcraft) http://www.chronolabs.com.au/ + * @version $Id: sha1.php 8066 2012-09-08 12:19:00Z wishcraft $ + */ + + +/** + * A sha1 checksum wrapper class for hashing data. + * + */ +class XoopsHashSha1 extends XoopsHash +{ + /** + * function name and class typecast + * + */ + var $_func = 'sha1'; + + /** + * method name for calculation of checksum + * + */ + var $_method = 'calc'; + + /** + * class name of this class + * + */ + var $_name = __CLASS__; + + /** + * parent object from XoopsHash ($this) + * + */ + var $_parent = ''; + + /** + * Constructor + * + * @param string $data + * @param array $options + * @param object $parent + */ + function __construct($data, $options, $parent, $mode = 'inhertit') { + switch ($mode) { + default: + $this->_parent = $parent; + if (empty($options)&&is_object($this->_parent)) + $options = $this->_parent->_options[$this->_func]; + if (!empty($data)) + $this->_crc = $this->calc($data, $options); + break; + case 'static': + return $this->calc($data, $options); + } + } + + /** + * function calc + * For Calculating an Checksum from Parent Class + * + * @param string $data + * @param array $options + */ + function calc($data, $options) { + return $this->sha1($data, $options); + } + + /** + * private function sha1 + * For calculating an SHA1 Checksum + * + * @param string $data + * @param array $options + */ + private function sha1($data, $options) { + if (isset($options['length'])) + return substr(sha1($data), intval($options['start']), $options['length']); + else + return sha1($data); + } +} + +/** + * A md5 checksum wrapper class for hashing data statically. + * + * @abstract + */ +class XoopsHashSha1Static extends XoopsHashSha1 +{ + function __construct($data, $options, $parent, $mode = 'inhertit') { + return parent::__construct($data, $options, $parent, 'static'); + } +} +?> \ No newline at end of file Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.base.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.base.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.base.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,553 @@ +<?php +// $Id: xoops.crc.base.php 1.1.0 - XOOPSCRC 2008-08-15 9:22:20 wishcraft $ +// ------------------------------------------------------------------------ // +// CLORA - Chronolabs Australia // +// Copyright (c) 2008 // +// <http://www.chronolabs.org.au/> // +// ------------------------------------------------------------------------ // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the SDPL Source Directive Public Licence // +// as published by Chronolabs Australia; either version 2 of the License, // +// (at your option) any later version. // +// // +// You may not change or alter any portion of this comment or credits // +// of supporting developers from this source code or any supporting // +// source code which is considered copyrighted (c) material of the // +// original comment or credit authors. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Chronolab Australia // +// Chronolabs International PO BOX 699, DULWICH HILL, NSW, 2203, Australia // +// ------------------------------------------------------------------------ // + +if (!class_exists('xoops_crc_base')) +{ + error_reporting(0); + + class xoops_crc_base extends xoops_crc + { + + var $base; + var $seed; + var $mode; + var $roll; + var $num_evr; + + function __construct ($seed = 127) + { + if ($seed<1) + { + $this->seed = 1; + } elseif ($seed>255) { + $this->seed = 256; + } else { + $this->seed = $seed; + } + $base = $this->_set_base(); + return $this->get_base(); + } + + private function _set_base() + { + + if ($this->seed < 65) + { + $case=true; + } else { + $case=false; + } + + $this->roll = ($this->seed / (3+(1/6))); + $this->num_evr = floor((34.32 / ($this->roll/$this->seed))/($this->seed*($this->roll/17.8))); + + if ($this->roll<16) + { + $this->mode = '1'; + } elseif ($this->roll >15 && $this->roll<32) { + $this->mode = '2'; + } elseif ($this->roll >32 && $this->roll<48) { + $this->mode = '3'; + } elseif ($this->roll >48 ) { + $this->mode = '4'; + } + + if ($this->num_evr==0) + { + $this->num_evr = floor((($this->seed/$this->mode)/($this->mode*3.015))); + } elseif ($this->num_evr>8) { + $this->num_evr = $this->num_evr - floor($this->mode*1.35); + } + + + + $this->base = array(); + switch ($this->mode){ + case 1: + $ii = 0; + $num = 0; + $letter = "a"; + for ($qcb=1;$qcb<32;$qcb++) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + + for ($qcb=64;$qcb>31;$qcb--) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + break; + case 2: + $ii = 0; + $num = 0; + $letter = "a"; + for ($qcb=32;$qcb>0;$qcb--) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + + for ($qcb=32;$qcb<65;$qcb++) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + break; + case 3: + $ii = 0; + $num = 0; + $letter = "a"; + for ($qcb=1;$qcb<17;$qcb++) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + + for ($qcb=64;$qcb>47;$qcb--) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + + for ($qcb=32;$qcb>16;$qcb--) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + + + for ($qcb=32;$qcb<48;$qcb++) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + break; + case 4: + $ii = 0; + $num = 0; + $letter = "a"; + + for ($qcb=17;$qcb>0;$qcb--) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + + for ($qcb=17;$qcb<49;$qcb++) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + + for ($qcb=64;$qcb>48;$qcb--) + { + $ii++; + $done = false; + if ($sofar == $this->num_evr) + { + if ($num < 9) + { + $this->base[$qcb] = $num; + $num++; + $sofar = 0; + $done = true; + } + } else { + $sofar++; + } + + if ($done == false) + { + if (floor($qcb / ($this->roll/$this->num_evr))>$this->mode) + { + switch ($case) + { + case true: + $this->base[$qcb] = $letter; + break; + case false: + $this->base[$qcb] = strtoupper($letter); + break; + } + } else { + $this->base[$qcb] = $letter; + } + $letter++; + if (strlen($letter++)>1) { $letter="a"; } + } + } + break; + } + } + + function get_base() + { + return $this->base; + + } + + function debug_base() + { + $base = array(); + foreach ($this->base as $key => $data) + { + $base[$key] = array("char" => $data, + "ord" => ord($data), + "bin" => decbin(ord($data))); + } + + return array("mode" => $this->mode, "roll" => $this->roll, + "seed" => $this->seed, "mode" => $this->mode, + "num_evr" => $this->num_evr, "base" => $this->base, + "debug" => $base); + } + } +} + +?> \ No newline at end of file Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.class.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.class.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.class.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,75 @@ +<?php +// $Id: xoops.crc.class.php 1.1.0 - XOOPSCRC 2008-08-15 9:22:20 wishcraft $ +// ------------------------------------------------------------------------ // +// CLORA - Chronolabs Australia // +// Copyright (c) 2008 // +// <http://www.chronolabs.org.au/> // +// ------------------------------------------------------------------------ // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the SDPL Source Directive Public Licence // +// as published by Chronolabs Australia; either version 2 of the License, // +// (at your option) any later version. // +// // +// You may not change or alter any portion of this comment or credits // +// of supporting developers from this source code or any supporting // +// source code which is considered copyrighted (c) material of the // +// original comment or credit authors. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Chronolab Australia // +// Chronolabs International PO BOX 699, DULWICH HILL, NSW, 2203, Australia // +// ------------------------------------------------------------------------ // + +if (!class_exists('xoops_crc')) +{ + + error_reporting(E_ERROR); + + class xoops_crc + { + var $base; + var $enum; + var $seed; + var $crc; + + function __construct($data, $seed, $len=29) + { + $this->seed = $seed; + $this->length = $len; + $this->base = new xoops_crc_base((int)$seed); + $this->enum = new xoops_crc_enumerator($this->base); + + if (!empty($data)) + { + for ($i=1; $i<strlen($data); $i++) + { + $enum_calc = $this->enum->enum_calc(substr($data,$i,1),$enum_calc); + } + $xoops_crc_crc = new xoops_crc_leaver($enum_calc, $this->base, $this->length); + $this->crc = $xoops_crc_crc->crc; + } + + } + + function calc($data) + { + for ($i=1; $i<strlen($data); $i++) + { + $enum_calc = $this->enum->enum_calc(substr($data,$i,1),$enum_calc); + } + $xoops_crc_crc = new xoops_crc_leaver($enum_calc, $this->base, $this->length); + return $xoops_crc_crc->crc; + } + } +} + +require ('xoops.crc.base.php'); +require ('xoops.crc.enumerator.php'); +require ('xoops.crc.leaver.php'); + + Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.enumerator.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.enumerator.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.enumerator.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,325 @@ +<?php +// $Id: xoops.crc.enumerator.php 1.1.0 - XOOPSCRC 2008-08-15 9:22:20 wishcraft $ +// ------------------------------------------------------------------------ // +// CLORA - Chronolabs Australia // +// Copyright (c) 2008 // +// <http://www.chronolabs.org.au/> // +// ------------------------------------------------------------------------ // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the SDPL Source Directive Public Licence // +// as published by Chronolabs Australia; either version 2 of the License, // +// (at your option) any later version. // +// // +// You may not change or alter any portion of this comment or credits // +// of supporting developers from this source code or any supporting // +// source code which is considered copyrighted (c) material of the // +// original comment or credit authors. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Chronolab Australia // +// Chronolabs International PO BOX 699, DULWICH HILL, NSW, 2203, Australia // +// ------------------------------------------------------------------------ // + +if (!class_exists('xoops_crc_enumerator')) +{ + error_reporting(0); + + class xoops_crc_enumerator extends xoops_crc + { + + var $elekey; + var $base; + var $len; + + function __construct ($base, $len) + { + @$this->len = $len; + @$this->setElements($base); + } + + private function setElements($base) + { + @$this->base = $base; + @$this->elekey = array(); + + foreach ($base->base as $key => $data) + { + if (strlen((string)$data)==1) + { + if (strlen(bindec(ord($data)))==5) + { + $offset = array("ice" => (int)substr(decbin(ord($data)),5,1), + "icd" => (int)substr(decbin(ord($data)),4,1), + "icc" => (int)substr(decbin(ord($data)),3,1), + "icb" => (int)substr(decbin(ord($data)),2,1), + "ica" => (int)substr(decbin(ord($data)),1,1)); + if (substr(decbin(ord($data)),5,1)==1) + { + $offset['icf'] = 1; + } else { + $offset['icf'] = 0; + } + } elseif (strlen(decbin(ord($data)))==6) + { + $offset = array("icf" => (int)substr(decbin(ord($data)),6,1), + "ice" => (int)substr(decbin(ord($data)),5,1), + "icd" => (int)substr(decbin(ord($data)),4,1), + "icc" => (int)substr(decbin(ord($data)),3,1), + "icb" => (int)substr(decbin(ord($data)),2,1), + "ica" => (int)substr(decbin(ord($data)),1,1)); + } elseif (strlen(decbin(ord($data)))==7) + { + $offset = array("ica" => (int)substr(decbin(ord($data)),6,1), + "icb" => (int)substr(decbin(ord($data)),5,1), + "icc" => (int)substr(decbin(ord($data)),4,1), + "icd" => (int)substr(decbin(ord($data)),3,1), + "ice" => (int)substr(decbin(ord($data)),2,1), + "icf" => (int)substr(decbin(ord($data)),1,1)); + } + } else { + $offset = array("ica" => (int)substr(decbin(ord(substr($key,strlen($key)-1,1))),6,1), + "icb" => (int)substr(decbin(ord(substr($key,strlen($key)-1,1))),5,1), + "icc" => (int)substr(decbin(ord(substr($key,strlen($key)-1,1))),4,1), + "icd" => (int)substr(decbin(ord(substr($key,strlen($key)-1,1))),2,1), + "ice" => (int)substr(decbin(ord(substr($key,strlen($key)-1,1))),1,1), + "icf" => (int)substr(decbin(ord(substr($key,strlen($key)-1,1))),0,1)); + + } + + if (strlen(decbin(ord($data)))==7) + { + if (strlen($data)==1) + { + $cycle = array("icf", "ice", "icd", "icc", "icb", "ica"); + foreach ($cycle as $element) + { + if ($done==false) + { + if ($offset[$element]=='0') + { + if ($prev_ele!='') + { + if ($offset[$prev_ele] == '1') + { + $offset[$prev_ele] = '0'; + } else { + $offset[$prev_ele] = '1'; + } + } + $offset[$element]= '1'; + $done=true; + } + } + } + + } else { + $cycle = array("ica", "icb", "icc", "icd", "ice", "icf"); + foreach ($cycle as $element) + { + if ($done==false) + { + if ($offset[$element]=='0') + { + if ($prev_ele!='') + { + if ($offset[$prev_ele] == '0') + { + $offset[$prev_ele] = '1'; + } else { + $offset[$prev_ele] = '0'; + } + } + $offset[$element]= '1'; + $done=true; + } + } + } + } + } + $done=false; + if (strlen($data)==1) + { + @$this->elekey[$key] = array("key" => $data, + "bin" => decbin(ord($data)), + "offset" => $offset, + "flip" => 0); + } else { + @$this->elekey[$key] = array("key" => $data, + "bin" => decbin(ord($data)), + "offset" => $offset, + "flip" => 1); + } + } + + } + + private function getBytePos($char) + { + return floor((ord($char)+1)/4); + } + + function enum_calc ($char, $enum_calc, $debug=false) + { + static $flip; + + foreach ($enum_calc as $key => $value) + { + ${$key} = $value; + } + + static $charnum; + $charnum++; + if ($charnum>3) + { + $charnum=1; + } + + $nx_key.= $char; + + if ($this->len>15) + { + if (strlen($nx_key)>$this->len) + { + $nx_key = substr($nx_key, strlen($nx_key)/($charnum+1), strlen($nx_key) - (strlen($nx_key)/($charnum+1))).substr($nx_key, 1, strlen($nx_key)-(strlen($nx_key) - (strlen($nx_key)/($charnum+1)))); + } + } else { + if (strlen($nx_key)>32) + { + $nx_key = substr($nx_key, strlen($nx_key)/($charnum+1), strlen($nx_key) - (strlen($nx_key)/($charnum+1))).substr($nx_key, 1, strlen($nx_key)-(strlen($nx_key) - (strlen($nx_key)/($charnum+1)))); + } + } + + if ($this->elekey[$this->getBytePos($char)]['flip']==0) + { + $ica = $this->elekey[$this->getBytePos($char)]['offset']['ica']; + $icb = $this->elekey[$this->getBytePos($char)]['offset']['icb']; + $icc = $this->elekey[$this->getBytePos($char)]['offset']['icc']; + $icd = $this->elekey[$this->getBytePos($char)]['offset']['icd']; + $ice = $this->elekey[$this->getBytePos($char)]['offset']['ice']; + $icf = $this->elekey[$this->getBytePos($char)]['offset']['icf']; + } else { + if ($charnum==1) + { + $icf = $this->elekey[$this->getBytePos($char)]['offset']['ica']; + $ice = $this->elekey[$this->getBytePos($char)]['offset']['icb']; + $icd = $this->elekey[$this->getBytePos($char)]['offset']['icc']; + $icc = $this->elekey[$this->getBytePos($char)]['offset']['icd']; + $icb = $this->elekey[$this->getBytePos($char)]['offset']['ice']; + $ica = $this->elekey[$this->getBytePos($char)]['offset']['icf']; + } elseif ($charnum==2) + { + $icf = $this->elekey[$this->getBytePos($char)]['offset']['ica']; + $ice = $this->elekey[$this->getBytePos($char)]['offset']['icb']; + $icd = $this->elekey[$this->getBytePos($char)]['offset']['icc']; + $icc = $this->elekey[$this->getBytePos($char)]['offset']['icf']; + $icb = $this->elekey[$this->getBytePos($char)]['offset']['ice']; + $ica = $this->elekey[$this->getBytePos($char)]['offset']['icd']; + } else + { + $icf = $this->elekey[$this->getBytePos($char)]['offset']['icc']; + $ice = $this->elekey[$this->getBytePos($char)]['offset']['icb']; + $icd = $this->elekey[$this->getBytePos($char)]['offset']['ica']; + $icc = $this->elekey[$this->getBytePos($char)]['offset']['icd']; + $icb = $this->elekey[$this->getBytePos($char)]['offset']['ice']; + $ica = $this->elekey[$this->getBytePos($char)]['offset']['icf']; + } + } + for ($icount=1; $icount<65; $icount++) + { + if ($this->elekey[$icount]['offset']['ica'] == $icb && $this->elekey[$icount]['offset']['icb'] == $icc && $this->elekey[$icount]['offset']['icc'] == $icd) { + $nuclear .= '10'; + if ($icb = $this->elekey[$icount]['flip']) { + $nuclear .= '1'; + } else { + $nuclear .= '0'; + } + if ($icc = $this->elekey[$icount]['flip']) { + $nuclear .= '1'; + } else { + $nuclear .= '0'; + } + if ($icd = $this->elekey[$icount]['flip']) { + $nuclear .= '0'; + } else { + $nuclear .= '1'; + } + } + + if ($this->elekey[$icount]['offset']['ica'] == $icc && $this->elekey[$icount]['offset']['icb'] == $icd && $this->elekey[$icount]['offset']['icc'] == $ice) { + $nuclear .= '01'; + if ($icb = $this->elekey[$icount]['flip']) { + $nuclear .= '0'; + } else { + $nuclear .= '1'; + } + if ($icc = $this->elekey[$icount]['flip']) { + $nuclear .= '1'; + } else { + $nuclear .= '0'; + } + if ($icd = $this->elekey[$icount]['flip']) { + $nuclear .= '1'; + } else { + $nuclear .= '0'; + } + } + } + + // Change in version 1.6.4 + if (strlen($nuclear)>32768) + $nuclear = substr($nuclear,strlen($nuclear)-32768,32768); + + $result = $result + $ica; + $prince = $prince + $icb; + $karma = $karma + $icc; + $motivation = $motivation + $icd; + $official = $official + $ice; + $outsidecause = $outsidecause + $icf; + + if ($ica == '0') {$yang = $yang + 1;} else {$yin = $yin + 1;} + if ($icb == '0') {$yang = yang + 1;} else {$yin = $yin + 1;} + if ($icc == '0') {$yang = $yang+ 1;} else {$yin = $yin + 1;} + if ($icd == '0') {$yang = $yang + 1;} else {$yin = $yin + 1;} + if ($ice == '0') {$yang = yang + 1;} else {$yin = $yin + 1;} + if ($icf == '0') {$yang = $yang+ 1;} else {$yin = $yin + 1;} + + if ($debug==true) + { + + $data[sizeof($data)+1] = array("pos" => $this->getBytePos($char), + "elements" => $this->elekey); + + $result = array("result" => $result, + "prince" => $prince, + "karma" => $karma, + "motivation" => $motivation, + "official" => $official, + "outsidecause" => $outsidecause, + "nuclear" => $nuclear, + "yin" => $yin, + "yang" => $yang, + "nx_key" => $nx_key, + "data"=> $data); + } else { + $result = array("result" => $result, + "prince" => $prince, + "karma" => $karma, + "motivation" => $motivation, + "official" => $official, + "outsidecause" => $outsidecause, + "nuclear" => $nuclear, + "yin" => $yin, + "yang" => $yang, + "nx_key" => $nx_key); + + } + + return $result; + } + } +} \ No newline at end of file Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.leaver.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.leaver.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoops.crc.leaver.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,162 @@ +<?php +// $Id: xoops.crc.leaver.php 1.1.0 - XOOPSCRC 2008-08-15 9:22:20 wishcraft $ +// ------------------------------------------------------------------------ // +// CLORA - Chronolabs Australia // +// Copyright (c) 2008 // +// <http://www.chronolabs.org.au/> // +// ------------------------------------------------------------------------ // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the SDPL Source Directive Public Licence // +// as published by Chronolabs Australia; either version 2 of the License, // +// (at your option) any later version. // +// // +// You may not change or alter any portion of this comment or credits // +// of supporting developers from this source code or any supporting // +// source code which is considered copyrighted (c) material of the // +// original comment or credit authors. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Chronolab Australia // +// Chronolabs International PO BOX 699, DULWICH HILL, NSW, 2203, Australia // +// ------------------------------------------------------------------------ // + +if (!class_exists('xoops_crc_leaver')) +{ + error_reporting(E_ERROR); + + class xoops_crc_leaver extends xoops_crc + { + var $crc; + + function __construct($enum_calc, $base, $len=29) + { + @$this->crc = $this->calc_crc($enum_calc, $base, $len); + } + + function calc_crc ($enum_calc, $base, $len) + { + for ($qi=0; $qi<$len+1; $qi++) + { + $da = floor(9*($qi/$len)); + $pos = $this->GetPosition($enum_calc, $len, $qi); + $pos = ceil($pos / ($len/ ($qi-1))); + for($v=-$qi;$v<$pos;$v++) + { + if ($c>64) + $c=0; + + $c++; + } + if (strlen($base->base[$c])>1) + { + $crc .= $da; + } else { + $crc .= $base->base[$c]; + } + + + if ($qi<ceil($len/3)) + { + $crc = $this->nux_cycle($crc, $enum_calc['result'], $len); + $crc = $this->nux_cycle($crc, $enum_calc['prince'], $len); + } elseif ($qi<(ceil($len/3)*2)) { + $crc = $this->nux_cycle($crc, $enum_calc['karma'], $len); + $crc = $this->nux_cycle($crc, $enum_calc['motivation'], $len); + } else { + $crc = $this->nux_cycle($crc, $enum_calc['official'], $len); + $crc = $this->nux_cycle($crc, $enum_calc['outsidecause'], $len); + } + + $crc = $this->nux_cycle($crc, $enum_calc['yang'], $len); + } + + $crc = $this->nux_cycle($crc, $enum_calc['yin'], $len); + + $crc = $this->nux_xor($crc, $enum_calc['nx_key']); + + for ($qi=0; $qi<$len+1; $qi++) + { + $da = $len-floor(9*($qi/$len)); + $pos = ceil(ord($crc{$qi}) / 4); + for($v=-$qi;$v<$pos;$v++) + { + if ($c>64) + $c=0; + + $c++; + } + if (strlen($base->base[$c])>1) + { + $final_crc .= $da; + } else { + $final_crc .= $base->base[$c]; + } + } + return $final_crc; + } + + private function GetPosition($enum_calc, $len, $qi) + { + if ($enum_calc['yin']>$enum_calc['yang']) + { + $cycle = floor((256*($enum_calc['yin']/$enum_calc['yang']))/(256*($enum_calc['yang']/$enum_calc['yin'])))+($len - $qi); + } else { + $cycle = ceil((256*($enum_calc['yang']/$enum_calc['yin']))/(256*($enum_calc['yin']/$enum_calc['yang'])))+($len - $qi); + } + + $result = $this->nuc_step($enum_calc['nuclear'], $enum_calc['result'], $cycle+$qi); + $prince = $this->nuc_step($enum_calc['nuclear'], $enum_calc['prince'], $cycle+$qi); + $karma = $this->nuc_step($enum_calc['nuclear'], $enum_calc['karma'], $cycle+$qi); + $motivation = $this->nuc_step($enum_calc['nuclear'], $enum_calc['motivation'], $cycle+$qi); + $official = $this->nuc_step($enum_calc['nuclear'], $enum_calc['official'], $cycle+$qi); + $outsidecause = $this->nuc_step($enum_calc['nuclear'], $enum_calc['outsidecause'], $cycle+$qi); + + $char = decbin($result.$prince.$karma.$motivation.$official.$outsidecause); + + return (ord($char)); + } + + private function nuc_step($nuclear, $var, $cycle) + { + $c=1; + for($v=0;$v<($var+$cycle);$v++) + { + if ($c>strlen($nuclear)) + $c=0; + + $c++; + } + return substr($nuclear,$c,1); + } + + private function nux_cycle($crc, $var, $len) + { + for($v=0;$v<($var+1);$v++) + { + for($y=1;$y<$len;$y++) + { + $crc = substr($crc, $y, $len - $y).substr($crc, 0, $len-($len - $y)); + } + } + return $crc; + } + + private function nux_xor($text_crc, $key) + { + for($i=0;$i<strlen($text_crc);) // Dont need to increment here + { + for($j=0;$j<strlen($key);$j++,$i++) + { + $crc .= $text_crc{$i} ^ $key{$j}; + } + } + return $crc; + } + + } +} \ No newline at end of file Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoopscrc.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoopscrc.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopscrc/xoopscrc.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,136 @@ +<?php +/** + * XOOPS checksum handler + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package kernel + * @since 2.5.5 + * @author Simon Roberts (AKA wishcraft) http://www.chronolabs.com.au/ + * @version $Id: xoopscrc.php 8066 2012-09-08 12:19:00Z wishcraft $ + */ + +include_once dirname(__FILE__).'/xoops.crc.base.php'; +include_once dirname(__FILE__).'/xoops.crc.enumerator.php'; +include_once dirname(__FILE__).'/xoops.crc.leaver.php'; +include_once dirname(__FILE__).'/xoops.crc.class.php'; + +/** + * A xoops checksum wrapper class for hashing data. + * + */ +class XoopsHashXoopscrc extends XoopsHash +{ + /** + * function name and class typecast + * + */ + var $_func = 'sha1'; + + /** + * method name for calculation of checksum + * + */ + var $_method = 'calc'; + + /** + * class name of this class + * + */ + var $_name = __CLASS__; + + /** + * parent object from XoopsHash ($this) + * + */ + var $_parent = ''; + + /** + * 3rd Party class/function to use for generation of checksum + * + */ + var $_class = 'xoops_crc'; + + /** + * Constructor + * + * @param string $data + * @param array $options + * @param object $parent + */ + function __construct($data, $options, $parent, $mode = 'inhertit') { + switch ($mode) { + default: + $this->_parent = $parent; + if (empty($options)&&is_object($this->_parent)) + $options = $this->_parent->_options[$this->_func]; + if (!empty($data)) + $this->_crc = $this->calc($data, $options); + break; + case 'static': + return $this->calc($data, $options); + } + } + + /** + * function calc + * For Calculating an Checksum from Parent Class + * + * @param string $data + * @param array $options + */ + function calc($data, $options) { + if (empty($options)&&is_object($this->_parent)) + $options = $this->_parent->_options[$this->_func]; + return $this->xoopscrc($data, $options); + } + + /** + * private function xoopscrc + * For calculating an XoopsCrc Checksum + * + * @param string $data + * @param array $options + */ + private function xoopscrc($data, $options) { + if (empty($options)&&is_object($this->_parent)) + $options = $this->_parent->_options[$this->_func]; + if (!isset($options['seed'])) { + if(is_numeric($this->_parent->_options[$this->_func]['seed'])&&$this->_parent->_options[$this->_func]['seed']<255) + $options['seed'] = $this->_parent->_options[$this->_func]['seed']; + else + $options['seed'] = ord(substr($data, 0, 1)); + } elseif (!is_numeric($options['seed'])) { + $options['seed'] = ord(substr($data, 0, 1)); + } + if (!isset($options['length'])) { + if(is_numeric($this->_parent->_options[$this->_func]['length'])&&$this->_parent->_options[$this->_func]['length']>1) + $options['length'] = $this->_parent->_options[$this->_func]['length']; + else + $options['length'] = 28; + } + set_time_limit(120); + $crc = new $this->_class($data, $options['seed'], $options['length']); + return $crc->crc; + } +} + +/** + * A md5 checksum wrapper class for hashing data statically. + * + * @abstract + */ +class XoopsHashXoopscrcStatic extends XoopsHashXoopscrc +{ + function __construct($data, $options, $parent, $mode = 'inhertit') { + return parent::__construct($data, $options, $parent, 'static'); + } +} +?> \ No newline at end of file Added: ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopshash.php =================================================================== --- ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopshash.php (rev 0) +++ ThirdParty/checksums/xoopshash/htdocs/class/hash/xoopshash.php 2012-09-08 03:27:00 UTC (rev 10154) @@ -0,0 +1,210 @@ +<?php +/** + * XOOPS checksum handler + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package kernel + * @since 2.5.5 + * @author Simon Roberts (AKA wishcraft) http://www.chronolabs.com.au/ + * @version $Id: xoopshash.php 8066 2012-09-08 12:19:00Z wishcraft $ + */ + +/** + * A checksum Class for hashing data. + * + * @abstract + */ +class XoopsHash { + + // Child Checksum/Hash Storage + var $_class = array(); + + // Errors Storage Mechanism + var $_errors = array(); + + // Last Checksum Calculated + var $_crc = ''; + + // Last Type Hashes/Checksums Used + var $_type = 'md5'; + + // Default Options for the Preset Hashes/Checksums + var $_options = array( 'md5' => array(), + 'sha1' => array(), + 'xoopscrc' => array('seed'=>'ord(0)', 'length' => 28), + 'password' => array('seed'=>'ord(0)', 'length' => 12) ); + + private static $_vars = array( 'class' => array(), + 'crc' => '', + 'type' => 'md5', + 'options' => array( 'md5' => array(), + 'sha1' => array(), + 'xoopscrc' => array('seed'=>'ord(0)', 'length' => 28), + 'password' => array('seed'=>'ord(0)', 'length' => 12)) + ); + + /** + * Constructor + * + * @param string $data + * @param string $type + * @param array $options + */ + function __construct($data = '', $type = '', $options = '') { + if (empty($type)) + $type = $this->_type; + else + $this->_type = $type; + if (empty($options)&&isset($this->_options[$type])) + $options = $this->_options[$type]; + if ($this->setType($type, $data, $options)) { + if (!empty($data)&&!empty($this->_crc)) + return $this->_crc; + } + return $this; + } + + /** + * function __call + * magic method for calling checksum types as a function + * + * ie. + * $xoopsHash = new XoopsHash(); // Instanciate the Object + * $xoopsHash->md5($data); // Returns MD5 Checksum + * $xoopsHash->sha1($data); // Returns SHA1 Checksum + * $xoopsHash->xoopscrc($data); // Returns XoopsCrc Checksum + * $xoopsHash->password($data); // Returns Password Checksum + * + * @param string $type + * @param array $args + */ + function __call($type, $args) { + if (empty($args[1])&&isset($this->_options[$type])) + $args[1] = $this->_options[$type]; + return $this->calc($args[0], $type, $args[1]); + } + + /** + * function __callStatic + * magic method for calling checksum statically as types in function + * + * ie. + * XoopsHash::md5($data); // Returns MD5 Checksum + * XoopsHash::sha1($data); // Returns SHA1 Checksum + * XoopsHash::xoopscrc($data); // Returns XoopsCrc Checksum + * XoopsHash::password($data); // Returns Password Checksum + * + * @param string $type + * @param array $args + */ + function __callStatic($type, $args) { + if (empty($args[1])&&isset(self::$_vars['options'][$type])) + $args[1] = self::$_vars['options'][$type]; + return self::calcStatic($args[0], $type, $args[1]); + } + + /** + * function calc + * For calculating a hash/checksum after class is instanciated + * + * @param string $data + * @param string $type + * @param array $options + */ + function calc($data, $type = '', $options = '') { + if (empty($options)&&isset($this->_options[$type])) + $options = $this->_options[$type]; + + if (empty($type)) + $type = $this->_type; + else { + if (isset($this->_class[$type])) { + $this->_type = $type; + } elseif ($this->setType($type, $data, $options)) { + $this->_type = $type; + return $this->_crc; + } + } + if (is_object($this->_class[$type])) + return $this->_class[$type]->calc($data, $options); + else + $this->_errors[] = 'Error: XoopsHash Class Not Set'; + return false; + } + + /** + * function calcStatic + * For calculating a hash/checksum after class is called statically + * + * @param string $data + * @param string $type + * @param array $options + */ + function calcStatic($data, $type = '', $options = '') { + if (empty($options)&&isset(self::$_options[$type])) + $options = self::$_vars['options'][$type]; + return self::setTypeStatic($type, $data, $options); + } + + /** + * private function setType + * For load a child Class and instaniating it + * + * @param string $type + * @param string $data + * @param array $options + */ + private function setType($type, $data, $options) { + if (file_exists(dirname(__FILE__).DS.$type.DS.$type.'.php')) { + include_once(dirname(__FILE__).DS.$type.DS.$type.'.php'); + $class = 'XoopsHash'.ucfirst($type); + if (class_exists($class)) { + $this->_type = $type; + $this->_options[$type] = $options; + $this->_class[$type] = new $class($data, $options, $this); + return true; + } else { + $this->_errors[] = 'Error: XoopsHash Child Class Does not Exist - '.$class.' missing.'; + } + } else { + $this->_errors[] = 'Error: XoopsHash Child Class Definition File Does not Exist - '.DS.$type.DS.$type.'.php missing.'; + } + return false; + } + + /** + * private function setTypeStatic + * For using child class statically + * + * @param string $type + * @param string $data + * @param array $options + */ + private function setTypeStatic($type, $data, $options) { + if (file_exists(dirname(__FILE__).DS.$type.DS.$type.'.php')) { + include_once(dirname(__FILE__).DS.$type.DS.$type.'.php'); + $class = 'XoopsHash'.ucfirst($type).'Static'; + if (class_exists($class)) { + return new $class($data, $options, null, 'static'); + } + } + return false; + } + + /** + * function getErrorsHtml + * Gets the Errors as HTML for xoops_error() Function + * + */ + function getErrorsHtml() { + return implode('<br/>', $this->_errors); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |