You are here

rc4.inc in Simplenews Statistics 6.3

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/

File

includes/rc4.inc
View source
<?php

/**
 * @file
 * 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.
 */
function _simplenews_statistics_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.
 */
function _simplenews_statistics_rc4Decrypt($key, $ct) {
  return _simplenews_statistics_rc4Encrypt($key, $ct);
}

Functions

Namesort descending Description
_simplenews_statistics_rc4Decrypt Decrypt given cipher text using the key with RC4 algorithm. All parameters and return value are in binary format.
_simplenews_statistics_rc4Encrypt Encrypt given plain text using the key with RC4 algorithm. All parameters and return value are in binary format.