The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit b818228d authored by Demian Katz's avatar Demian Katz
Browse files

Eliminated RC4 file from vendor directory in favor of moving code inside wrapper class;

the original code no longer seems to be maintained, so it is not composer-friendly.
parent 42ffe9a7
No related merge requests found
<?php
/**
* RC4 encryption class (wrapper around third-party functions)
* RC4 encryption class (wrapper around code borrowed from a third-party
* developer -- see embedded copyright information on encrypt method)
*
* PHP version 5
*
......@@ -27,10 +28,9 @@
*/
namespace VuFind\Crypt;
require_once APPLICATION_PATH . '/vendor/3rdparty/rc4.php';
/**
* RC4 encryption class (wrapper around third-party functions)
* RC4 encryption class (wrapper around code borrowed from a third-party
* developer -- see embedded copyright information on encrypt method)
*
* @category VuFind2
* @package Crypt
......@@ -51,7 +51,39 @@ class RC4
*/
public static function encrypt($key, $pt)
{
return \rc4Encrypt($key, $pt);
/* RC4 symmetric cipher encryption/decryption
* Copyright (c) 2006 by Ali Farhadi.
* released under the terms of the Gnu Public License.
* see the GPL for details.
*
* Email: ali[at]farhadi[dot]ir
* Website: http://farhadi.ir/
*/
$s = array();
for ($i=0; $i<256; $i++) {
$s[$i] = $i;
}
$j = 0;
$x;
for ($i=0; $i<256; $i++) {
$j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
}
$i = 0;
$j = 0;
$ct = '';
$y;
for ($y=0; $y<strlen($pt); $y++) {
$i = ($i + 1) % 256;
$j = ($j + $s[$i]) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
$ct .= $pt[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
}
return $ct;
}
/**
......@@ -65,6 +97,6 @@ class RC4
*/
public static function decrypt($key, $ct)
{
return \rc4Decrypt($key, $ct);
return static::encrypt($key, $ct);
}
}
<?php
/* RC4 symmetric cipher encryption/decryption
* Copyright (c) 2006 by Ali Farhadi.
* released under the terms of the Gnu Public License.
* see the GPL for details.
*
* Email: ali[at]farhadi[dot]ir
* Website: http://farhadi.ir/
*/
/**
* Encrypt given plain text using the key with RC4 algorithm.
* All parameters and return value are in binary format.
*
* @param string key - secret key for encryption
* @param string pt - plain text to be encrypted
* @return string
*/
function rc4Encrypt($key, $pt) {
$s = array();
for ($i=0; $i<256; $i++) {
$s[$i] = $i;
}
$j = 0;
$x;
for ($i=0; $i<256; $i++) {
$j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
}
$i = 0;
$j = 0;
$ct = '';
$y;
for ($y=0; $y<strlen($pt); $y++) {
$i = ($i + 1) % 256;
$j = ($j + $s[$i]) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
$ct .= $pt[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
}
return $ct;
}
/**
* Decrypt given cipher text using the key with RC4 algorithm.
* All parameters and return value are in binary format.
*
* @param string key - secret key for decryption
* @param string ct - cipher text to be decrypted
* @return string
*/
function rc4Decrypt($key, $ct) {
return rc4Encrypt($key, $ct);
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment