Source for file rc4crypt.class.php
Documentation is available at rc4crypt.class.php
/* vim: set expandtab shiftwidth=4 softtabstop=4 tabstop=4: */
* RC4Crypt is a petite library that allows you to use RC4
* encryption easily in PHP. It's OO and can produce outputs
* (C) Copyright 2006 Mukul Sabharwal [http://mjsabby.com]
* @link http://rc4crypt.devhome.org
* @author Mukul Sabharwal <mjsabby@gmail.com>
* @version $Id: class.rc4crypt.php,v 3.2 2006/03/10 05:47:24 mukul Exp $
* @copyright Copyright © 2006 Mukul Sabharwal
* @license http://www.gnu.org/copyleft/gpl.html
* The symmetric encryption function
* @param string $pwd Key to encrypt with (can be binary of hex)
* @param string $data Content to be encrypted
* @param bool $ispwdHex Key passed is in hexadecimal or not
function encrypt ($pwd, $data, $ispwdHex = 0)
$pwd = @pack('H*', $pwd); // valid input, please!
for ($i = 0; $i < 256; $i++ )
$key[$i] = ord($pwd[$i % $pwd_length]);
for ($j = $i = 0; $i < 256; $i++ )
$j = ($j + $box[$i] + $key[$i]) % 256;
for ($a = $j = $i = 0; $i < $data_length; $i++ )
$j = ($j + $box[$a]) % 256;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipher .= chr(ord($data[$i]) ^ $k);
* Decryption, recall encryption
* @param string $pwd Key to decrypt with (can be binary of hex)
* @param string $data Content to be decrypted
* @param bool $ispwdHex Key passed is in hexadecimal or not
function decrypt ($pwd, $data, $ispwdHex = 0)
|