cvs: pear /Crypt NumberID.php README Rc4.php package.xml

From: Date: Mon, 23 Jul 2001 09:58:04 +0000
Subject: cvs: pear /Crypt NumberID.php README Rc4.php package.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-332@lists.php.net to get a copy of this message
zyprexia Mon Jul 23 05:58:04 2001 EDT Added files: /pear/Crypt NumberID.php README Rc4.php package.xml Log: Added some Encryption classes to the repository tree. Rc4.php - RC4 chiper encryption class NumberID.php - Number <> ID translation (encryption) class Index: pear/Crypt/NumberID.php +++ pear/Crypt/NumberID.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Dave Mertens <dmertens@zyprexia.com> | // +----------------------------------------------------------------------+ // // $Id: NumberID.php,v 1.1 2001/07/23 09:58:04 zyprexia Exp $ class NumberID { /** * * This is not a real encryption class, but it can be usefull. * * Especialy for eshops it's handy that the user gets another order nr than * the normal used order ID. A regular customer can see if the store is successfull * just by looking at the orderid's. * * This class created an order number that can be used as a referal for the customer. Intern * you can still use the order ID. * * Ofcourse it's possible to make an number of any id. * * The numbers are unique as long ID is below 1000000. */ /** * translate an ID into a number * * @param long $ID - Identifier * @return string containing the number */ function toNumber($ID) { mt_srand(time()); $str = sprintf("%02d", date("m") * 9); $str .= sprintf("%02d", date("s")); $str .= right(sprintf("%04d", date("z") * mt_rand(0, 16)), 4); $str .= right(sprintf("%06d", $ID), 6); $newstr = $str[12] . $str[6] . $str[8] . $str[1] . $str[4] . $str[11] . $str[2]; $newstr .= $str[7] . $str[9] . $str[3] . $str[5] . $str[10] . $str[0] . $str[13]; return $newstr; } /** * translate an number into an ID * * @param string nr - number create by toNumber function * @return long ID - your original ID */ function toId($nr) { return $nr[2] . $nr[8] . $nr[11] . $nr[5] . $nr[0] . $nr[13]; } } // end of NumberID class ?> Index: pear/Crypt/Rc4.php +++ pear/Crypt/Rc4.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Dave Mertens <dmertens@zyprexia.com> | // +----------------------------------------------------------------------+ // // $Id: Rc4.php,v 1.1 2001/07/23 09:58:04 zyprexia Exp $ /***** RC4 stream cipher routines implementation in PHP4 based on code written by Damien Miller <djm@mindrot.org> crypt is used to encrypt AND decrypt the messages! Usage: $key = "pear"; $message = "PEAR rulez!"; $rc4 = new RC4; $rc4->key($key); echo "Original message: $message <br>\n"; $rc4->crypt($message); echo "Encrypted message: $message <br>\n"; $rc4->crypt($message); echo "Decrypted message: $message <br>\n"; *****/ /** * RC4 stream cipher routines implementation in PHP4 based on code written by * Damien Miller <djm@mindrot.org> * * @version 0.1 * @author Dave Mertens <dmertens@zyprexia.com> */ class RC4 { var $s= array(); var $i= 0; var $j= 0; /** * Class Constructor. * * @return bool always true; */ function RC4() { return true; } /** * Assign encryption key to class * * @param string key - Key which will be used for encryption * @return void */ function key(&$key) { $len= strlen($key); for ($this->i = 0; $this->i < 256; $this->i++) { $this->s[$this->i] = $this->i; } $this->j = 0; for ($this->i = 0; $this->i < 256; $this->i++) { $this->j = ($this->j + $this->s[$this->i] + ord($key[$this->i % $len])) % 256; $t = $this->s[$this->i]; $this->s[$this->i] = $this->s[$this->j]; $this->s[$this->j] = $t; } $this->i = $this->j = 0; } /** * Encrypt/decrypt function * * @param string paramstr - string that will encrypted * @return void */ function crypt(&$paramstr) { $len= strlen($paramstr); for ($c= 0; $c < $len; $c++) { $this->i = ($this->i + 1) % 256; $this->j = ($this->j + $this->s[$this->i]) % 256; $t = $this->s[$this->i]; $this->s[$this->i] = $this->s[$this->j]; $this->s[$this->j] = $t; $t = ($this->s[$this->i] + $this->s[$this->j]) % 256; $paramstr[$c] = chr(ord($paramstr[$c]) ^ $this->s[$t]); } } } //end of RC4 class ?> Index: pear/Crypt/package.xml +++ pear/Crypt/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!-- do not use the "Type" attribute here, that one is only for generated package.xml files --> <Package> <Name>Crypt</Name> <Summary>Several encryption classes</Summary> <Maintainer> <Initials>DM</Initials> <Name>Dave Mertens</Name> <Email>dmertens@zyprexia.com</Email> </Maintainer> <Release> <Version>0.1</Version> <Date>2001-07-22</Date> <Notes> This is the first release of the encryption classes. The classes needs to be updated to follow the pear coding standards. </Notes> </Release> <FileList> <Dir>/</Dir> <File>Rc4.php</File> <File>NumberID.php</File> </FileList> </Package>

« previous php.pear.cvs (#332) next »