ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
RC4.php
Go to the documentation of this file.
1<?php
36{
37 // Context
38 var $s = array();
39 var $i = 0;
40 var $j = 0;
41
47 public function __construct($key)
48 {
49 $len = strlen($key);
50
51 for ($this->i = 0; $this->i < 256; $this->i++) {
52 $this->s[$this->i] = $this->i;
53 }
54
55 $this->j = 0;
56 for ($this->i = 0; $this->i < 256; $this->i++) {
57 $this->j = ($this->j + $this->s[$this->i] + ord($key[$this->i % $len])) % 256;
58 $t = $this->s[$this->i];
59 $this->s[$this->i] = $this->s[$this->j];
60 $this->s[$this->j] = $t;
61 }
62 $this->i = $this->j = 0;
63 }
64
72 public function RC4($data)
73 {
74 $len = strlen($data);
75 for ($c = 0; $c < $len; $c++) {
76 $this->i = ($this->i + 1) % 256;
77 $this->j = ($this->j + $this->s[$this->i]) % 256;
78 $t = $this->s[$this->i];
79 $this->s[$this->i] = $this->s[$this->j];
80 $this->s[$this->j] = $t;
81
82 $t = ($this->s[$this->i] + $this->s[$this->j]) % 256;
83
84 $data[$c] = chr(ord($data[$c]) ^ $this->s[$t]);
85 }
86 return $data;
87 }
88}
An exception for terminatinating execution or to throw for unit testing.
__construct($key)
RC4 stream decryption/encryption constrcutor.
Definition: RC4.php:47
RC4($data)
Symmetric decryption/encryption function.
Definition: RC4.php:72
$key
Definition: croninfo.php:18