Completed
Push — development ( 362b6c...477849 )
by Nils
08:04
created
includes/libraries/phpcrypt/ciphers/Enigma.php 3 patches
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -46,219 +46,219 @@
 block discarded – undo
46 46
  */
47 47
 class Cipher_Enigma extends Cipher
48 48
 {
49
-	const MASK = 0377;
50
-
51
-	/** @type integer ROTORSZ The size of $t1,$t2,$t3,$deck */
52
-	const ROTORSZ = 256;
53
-
54
-	/** @type array $t1 An array of chars, ROTORSZ size */
55
-	private $t1 = array();
56
-
57
-	/** @type array $t2 An array of chars, ROTORSZ size */
58
-	private $t2 = array();
59
-
60
-	/** @type array $t3 An array of chars, ROTORSZ size */
61
-	private $t3 = array();
62
-
63
-	/** @type array $deck An array of chars, ROTORSZ size */
64
-	private $deck = array();
65
-
66
-	private $n1 = 0;
67
-	private $n2 = 0;
68
-	private $nr1 = 0;
69
-	private $nr2 = 0;
70
-
71
-	/** @type string $xkey Stores the modified key */
72
-	private $xkey = "";
73
-
74
-
75
-	/**
76
-	 * Constructor
77
-	 *
78
-	 * @param string $key The key used for Encryption/Decryption
79
-	 * @return void
80
-	 */
81
-	public function __construct($key)
82
-	{
83
-		parent::__construct(PHP_Crypt::CIPHER_ENIGMA, $key, strlen($key));
84
-
85
-		$this->createKey();
86
-	}
87
-
88
-
89
-	/**
90
-	 * Destructor
91
-	 *
92
-	 * @return void
93
-	 */
94
-	public function __destruct()
95
-	{
96
-		parent::__destruct();
97
-	}
98
-
99
-
100
-	/**
101
-	 * Encrypt plain text data using Enigma
102
-	 *
103
-	 * @param string $str A plain text string of any length
104
-	 * @return boolean Returns true
105
-	 */
106
-	public function encrypt(&$str)
107
-	{
108
-		$this->operation(parent::ENCRYPT);
109
-		return $this->enigma($str);
110
-	}
111
-
112
-
113
-	/**
114
-	 * Decrypt an Enigma encrypted string
115
-	 *
116
-	 * @param string $str A Enigma encrypted string
117
-	 * @return boolean Returns true
118
-	 */
119
-	public function decrypt(&$str)
120
-	{
121
-		$this->operation(parent::DECRYPT);
122
-		return $this->enigma($str);
123
-	}
124
-
125
-
126
-	/**
127
-	 * Peforms the actual Enigma encryption/decryption. Since
128
-	 * the algorithm is the same for both, we do it all in
129
-	 * this one function
130
-	 *
131
-	 * @param string $str A string to encrypt or decrypt
132
-	 * @return boolean Returns true
133
-	 */
134
-	private function enigma(&$str)
135
-	{
136
-		// zero out the counters
137
-		$this->n1 = 0;
138
-		$this->n2 = 0;
139
-		$this->nr1 = 0;
140
-		$this->nr2 = 0;
141
-
142
-		$max = strlen($str);
143
-		for($j = 0; $j < $max; ++$j)
144
-		{
145
-			$i = ord($str[$j]);
146
-			$this->nr1 = $this->n1;
147
-
148
-			$pos1 = ($i + $this->nr1) & self::MASK;
149
-			$pos3 = ($this->t1[$pos1] + $this->nr2) & self::MASK;
150
-			$pos2 = ($this->t3[$pos3] - $this->nr2) & self::MASK;
151
-			$i = $this->t2[$pos2] - $this->nr1;
152
-
153
-			$str[$j] = chr($i);
154
-			$this->n1++;
155
-
156
-			if($this->n1 == self::ROTORSZ)
157
-			{
158
-				$this->n1 = 0;
159
-				$this->n2++;
160
-
161
-				if($this->n2 == self::ROTORSZ)
162
-					$this->n2 = 0;
163
-
164
-				$this->nr2 = $this->n2;
165
-			}
166
-		}
167
-
168
-		return true;
169
-	}
170
-
171
-
172
-	/**
173
-	 * The code for this function was translated to PHP from mcrypt's enigma.c,
174
-	 * I was not able to find sufficient documentation to create my own
175
-	 * version of this function.
176
-	 * Enigma requires a 13 byte key, this function will
177
-	 * lengthen the key to get it to 13 bytes long if it's short. It also
178
-	 * Sets $deck, and $t1, $t2, $t3 which I think are the Enigma rotors.
179
-	 *
180
-	 * @return void
181
-	 */
182
-	private function createKey()
183
-	{
184
-		$this->deck = array();
185
-		$this->t1 = array();
186
-		$this->t2 = array_fill(0, self::ROTORSZ, 0);
187
-		$this->t3 = $this->t2;
188
-		$this->xkey = $this->key();
189
-		$klen = $this->keySize();
190
-
191
-		// get the key to exactly 13 bytes if it's less than 13
192
-		if($klen < 13)
193
-			$this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT);
194
-
195
-		$seed = 123;
196
-		for($i = 0; $i < 13; ++$i)
197
-			$seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i;
198
-
199
-		// sets $t1 and $deck
200
-		for($i = 0; $i < self::ROTORSZ; ++$i)
201
-		{
202
-			$this->t1[] = $i;
203
-			$this->deck[] = $i;
204
-		}
205
-
206
-		// sets $t3
207
-		for($i = 0; $i < self::ROTORSZ; ++$i)
208
-		{
209
-			// make sure the return values are 32 bit
210
-			$seed = 5 * parent::sInt32($seed) + ord($this->xkey[$i % 13]);
211
-			$seed = parent::sInt32($seed);
212
-
213
-			// force the returned value to be an unsigned int
214
-			//$random = parent::uint32($seed % 65521);
215
-			$random = parent::uInt($seed % 65521);
216
-
217
-			$k = self::ROTORSZ - 1 - $i;
218
-			$ic = ($random & self::MASK) % ($k + 1);
219
-
220
-			// make sure the returned value is an unsigned int
221
-			$random = parent::uInt($random >> 8);
222
-
223
-			$temp = $this->t1[$k];
224
-			$this->t1[$k] = $this->t1[$ic];
225
-			$this->t1[$ic] = $temp;
226
-			if($this->t3[$k] != 0)
227
-				continue;
228
-
229
-			$ic = ($random & self::MASK) % $k;
230
-			while($this->t3[$ic] != 0)
231
-				$ic = ($ic + 1) % $k;
232
-
233
-			$this->t3[$k] = $ic;
234
-			$this->t3[$ic] = $k;
235
-		}
236
-
237
-		// sets $t2
238
-		for($i = 0; $i < self::ROTORSZ; ++$i)
239
-		{
240
-			$pos = $this->t1[$i] & self::MASK;
241
-			$this->t2[$pos] = $i;
242
-		}
243
-
244
-		// now convert $t1, $t2, $t3, $deck values to signed chars,
245
-		// PHP's chr() function returns an unsigned char, so we have
246
-		// to use use our own
247
-		$this->t1   = array_map("parent::sChar", $this->t1);
248
-		$this->t2   = array_map("parent::sChar", $this->t2);
249
-		$this->t3   = array_map("parent::sChar", $this->t3);
250
-		$this->deck = array_map("parent::sChar", $this->deck);
251
-	}
252
-
253
-
254
-	/**
255
-	 * Indicates this is a stream cipher
256
-	 *
257
-	 * @return integer Returns Cipher::STREAM
258
-	 */
259
-	public function type()
260
-	{
261
-		return parent::STREAM;
262
-	}
49
+    const MASK = 0377;
50
+
51
+    /** @type integer ROTORSZ The size of $t1,$t2,$t3,$deck */
52
+    const ROTORSZ = 256;
53
+
54
+    /** @type array $t1 An array of chars, ROTORSZ size */
55
+    private $t1 = array();
56
+
57
+    /** @type array $t2 An array of chars, ROTORSZ size */
58
+    private $t2 = array();
59
+
60
+    /** @type array $t3 An array of chars, ROTORSZ size */
61
+    private $t3 = array();
62
+
63
+    /** @type array $deck An array of chars, ROTORSZ size */
64
+    private $deck = array();
65
+
66
+    private $n1 = 0;
67
+    private $n2 = 0;
68
+    private $nr1 = 0;
69
+    private $nr2 = 0;
70
+
71
+    /** @type string $xkey Stores the modified key */
72
+    private $xkey = "";
73
+
74
+
75
+    /**
76
+     * Constructor
77
+     *
78
+     * @param string $key The key used for Encryption/Decryption
79
+     * @return void
80
+     */
81
+    public function __construct($key)
82
+    {
83
+        parent::__construct(PHP_Crypt::CIPHER_ENIGMA, $key, strlen($key));
84
+
85
+        $this->createKey();
86
+    }
87
+
88
+
89
+    /**
90
+     * Destructor
91
+     *
92
+     * @return void
93
+     */
94
+    public function __destruct()
95
+    {
96
+        parent::__destruct();
97
+    }
98
+
99
+
100
+    /**
101
+     * Encrypt plain text data using Enigma
102
+     *
103
+     * @param string $str A plain text string of any length
104
+     * @return boolean Returns true
105
+     */
106
+    public function encrypt(&$str)
107
+    {
108
+        $this->operation(parent::ENCRYPT);
109
+        return $this->enigma($str);
110
+    }
111
+
112
+
113
+    /**
114
+     * Decrypt an Enigma encrypted string
115
+     *
116
+     * @param string $str A Enigma encrypted string
117
+     * @return boolean Returns true
118
+     */
119
+    public function decrypt(&$str)
120
+    {
121
+        $this->operation(parent::DECRYPT);
122
+        return $this->enigma($str);
123
+    }
124
+
125
+
126
+    /**
127
+     * Peforms the actual Enigma encryption/decryption. Since
128
+     * the algorithm is the same for both, we do it all in
129
+     * this one function
130
+     *
131
+     * @param string $str A string to encrypt or decrypt
132
+     * @return boolean Returns true
133
+     */
134
+    private function enigma(&$str)
135
+    {
136
+        // zero out the counters
137
+        $this->n1 = 0;
138
+        $this->n2 = 0;
139
+        $this->nr1 = 0;
140
+        $this->nr2 = 0;
141
+
142
+        $max = strlen($str);
143
+        for($j = 0; $j < $max; ++$j)
144
+        {
145
+            $i = ord($str[$j]);
146
+            $this->nr1 = $this->n1;
147
+
148
+            $pos1 = ($i + $this->nr1) & self::MASK;
149
+            $pos3 = ($this->t1[$pos1] + $this->nr2) & self::MASK;
150
+            $pos2 = ($this->t3[$pos3] - $this->nr2) & self::MASK;
151
+            $i = $this->t2[$pos2] - $this->nr1;
152
+
153
+            $str[$j] = chr($i);
154
+            $this->n1++;
155
+
156
+            if($this->n1 == self::ROTORSZ)
157
+            {
158
+                $this->n1 = 0;
159
+                $this->n2++;
160
+
161
+                if($this->n2 == self::ROTORSZ)
162
+                    $this->n2 = 0;
163
+
164
+                $this->nr2 = $this->n2;
165
+            }
166
+        }
167
+
168
+        return true;
169
+    }
170
+
171
+
172
+    /**
173
+     * The code for this function was translated to PHP from mcrypt's enigma.c,
174
+     * I was not able to find sufficient documentation to create my own
175
+     * version of this function.
176
+     * Enigma requires a 13 byte key, this function will
177
+     * lengthen the key to get it to 13 bytes long if it's short. It also
178
+     * Sets $deck, and $t1, $t2, $t3 which I think are the Enigma rotors.
179
+     *
180
+     * @return void
181
+     */
182
+    private function createKey()
183
+    {
184
+        $this->deck = array();
185
+        $this->t1 = array();
186
+        $this->t2 = array_fill(0, self::ROTORSZ, 0);
187
+        $this->t3 = $this->t2;
188
+        $this->xkey = $this->key();
189
+        $klen = $this->keySize();
190
+
191
+        // get the key to exactly 13 bytes if it's less than 13
192
+        if($klen < 13)
193
+            $this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT);
194
+
195
+        $seed = 123;
196
+        for($i = 0; $i < 13; ++$i)
197
+            $seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i;
198
+
199
+        // sets $t1 and $deck
200
+        for($i = 0; $i < self::ROTORSZ; ++$i)
201
+        {
202
+            $this->t1[] = $i;
203
+            $this->deck[] = $i;
204
+        }
205
+
206
+        // sets $t3
207
+        for($i = 0; $i < self::ROTORSZ; ++$i)
208
+        {
209
+            // make sure the return values are 32 bit
210
+            $seed = 5 * parent::sInt32($seed) + ord($this->xkey[$i % 13]);
211
+            $seed = parent::sInt32($seed);
212
+
213
+            // force the returned value to be an unsigned int
214
+            //$random = parent::uint32($seed % 65521);
215
+            $random = parent::uInt($seed % 65521);
216
+
217
+            $k = self::ROTORSZ - 1 - $i;
218
+            $ic = ($random & self::MASK) % ($k + 1);
219
+
220
+            // make sure the returned value is an unsigned int
221
+            $random = parent::uInt($random >> 8);
222
+
223
+            $temp = $this->t1[$k];
224
+            $this->t1[$k] = $this->t1[$ic];
225
+            $this->t1[$ic] = $temp;
226
+            if($this->t3[$k] != 0)
227
+                continue;
228
+
229
+            $ic = ($random & self::MASK) % $k;
230
+            while($this->t3[$ic] != 0)
231
+                $ic = ($ic + 1) % $k;
232
+
233
+            $this->t3[$k] = $ic;
234
+            $this->t3[$ic] = $k;
235
+        }
236
+
237
+        // sets $t2
238
+        for($i = 0; $i < self::ROTORSZ; ++$i)
239
+        {
240
+            $pos = $this->t1[$i] & self::MASK;
241
+            $this->t2[$pos] = $i;
242
+        }
243
+
244
+        // now convert $t1, $t2, $t3, $deck values to signed chars,
245
+        // PHP's chr() function returns an unsigned char, so we have
246
+        // to use use our own
247
+        $this->t1   = array_map("parent::sChar", $this->t1);
248
+        $this->t2   = array_map("parent::sChar", $this->t2);
249
+        $this->t3   = array_map("parent::sChar", $this->t3);
250
+        $this->deck = array_map("parent::sChar", $this->deck);
251
+    }
252
+
253
+
254
+    /**
255
+     * Indicates this is a stream cipher
256
+     *
257
+     * @return integer Returns Cipher::STREAM
258
+     */
259
+    public function type()
260
+    {
261
+        return parent::STREAM;
262
+    }
263 263
 }
264 264
 ?>
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		$this->nr2 = 0;
141 141
 
142 142
 		$max = strlen($str);
143
-		for($j = 0; $j < $max; ++$j)
143
+		for ($j = 0; $j < $max; ++$j)
144 144
 		{
145 145
 			$i = ord($str[$j]);
146 146
 			$this->nr1 = $this->n1;
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
 			$str[$j] = chr($i);
154 154
 			$this->n1++;
155 155
 
156
-			if($this->n1 == self::ROTORSZ)
156
+			if ($this->n1 == self::ROTORSZ)
157 157
 			{
158 158
 				$this->n1 = 0;
159 159
 				$this->n2++;
160 160
 
161
-				if($this->n2 == self::ROTORSZ)
161
+				if ($this->n2 == self::ROTORSZ)
162 162
 					$this->n2 = 0;
163 163
 
164 164
 				$this->nr2 = $this->n2;
@@ -189,22 +189,22 @@  discard block
 block discarded – undo
189 189
 		$klen = $this->keySize();
190 190
 
191 191
 		// get the key to exactly 13 bytes if it's less than 13
192
-		if($klen < 13)
192
+		if ($klen < 13)
193 193
 			$this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT);
194 194
 
195 195
 		$seed = 123;
196
-		for($i = 0; $i < 13; ++$i)
196
+		for ($i = 0; $i < 13; ++$i)
197 197
 			$seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i;
198 198
 
199 199
 		// sets $t1 and $deck
200
-		for($i = 0; $i < self::ROTORSZ; ++$i)
200
+		for ($i = 0; $i < self::ROTORSZ; ++$i)
201 201
 		{
202 202
 			$this->t1[] = $i;
203 203
 			$this->deck[] = $i;
204 204
 		}
205 205
 
206 206
 		// sets $t3
207
-		for($i = 0; $i < self::ROTORSZ; ++$i)
207
+		for ($i = 0; $i < self::ROTORSZ; ++$i)
208 208
 		{
209 209
 			// make sure the return values are 32 bit
210 210
 			$seed = 5 * parent::sInt32($seed) + ord($this->xkey[$i % 13]);
@@ -223,11 +223,11 @@  discard block
 block discarded – undo
223 223
 			$temp = $this->t1[$k];
224 224
 			$this->t1[$k] = $this->t1[$ic];
225 225
 			$this->t1[$ic] = $temp;
226
-			if($this->t3[$k] != 0)
226
+			if ($this->t3[$k] != 0)
227 227
 				continue;
228 228
 
229 229
 			$ic = ($random & self::MASK) % $k;
230
-			while($this->t3[$ic] != 0)
230
+			while ($this->t3[$ic] != 0)
231 231
 				$ic = ($ic + 1) % $k;
232 232
 
233 233
 			$this->t3[$k] = $ic;
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 		}
236 236
 
237 237
 		// sets $t2
238
-		for($i = 0; $i < self::ROTORSZ; ++$i)
238
+		for ($i = 0; $i < self::ROTORSZ; ++$i)
239 239
 		{
240 240
 			$pos = $this->t1[$i] & self::MASK;
241 241
 			$this->t2[$pos] = $i;
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -158,8 +158,9 @@  discard block
 block discarded – undo
158 158
 				$this->n1 = 0;
159 159
 				$this->n2++;
160 160
 
161
-				if($this->n2 == self::ROTORSZ)
162
-					$this->n2 = 0;
161
+				if($this->n2 == self::ROTORSZ) {
162
+									$this->n2 = 0;
163
+				}
163 164
 
164 165
 				$this->nr2 = $this->n2;
165 166
 			}
@@ -189,12 +190,14 @@  discard block
 block discarded – undo
189 190
 		$klen = $this->keySize();
190 191
 
191 192
 		// get the key to exactly 13 bytes if it's less than 13
192
-		if($klen < 13)
193
-			$this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT);
193
+		if($klen < 13) {
194
+					$this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT);
195
+		}
194 196
 
195 197
 		$seed = 123;
196
-		for($i = 0; $i < 13; ++$i)
197
-			$seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i;
198
+		for($i = 0; $i < 13; ++$i) {
199
+					$seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i;
200
+		}
198 201
 
199 202
 		// sets $t1 and $deck
200 203
 		for($i = 0; $i < self::ROTORSZ; ++$i)
@@ -223,12 +226,14 @@  discard block
 block discarded – undo
223 226
 			$temp = $this->t1[$k];
224 227
 			$this->t1[$k] = $this->t1[$ic];
225 228
 			$this->t1[$ic] = $temp;
226
-			if($this->t3[$k] != 0)
227
-				continue;
229
+			if($this->t3[$k] != 0) {
230
+							continue;
231
+			}
228 232
 
229 233
 			$ic = ($random & self::MASK) % $k;
230
-			while($this->t3[$ic] != 0)
231
-				$ic = ($ic + 1) % $k;
234
+			while($this->t3[$ic] != 0) {
235
+							$ic = ($ic + 1) % $k;
236
+			}
232 237
 
233 238
 			$this->t3[$k] = $ic;
234 239
 			$this->t3[$ic] = $k;
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/Rijndael256.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -38,39 +38,39 @@
 block discarded – undo
38 38
  */
39 39
 class Cipher_Rijndael_256 extends Cipher_Rijndael
40 40
 {
41
-	/** @type integer BYTES_BLOCK The size of the block, in bytes */
42
-	const BYTES_BLOCK = 32; // 256 bits
41
+    /** @type integer BYTES_BLOCK The size of the block, in bytes */
42
+    const BYTES_BLOCK = 32; // 256 bits
43 43
 
44
-	//const BITS_KEY = 0;
44
+    //const BITS_KEY = 0;
45 45
 
46 46
 
47
-	/**
48
-	 * Constructor
49
-	 * Sets the key used for encryption. Also sets the requied block size
50
-	 *
51
-	 * @param string $key string containing the user supplied encryption key
52
-	 * @return void
53
-	 */
54
-	public function __construct($key)
55
-	{
56
-		// Set up the key
57
-		parent::__construct(PHP_Crypt::CIPHER_RIJNDAEL_256, $key);
47
+    /**
48
+     * Constructor
49
+     * Sets the key used for encryption. Also sets the requied block size
50
+     *
51
+     * @param string $key string containing the user supplied encryption key
52
+     * @return void
53
+     */
54
+    public function __construct($key)
55
+    {
56
+        // Set up the key
57
+        parent::__construct(PHP_Crypt::CIPHER_RIJNDAEL_256, $key);
58 58
 
59
-		// required block size in bits
60
-		$this->blockSize(self::BYTES_BLOCK);
59
+        // required block size in bits
60
+        $this->blockSize(self::BYTES_BLOCK);
61 61
 
62
-		// expand the key now that we know the key size, and the bit size
63
-		$this->expandKey();
64
-	}
62
+        // expand the key now that we know the key size, and the bit size
63
+        $this->expandKey();
64
+    }
65 65
 
66 66
 
67
-	/**
68
-	 * Destructor
69
-	 *
70
-	 * @return void
71
-	 */
72
-	public function __destruct()
73
-	{
74
-		parent::__destruct();
75
-	}
67
+    /**
68
+     * Destructor
69
+     *
70
+     * @return void
71
+     */
72
+    public function __destruct()
73
+    {
74
+        parent::__destruct();
75
+    }
76 76
 }
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/AES128.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -38,34 +38,34 @@
 block discarded – undo
38 38
  */
39 39
 class Cipher_AES_128 extends Cipher_Rijndael_128
40 40
 {
41
-	/** @type integer BYTES_BLOCK The size of the block, in bytes */
42
-	const BYTES_BLOCK = 16; //128 bits;
41
+    /** @type integer BYTES_BLOCK The size of the block, in bytes */
42
+    const BYTES_BLOCK = 16; //128 bits;
43 43
 
44
-	/** @type integer BYTES_KEY The size of the key, in bytes */
45
-	const BYTES_KEY = 16; // 128 bits;
44
+    /** @type integer BYTES_KEY The size of the key, in bytes */
45
+    const BYTES_KEY = 16; // 128 bits;
46 46
 
47
-	/**
48
-	 * Constructor, Sets the key used for encryption.
49
-	 *
50
-	 * @param string $key string containing the user supplied encryption key
51
-	 * @return void
52
-	 */
53
-	public function __construct($key)
54
-	{
55
-		// Setup AES by calling the second constructor in Rijndael_128
56
-		// The block size is set here too, since all AES implementations use 128 bit blocks
57
-		parent::__construct1(PHP_Crypt::CIPHER_AES_128, $key, self::BYTES_KEY);
58
-	}
47
+    /**
48
+     * Constructor, Sets the key used for encryption.
49
+     *
50
+     * @param string $key string containing the user supplied encryption key
51
+     * @return void
52
+     */
53
+    public function __construct($key)
54
+    {
55
+        // Setup AES by calling the second constructor in Rijndael_128
56
+        // The block size is set here too, since all AES implementations use 128 bit blocks
57
+        parent::__construct1(PHP_Crypt::CIPHER_AES_128, $key, self::BYTES_KEY);
58
+    }
59 59
 
60 60
 
61
-	/**
62
-	 * Destructor
63
-	 *
64
-	 * @return void
65
-	 */
66
-	public function __destruct()
67
-	{
68
-		parent::__destruct();
69
-	}
61
+    /**
62
+     * Destructor
63
+     *
64
+     * @return void
65
+     */
66
+    public function __destruct()
67
+    {
68
+        parent::__destruct();
69
+    }
70 70
 }
71 71
 ?>
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/Blowfish.php 3 patches
Indentation   +550 added lines, -550 removed lines patch added patch discarded remove patch
@@ -40,563 +40,563 @@
 block discarded – undo
40 40
  */
41 41
 class Cipher_Blowfish extends Cipher
42 42
 {
43
-	/** @type integer BYTES_BLOCK The size of the block, in bytes */
44
-	const BYTES_BLOCK = 8; // 64 bits;
43
+    /** @type integer BYTES_BLOCK The size of the block, in bytes */
44
+    const BYTES_BLOCK = 8; // 64 bits;
45 45
 
46
-	// a variable length key, between 8 - 448 bits
47
-	//const BYTES_KEY = 0;
46
+    // a variable length key, between 8 - 448 bits
47
+    //const BYTES_KEY = 0;
48 48
 
49
-	/** @type array $_sbox1 S-Box 1 */
50
-	private static $_sbox1 = array();
49
+    /** @type array $_sbox1 S-Box 1 */
50
+    private static $_sbox1 = array();
51 51
 
52
-	/** @type string $_sbox2 S-Box 2 */
53
-	private static $_sbox2 = array();
52
+    /** @type string $_sbox2 S-Box 2 */
53
+    private static $_sbox2 = array();
54 54
 
55
-	/** @type string $_sbox3 S-Box 3 */
56
-	private static $_sbox3 = array();
55
+    /** @type string $_sbox3 S-Box 3 */
56
+    private static $_sbox3 = array();
57 57
 
58
-	/** @type string $_sbox4 S-Box 4 */
59
-	private static $_sbox4 = array();
58
+    /** @type string $_sbox4 S-Box 4 */
59
+    private static $_sbox4 = array();
60 60
 
61
-	/** @type array $_p The P-Array, 18 elements long */
62
-	private static $_p = array();
61
+    /** @type array $_p The P-Array, 18 elements long */
62
+    private static $_p = array();
63 63
 
64
-	/** @type integer $key_pos Used for keyChunk(), to determine the current
64
+    /** @type integer $key_pos Used for keyChunk(), to determine the current
65 65
 	position in the key */
66
-	private $key_pos = 0;
67
-
68
-	/**
69
-	 * Constructor
70
-	 *
71
-	 * @param string $key The key used for Encryption/Decryption
72
-	 * @return void
73
-	 */
74
-	public function __construct($key)
75
-	{
76
-		// the max length of the key is 448 bits (56 bytes)
77
-		$keylen = strlen($key);
78
-		if($keylen > 56)
79
-		{
80
-			$key = substr($key, 0, 56);
81
-			$keylen = 56;
82
-		}
83
-		else if($keylen < 1)
84
-		{
85
-			$msg  = "No key given. The key must be between 1 - 56 bytes.";
86
-			trigger_error($msg, E_USER_WARNING);
87
-		}
88
-
89
-		// set the key, make sure the required length is set in bits
90
-		parent::__construct(PHP_Crypt::CIPHER_BLOWFISH, $key, $keylen);
91
-
92
-		// set the block size
93
-		$this->blockSize(self::BYTES_BLOCK);
94
-
95
-		$this->initTables();
96
-		$this->subKeys();
97
-	}
98
-
99
-
100
-	/**
101
-	 * Destructor
102
-	 *
103
-	 * @return void
104
-	 */
105
-	public function __destruct()
106
-	{
107
-		parent::__destruct();
108
-	}
109
-
110
-
111
-	/**
112
-	 * Encrypt plain text data
113
-	 *
114
-	 * @param string $data A 64 bit (8 byte) plain text string
115
-	 * @return boolean Returns true
116
-	 */
117
-	public function encrypt(&$data)
118
-	{
119
-		$this->operation(parent::ENCRYPT);
120
-		return $this->blowfish($data);
121
-	}
122
-
123
-
124
-	/**
125
-	 * Decrypt an encrypted string
126
-	 *
127
-	 * @param string $data A 64 bit block of Blowfish encrypted data
128
-	 * @return boolean Returns true
129
-	 */
130
-	public function decrypt(&$data)
131
-	{
132
-		$this->operation(parent::DECRYPT);
133
-		return $this->blowfish($data);
134
-	}
135
-
136
-
137
-	/**
138
-	 * The same alorigthm is used for both Encryption, and Decryption
139
-	 *
140
-	 * @param string $data A 64 bit block of data
141
-	 * @return boolean Returns true
142
-	 */
143
-	private function blowfish(&$data)
144
-	{
145
-		// divide the data into into two 32 bit halves
146
-		$xl = parent::str2Dec(substr($data, 0, 4));
147
-		$xr = parent::str2Dec(substr($data, 4, 4));
148
-
149
-		for($i = 0; $i < 16; ++$i)
150
-		{
151
-			if($this->operation() == parent::ENCRYPT)
152
-				$xl ^= self::$_p[$i];
153
-			else
154
-				$xl ^= self::$_p[17-$i];
155
-
156
-			// perform F() on the left half, and XOR with the right half
157
-			$xr = $this->F($xl) ^ $xr;
158
-
159
-			// swap $xl and $xr
160
-			$tmp = $xr;
161
-			$xr = $xl;
162
-			$xl = $tmp;
163
-		}
164
-
165
-		// swap $xl and $xr after the 16th round to undo the last swap
166
-		$tmp = $xl;
167
-		$xl  = $xr;
168
-		$xr  = $tmp;
169
-
170
-		// XOR the final two elements of $_p
171
-		if($this->operation() == parent::ENCRYPT)
172
-		{
173
-			$xr ^= self::$_p[16];
174
-			$xl  = $xl ^ self::$_p[17];
175
-		}
176
-		else // parent::DECRYPT
177
-		{
178
-			$xr ^= self::$_p[1];
179
-			$xl ^= self::$_p[0];
180
-		}
181
-
182
-		// recombine the two halves, force them to be 4 bytes each
183
-		$data = parent::dec2Str($xl, 4).parent::dec2Str($xr, 4);
184
-
185
-		return true;
186
-	}
187
-
188
-
189
-	/**
190
-	 * Blowfish's F() function
191
-	 *
192
-	 * @param string $i A 32 bit integer
193
-	 */
194
-	private function F($i)
195
-	{
196
-		// split the 32 bits into four 8 bit parts
197
-		$x[0] = $i & 0xff; // first byte
198
-		$x[1] = ($i >> 8)  & 0xff; // second byte
199
-		$x[2] = ($i >> 16) & 0xff; // third byte
200
-		$x[3] = ($i >> 24) & 0xff; // fourth byte
201
-
202
-		// perform F(), make sure all values returned are
203
-		// unsigned 32 bit
204
-		$f  = parent::uInt32(self::$_sbox1[$x[3]] + self::$_sbox2[$x[2]]);
205
-		$f  = parent::uInt32($f ^ self::$_sbox3[$x[1]]);
206
-		$f  = parent::uInt32($f + self::$_sbox4[$x[0]]);
207
-
208
-		return $f;
209
-	}
210
-
211
-
212
-	/**
213
-	 * Generates the subkeys used in Blowfish
214
-	 *
215
-	 * @return void
216
-	 */
217
-	private function subKeys()
218
-	{
219
-		// now xor each element of $_p with 32 bits from the key
220
-		for($i = 0; $i < 18; ++$i)
221
-		{
222
-			$c = $this->keyChunk(4);
223
-			self::$_p[$i] ^= parent::str2Dec($c);
224
-		}
225
-
226
-		// start with an 8 byte null string
227
-		$zero = "\0\0\0\0\0\0\0\0";
228
-
229
-		// now we loop, each loop replacing elements of $_p, or an $_sbox with the
230
-		// repeatedly encrypted zero string
231
-		for($i = 0; $i < 1042; $i += 2)
232
-		{
233
-			// encrypt the 64 bit null string
234
-			$this->encrypt($zero);
235
-
236
-			// split the encrypted null string into two 32 bit parts
237
-			$z0 = parent::str2Dec(substr($zero, 0, 4));
238
-			$z1 = parent::str2Dec(substr($zero, 4, 4));
239
-
240
-			// now fill the $_p, $_sbox1, $_sbox2, $_sbox3, $_sbox4
241
-			// with 4 bytes from the repeatedly encrypted 8 byte null string
242
-			if($i < 18)
243
-			{
244
-				self::$_p[$i] = $z0;
245
-				self::$_p[$i + 1] = $z1;
246
-			}
247
-			else if($i >= 18 && $i < 274)
248
-			{
249
-				self::$_sbox1[$i - 18] = $z0;
250
-				self::$_sbox1[$i - 18 + 1] = $z1;
251
-			}
252
-			else if($i >= 274 && $i < 530)
253
-			{
254
-				self::$_sbox2[$i - 274] = $z0;
255
-				self::$_sbox2[$i - 274 + 1] = $z1;
256
-			}
257
-			else if($i >= 530 && $i < 786)
258
-			{
259
-				self::$_sbox3[$i - 530] = $z0;
260
-				self::$_sbox3[$i - 530 + 1] = $z1;
261
-			}
262
-			else if($i >= 786 && $i < 1042)
263
-			{
264
-				self::$_sbox4[$i -786] = $z0;
265
-				self::$_sbox4[$i - 786 + 1] = $z1;
266
-			}
267
-		}
268
-	}
269
-
270
-
271
-	/**
272
-	 * Returns a substring of $this->key. The size of the substring is set in the
273
-	 * parameter $size. Each call to this function returns a substring starting
274
-	 * in the position where the last substring ended. Effectively it rotates
275
-	 * through the key, when it reaches the end, it starts over at the
276
-	 * beginning of the key and continues on. You can reset the current position
277
-	 * by setting the parameter $reset=true, which will start the key back at the
278
-	 * first byte of the $this->key string.
279
-	 *
280
-	 * @param integer $size The size of the substring to return, in bytes
281
-	 * @param bool $reset If set to true, sets the position back to 0, the first
282
-	 *	byte of the key string
283
-	 * @return string The next substring of the key
284
-	 */
285
-	private function keyChunk($size = 1, $reset = false)
286
-	{
287
-		if($reset || $this->key_pos >= $this->keySize())
288
-			$this->key_pos = 0;
289
-
290
-		$bytes = substr($this->key(), $this->key_pos, $size);
291
-		$len = strlen($bytes);
292
-		if($len < $size)
293
-		{
294
-			$bytes .= substr($this->key(), 0, $size - $len);
295
-			$this->key_pos = $size - $len;
296
-		}
297
-		else
298
-			$this->key_pos += $size;
299
-
300
-		return $bytes;
301
-	}
302
-
303
-
304
-	/**
305
-	 * Initialize the tables used in Blowfish Encryption. These
306
-	 * are calculated from the value of PI. We grabbed
307
-	 * these from the mcrypt blowfish source, which already had
308
-	 * these values calculated
309
-	 *
310
-	 * @return void
311
-	 */
312
-	private function initTables()
313
-	{
314
-		self::$_sbox1 = array(
315
-			0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
316
-			0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
317
-			0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
318
-			0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
319
-			0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
320
-			0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
321
-			0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
322
-			0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
323
-			0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
324
-			0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
325
-			0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
326
-			0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
327
-			0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
328
-			0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
329
-			0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
330
-			0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
331
-			0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
332
-			0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
333
-			0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
334
-			0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
335
-			0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
336
-			0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
337
-			0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
338
-			0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
339
-			0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
340
-			0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
341
-			0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
342
-			0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
343
-			0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
344
-			0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
345
-			0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
346
-			0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
347
-			0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
348
-			0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
349
-			0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
350
-			0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
351
-			0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
352
-			0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
353
-			0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
354
-			0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
355
-			0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
356
-			0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
357
-			0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
358
-			0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
359
-			0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
360
-			0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
361
-			0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
362
-			0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
363
-			0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
364
-			0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
365
-			0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
366
-			0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
367
-			0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
368
-			0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
369
-			0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
370
-			0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
371
-			0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
372
-			0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
373
-			0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
374
-			0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
375
-			0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
376
-			0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
377
-			0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
378
-			0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
379
-		);
380
-
381
-		self::$_sbox2 = array(
382
-			0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
383
-			0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
384
-			0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
385
-			0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
386
-			0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
387
-			0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
388
-			0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
389
-			0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
390
-			0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
391
-			0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
392
-			0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
393
-			0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
394
-			0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
395
-			0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
396
-			0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
397
-			0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
398
-			0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
399
-			0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
400
-			0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
401
-			0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
402
-			0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
403
-			0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
404
-			0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
405
-			0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
406
-			0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
407
-			0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
408
-			0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
409
-			0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
410
-			0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
411
-			0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
412
-			0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
413
-			0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
414
-			0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
415
-			0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
416
-			0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
417
-			0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
418
-			0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
419
-			0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
420
-			0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
421
-			0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
422
-			0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
423
-			0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
424
-			0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
425
-			0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
426
-			0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
427
-			0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
428
-			0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
429
-			0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
430
-			0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
431
-			0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
432
-			0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
433
-			0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
434
-			0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
435
-			0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
436
-			0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
437
-			0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
438
-			0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
439
-			0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
440
-			0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
441
-			0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
442
-			0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
443
-			0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
444
-			0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
445
-			0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
446
-		);
447
-
448
-		self::$_sbox3 = array(
449
-			0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
450
-			0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
451
-			0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
452
-			0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
453
-			0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
454
-			0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
455
-			0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
456
-			0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
457
-			0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
458
-			0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
459
-			0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
460
-			0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
461
-			0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
462
-			0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
463
-			0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
464
-			0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
465
-			0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
466
-			0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
467
-			0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
468
-			0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
469
-			0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
470
-			0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
471
-			0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
472
-			0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
473
-			0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
474
-			0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
475
-			0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
476
-			0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
477
-			0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
478
-			0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
479
-			0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
480
-			0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
481
-			0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
482
-			0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
483
-			0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
484
-			0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
485
-			0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
486
-			0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
487
-			0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
488
-			0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
489
-			0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
490
-			0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
491
-			0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
492
-			0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
493
-			0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
494
-			0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
495
-			0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
496
-			0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
497
-			0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
498
-			0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
499
-			0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
500
-			0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
501
-			0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
502
-			0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
503
-			0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
504
-			0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
505
-			0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
506
-			0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
507
-			0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
508
-			0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
509
-			0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
510
-			0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
511
-			0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
512
-			0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
513
-		);
514
-
515
-		self::$_sbox4 = array(
516
-			0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
517
-			0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
518
-			0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
519
-			0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
520
-			0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
521
-			0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
522
-			0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
523
-			0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
524
-			0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
525
-			0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
526
-			0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
527
-			0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
528
-			0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
529
-			0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
530
-			0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
531
-			0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
532
-			0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
533
-			0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
534
-			0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
535
-			0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
536
-			0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
537
-			0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
538
-			0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
539
-			0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
540
-			0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
541
-			0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
542
-			0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
543
-			0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
544
-			0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
545
-			0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
546
-			0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
547
-			0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
548
-			0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
549
-			0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
550
-			0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
551
-			0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
552
-			0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
553
-			0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
554
-			0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
555
-			0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
556
-			0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
557
-			0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
558
-			0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
559
-			0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
560
-			0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
561
-			0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
562
-			0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
563
-			0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
564
-			0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
565
-			0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
566
-			0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
567
-			0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
568
-			0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
569
-			0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
570
-			0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
571
-			0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
572
-			0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
573
-			0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
574
-			0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
575
-			0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
576
-			0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
577
-			0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
578
-			0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
579
-			0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
580
-		);
581
-
582
-		self::$_p = array(
583
-			0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
584
-			0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
585
-			0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
586
-			0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
587
-			0x9216d5d9, 0x8979fb1b
588
-		);
589
-	}
590
-
591
-
592
-	/**
593
-	 * Indicates this is a block cipher
594
-	 *
595
-	 * @return integer Returns Cipher::BLOCK
596
-	 */
597
-	public function type()
598
-	{
599
-		return parent::BLOCK;
600
-	}
66
+    private $key_pos = 0;
67
+
68
+    /**
69
+     * Constructor
70
+     *
71
+     * @param string $key The key used for Encryption/Decryption
72
+     * @return void
73
+     */
74
+    public function __construct($key)
75
+    {
76
+        // the max length of the key is 448 bits (56 bytes)
77
+        $keylen = strlen($key);
78
+        if($keylen > 56)
79
+        {
80
+            $key = substr($key, 0, 56);
81
+            $keylen = 56;
82
+        }
83
+        else if($keylen < 1)
84
+        {
85
+            $msg  = "No key given. The key must be between 1 - 56 bytes.";
86
+            trigger_error($msg, E_USER_WARNING);
87
+        }
88
+
89
+        // set the key, make sure the required length is set in bits
90
+        parent::__construct(PHP_Crypt::CIPHER_BLOWFISH, $key, $keylen);
91
+
92
+        // set the block size
93
+        $this->blockSize(self::BYTES_BLOCK);
94
+
95
+        $this->initTables();
96
+        $this->subKeys();
97
+    }
98
+
99
+
100
+    /**
101
+     * Destructor
102
+     *
103
+     * @return void
104
+     */
105
+    public function __destruct()
106
+    {
107
+        parent::__destruct();
108
+    }
109
+
110
+
111
+    /**
112
+     * Encrypt plain text data
113
+     *
114
+     * @param string $data A 64 bit (8 byte) plain text string
115
+     * @return boolean Returns true
116
+     */
117
+    public function encrypt(&$data)
118
+    {
119
+        $this->operation(parent::ENCRYPT);
120
+        return $this->blowfish($data);
121
+    }
122
+
123
+
124
+    /**
125
+     * Decrypt an encrypted string
126
+     *
127
+     * @param string $data A 64 bit block of Blowfish encrypted data
128
+     * @return boolean Returns true
129
+     */
130
+    public function decrypt(&$data)
131
+    {
132
+        $this->operation(parent::DECRYPT);
133
+        return $this->blowfish($data);
134
+    }
135
+
136
+
137
+    /**
138
+     * The same alorigthm is used for both Encryption, and Decryption
139
+     *
140
+     * @param string $data A 64 bit block of data
141
+     * @return boolean Returns true
142
+     */
143
+    private function blowfish(&$data)
144
+    {
145
+        // divide the data into into two 32 bit halves
146
+        $xl = parent::str2Dec(substr($data, 0, 4));
147
+        $xr = parent::str2Dec(substr($data, 4, 4));
148
+
149
+        for($i = 0; $i < 16; ++$i)
150
+        {
151
+            if($this->operation() == parent::ENCRYPT)
152
+                $xl ^= self::$_p[$i];
153
+            else
154
+                $xl ^= self::$_p[17-$i];
155
+
156
+            // perform F() on the left half, and XOR with the right half
157
+            $xr = $this->F($xl) ^ $xr;
158
+
159
+            // swap $xl and $xr
160
+            $tmp = $xr;
161
+            $xr = $xl;
162
+            $xl = $tmp;
163
+        }
164
+
165
+        // swap $xl and $xr after the 16th round to undo the last swap
166
+        $tmp = $xl;
167
+        $xl  = $xr;
168
+        $xr  = $tmp;
169
+
170
+        // XOR the final two elements of $_p
171
+        if($this->operation() == parent::ENCRYPT)
172
+        {
173
+            $xr ^= self::$_p[16];
174
+            $xl  = $xl ^ self::$_p[17];
175
+        }
176
+        else // parent::DECRYPT
177
+        {
178
+            $xr ^= self::$_p[1];
179
+            $xl ^= self::$_p[0];
180
+        }
181
+
182
+        // recombine the two halves, force them to be 4 bytes each
183
+        $data = parent::dec2Str($xl, 4).parent::dec2Str($xr, 4);
184
+
185
+        return true;
186
+    }
187
+
188
+
189
+    /**
190
+     * Blowfish's F() function
191
+     *
192
+     * @param string $i A 32 bit integer
193
+     */
194
+    private function F($i)
195
+    {
196
+        // split the 32 bits into four 8 bit parts
197
+        $x[0] = $i & 0xff; // first byte
198
+        $x[1] = ($i >> 8)  & 0xff; // second byte
199
+        $x[2] = ($i >> 16) & 0xff; // third byte
200
+        $x[3] = ($i >> 24) & 0xff; // fourth byte
201
+
202
+        // perform F(), make sure all values returned are
203
+        // unsigned 32 bit
204
+        $f  = parent::uInt32(self::$_sbox1[$x[3]] + self::$_sbox2[$x[2]]);
205
+        $f  = parent::uInt32($f ^ self::$_sbox3[$x[1]]);
206
+        $f  = parent::uInt32($f + self::$_sbox4[$x[0]]);
207
+
208
+        return $f;
209
+    }
210
+
211
+
212
+    /**
213
+     * Generates the subkeys used in Blowfish
214
+     *
215
+     * @return void
216
+     */
217
+    private function subKeys()
218
+    {
219
+        // now xor each element of $_p with 32 bits from the key
220
+        for($i = 0; $i < 18; ++$i)
221
+        {
222
+            $c = $this->keyChunk(4);
223
+            self::$_p[$i] ^= parent::str2Dec($c);
224
+        }
225
+
226
+        // start with an 8 byte null string
227
+        $zero = "\0\0\0\0\0\0\0\0";
228
+
229
+        // now we loop, each loop replacing elements of $_p, or an $_sbox with the
230
+        // repeatedly encrypted zero string
231
+        for($i = 0; $i < 1042; $i += 2)
232
+        {
233
+            // encrypt the 64 bit null string
234
+            $this->encrypt($zero);
235
+
236
+            // split the encrypted null string into two 32 bit parts
237
+            $z0 = parent::str2Dec(substr($zero, 0, 4));
238
+            $z1 = parent::str2Dec(substr($zero, 4, 4));
239
+
240
+            // now fill the $_p, $_sbox1, $_sbox2, $_sbox3, $_sbox4
241
+            // with 4 bytes from the repeatedly encrypted 8 byte null string
242
+            if($i < 18)
243
+            {
244
+                self::$_p[$i] = $z0;
245
+                self::$_p[$i + 1] = $z1;
246
+            }
247
+            else if($i >= 18 && $i < 274)
248
+            {
249
+                self::$_sbox1[$i - 18] = $z0;
250
+                self::$_sbox1[$i - 18 + 1] = $z1;
251
+            }
252
+            else if($i >= 274 && $i < 530)
253
+            {
254
+                self::$_sbox2[$i - 274] = $z0;
255
+                self::$_sbox2[$i - 274 + 1] = $z1;
256
+            }
257
+            else if($i >= 530 && $i < 786)
258
+            {
259
+                self::$_sbox3[$i - 530] = $z0;
260
+                self::$_sbox3[$i - 530 + 1] = $z1;
261
+            }
262
+            else if($i >= 786 && $i < 1042)
263
+            {
264
+                self::$_sbox4[$i -786] = $z0;
265
+                self::$_sbox4[$i - 786 + 1] = $z1;
266
+            }
267
+        }
268
+    }
269
+
270
+
271
+    /**
272
+     * Returns a substring of $this->key. The size of the substring is set in the
273
+     * parameter $size. Each call to this function returns a substring starting
274
+     * in the position where the last substring ended. Effectively it rotates
275
+     * through the key, when it reaches the end, it starts over at the
276
+     * beginning of the key and continues on. You can reset the current position
277
+     * by setting the parameter $reset=true, which will start the key back at the
278
+     * first byte of the $this->key string.
279
+     *
280
+     * @param integer $size The size of the substring to return, in bytes
281
+     * @param bool $reset If set to true, sets the position back to 0, the first
282
+     *	byte of the key string
283
+     * @return string The next substring of the key
284
+     */
285
+    private function keyChunk($size = 1, $reset = false)
286
+    {
287
+        if($reset || $this->key_pos >= $this->keySize())
288
+            $this->key_pos = 0;
289
+
290
+        $bytes = substr($this->key(), $this->key_pos, $size);
291
+        $len = strlen($bytes);
292
+        if($len < $size)
293
+        {
294
+            $bytes .= substr($this->key(), 0, $size - $len);
295
+            $this->key_pos = $size - $len;
296
+        }
297
+        else
298
+            $this->key_pos += $size;
299
+
300
+        return $bytes;
301
+    }
302
+
303
+
304
+    /**
305
+     * Initialize the tables used in Blowfish Encryption. These
306
+     * are calculated from the value of PI. We grabbed
307
+     * these from the mcrypt blowfish source, which already had
308
+     * these values calculated
309
+     *
310
+     * @return void
311
+     */
312
+    private function initTables()
313
+    {
314
+        self::$_sbox1 = array(
315
+            0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
316
+            0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
317
+            0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
318
+            0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
319
+            0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
320
+            0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
321
+            0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
322
+            0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
323
+            0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
324
+            0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
325
+            0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
326
+            0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
327
+            0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
328
+            0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
329
+            0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
330
+            0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
331
+            0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
332
+            0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
333
+            0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
334
+            0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
335
+            0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
336
+            0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
337
+            0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
338
+            0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
339
+            0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
340
+            0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
341
+            0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
342
+            0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
343
+            0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
344
+            0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
345
+            0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
346
+            0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
347
+            0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
348
+            0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
349
+            0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
350
+            0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
351
+            0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
352
+            0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
353
+            0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
354
+            0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
355
+            0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
356
+            0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
357
+            0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
358
+            0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
359
+            0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
360
+            0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
361
+            0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
362
+            0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
363
+            0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
364
+            0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
365
+            0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
366
+            0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
367
+            0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
368
+            0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
369
+            0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
370
+            0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
371
+            0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
372
+            0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
373
+            0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
374
+            0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
375
+            0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
376
+            0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
377
+            0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
378
+            0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
379
+        );
380
+
381
+        self::$_sbox2 = array(
382
+            0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
383
+            0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
384
+            0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
385
+            0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
386
+            0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
387
+            0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
388
+            0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
389
+            0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
390
+            0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
391
+            0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
392
+            0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
393
+            0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
394
+            0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
395
+            0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
396
+            0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
397
+            0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
398
+            0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
399
+            0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
400
+            0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
401
+            0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
402
+            0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
403
+            0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
404
+            0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
405
+            0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
406
+            0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
407
+            0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
408
+            0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
409
+            0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
410
+            0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
411
+            0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
412
+            0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
413
+            0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
414
+            0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
415
+            0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
416
+            0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
417
+            0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
418
+            0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
419
+            0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
420
+            0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
421
+            0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
422
+            0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
423
+            0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
424
+            0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
425
+            0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
426
+            0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
427
+            0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
428
+            0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
429
+            0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
430
+            0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
431
+            0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
432
+            0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
433
+            0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
434
+            0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
435
+            0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
436
+            0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
437
+            0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
438
+            0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
439
+            0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
440
+            0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
441
+            0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
442
+            0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
443
+            0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
444
+            0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
445
+            0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
446
+        );
447
+
448
+        self::$_sbox3 = array(
449
+            0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
450
+            0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
451
+            0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
452
+            0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
453
+            0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
454
+            0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
455
+            0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
456
+            0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
457
+            0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
458
+            0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
459
+            0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
460
+            0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
461
+            0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
462
+            0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
463
+            0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
464
+            0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
465
+            0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
466
+            0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
467
+            0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
468
+            0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
469
+            0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
470
+            0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
471
+            0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
472
+            0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
473
+            0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
474
+            0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
475
+            0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
476
+            0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
477
+            0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
478
+            0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
479
+            0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
480
+            0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
481
+            0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
482
+            0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
483
+            0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
484
+            0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
485
+            0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
486
+            0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
487
+            0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
488
+            0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
489
+            0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
490
+            0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
491
+            0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
492
+            0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
493
+            0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
494
+            0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
495
+            0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
496
+            0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
497
+            0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
498
+            0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
499
+            0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
500
+            0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
501
+            0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
502
+            0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
503
+            0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
504
+            0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
505
+            0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
506
+            0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
507
+            0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
508
+            0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
509
+            0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
510
+            0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
511
+            0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
512
+            0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
513
+        );
514
+
515
+        self::$_sbox4 = array(
516
+            0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
517
+            0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
518
+            0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
519
+            0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
520
+            0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
521
+            0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
522
+            0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
523
+            0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
524
+            0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
525
+            0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
526
+            0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
527
+            0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
528
+            0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
529
+            0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
530
+            0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
531
+            0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
532
+            0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
533
+            0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
534
+            0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
535
+            0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
536
+            0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
537
+            0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
538
+            0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
539
+            0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
540
+            0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
541
+            0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
542
+            0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
543
+            0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
544
+            0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
545
+            0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
546
+            0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
547
+            0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
548
+            0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
549
+            0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
550
+            0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
551
+            0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
552
+            0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
553
+            0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
554
+            0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
555
+            0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
556
+            0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
557
+            0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
558
+            0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
559
+            0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
560
+            0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
561
+            0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
562
+            0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
563
+            0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
564
+            0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
565
+            0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
566
+            0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
567
+            0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
568
+            0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
569
+            0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
570
+            0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
571
+            0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
572
+            0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
573
+            0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
574
+            0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
575
+            0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
576
+            0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
577
+            0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
578
+            0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
579
+            0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
580
+        );
581
+
582
+        self::$_p = array(
583
+            0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
584
+            0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
585
+            0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
586
+            0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
587
+            0x9216d5d9, 0x8979fb1b
588
+        );
589
+    }
590
+
591
+
592
+    /**
593
+     * Indicates this is a block cipher
594
+     *
595
+     * @return integer Returns Cipher::BLOCK
596
+     */
597
+    public function type()
598
+    {
599
+        return parent::BLOCK;
600
+    }
601 601
 }
602 602
 ?>
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 	{
76 76
 		// the max length of the key is 448 bits (56 bytes)
77 77
 		$keylen = strlen($key);
78
-		if($keylen > 56)
78
+		if ($keylen > 56)
79 79
 		{
80 80
 			$key = substr($key, 0, 56);
81 81
 			$keylen = 56;
82 82
 		}
83
-		else if($keylen < 1)
83
+		else if ($keylen < 1)
84 84
 		{
85
-			$msg  = "No key given. The key must be between 1 - 56 bytes.";
85
+			$msg = "No key given. The key must be between 1 - 56 bytes.";
86 86
 			trigger_error($msg, E_USER_WARNING);
87 87
 		}
88 88
 
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 		$xl = parent::str2Dec(substr($data, 0, 4));
147 147
 		$xr = parent::str2Dec(substr($data, 4, 4));
148 148
 
149
-		for($i = 0; $i < 16; ++$i)
149
+		for ($i = 0; $i < 16; ++$i)
150 150
 		{
151
-			if($this->operation() == parent::ENCRYPT)
151
+			if ($this->operation() == parent::ENCRYPT)
152 152
 				$xl ^= self::$_p[$i];
153 153
 			else
154
-				$xl ^= self::$_p[17-$i];
154
+				$xl ^= self::$_p[17 - $i];
155 155
 
156 156
 			// perform F() on the left half, and XOR with the right half
157 157
 			$xr = $this->F($xl) ^ $xr;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 		$xr  = $tmp;
169 169
 
170 170
 		// XOR the final two elements of $_p
171
-		if($this->operation() == parent::ENCRYPT)
171
+		if ($this->operation() == parent::ENCRYPT)
172 172
 		{
173 173
 			$xr ^= self::$_p[16];
174 174
 			$xl  = $xl ^ self::$_p[17];
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	{
196 196
 		// split the 32 bits into four 8 bit parts
197 197
 		$x[0] = $i & 0xff; // first byte
198
-		$x[1] = ($i >> 8)  & 0xff; // second byte
198
+		$x[1] = ($i >> 8) & 0xff; // second byte
199 199
 		$x[2] = ($i >> 16) & 0xff; // third byte
200 200
 		$x[3] = ($i >> 24) & 0xff; // fourth byte
201 201
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	private function subKeys()
218 218
 	{
219 219
 		// now xor each element of $_p with 32 bits from the key
220
-		for($i = 0; $i < 18; ++$i)
220
+		for ($i = 0; $i < 18; ++$i)
221 221
 		{
222 222
 			$c = $this->keyChunk(4);
223 223
 			self::$_p[$i] ^= parent::str2Dec($c);
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
 		// now we loop, each loop replacing elements of $_p, or an $_sbox with the
230 230
 		// repeatedly encrypted zero string
231
-		for($i = 0; $i < 1042; $i += 2)
231
+		for ($i = 0; $i < 1042; $i += 2)
232 232
 		{
233 233
 			// encrypt the 64 bit null string
234 234
 			$this->encrypt($zero);
@@ -239,29 +239,29 @@  discard block
 block discarded – undo
239 239
 
240 240
 			// now fill the $_p, $_sbox1, $_sbox2, $_sbox3, $_sbox4
241 241
 			// with 4 bytes from the repeatedly encrypted 8 byte null string
242
-			if($i < 18)
242
+			if ($i < 18)
243 243
 			{
244 244
 				self::$_p[$i] = $z0;
245 245
 				self::$_p[$i + 1] = $z1;
246 246
 			}
247
-			else if($i >= 18 && $i < 274)
247
+			else if ($i >= 18 && $i < 274)
248 248
 			{
249 249
 				self::$_sbox1[$i - 18] = $z0;
250 250
 				self::$_sbox1[$i - 18 + 1] = $z1;
251 251
 			}
252
-			else if($i >= 274 && $i < 530)
252
+			else if ($i >= 274 && $i < 530)
253 253
 			{
254 254
 				self::$_sbox2[$i - 274] = $z0;
255 255
 				self::$_sbox2[$i - 274 + 1] = $z1;
256 256
 			}
257
-			else if($i >= 530 && $i < 786)
257
+			else if ($i >= 530 && $i < 786)
258 258
 			{
259 259
 				self::$_sbox3[$i - 530] = $z0;
260 260
 				self::$_sbox3[$i - 530 + 1] = $z1;
261 261
 			}
262
-			else if($i >= 786 && $i < 1042)
262
+			else if ($i >= 786 && $i < 1042)
263 263
 			{
264
-				self::$_sbox4[$i -786] = $z0;
264
+				self::$_sbox4[$i - 786] = $z0;
265 265
 				self::$_sbox4[$i - 786 + 1] = $z1;
266 266
 			}
267 267
 		}
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
 	 */
285 285
 	private function keyChunk($size = 1, $reset = false)
286 286
 	{
287
-		if($reset || $this->key_pos >= $this->keySize())
287
+		if ($reset || $this->key_pos >= $this->keySize())
288 288
 			$this->key_pos = 0;
289 289
 
290 290
 		$bytes = substr($this->key(), $this->key_pos, $size);
291 291
 		$len = strlen($bytes);
292
-		if($len < $size)
292
+		if ($len < $size)
293 293
 		{
294 294
 			$bytes .= substr($this->key(), 0, $size - $len);
295 295
 			$this->key_pos = $size - $len;
Please login to merge, or discard this patch.
Braces   +16 added lines, -20 removed lines patch added patch discarded remove patch
@@ -79,8 +79,7 @@  discard block
 block discarded – undo
79 79
 		{
80 80
 			$key = substr($key, 0, 56);
81 81
 			$keylen = 56;
82
-		}
83
-		else if($keylen < 1)
82
+		} else if($keylen < 1)
84 83
 		{
85 84
 			$msg  = "No key given. The key must be between 1 - 56 bytes.";
86 85
 			trigger_error($msg, E_USER_WARNING);
@@ -148,10 +147,11 @@  discard block
 block discarded – undo
148 147
 
149 148
 		for($i = 0; $i < 16; ++$i)
150 149
 		{
151
-			if($this->operation() == parent::ENCRYPT)
152
-				$xl ^= self::$_p[$i];
153
-			else
154
-				$xl ^= self::$_p[17-$i];
150
+			if($this->operation() == parent::ENCRYPT) {
151
+							$xl ^= self::$_p[$i];
152
+			} else {
153
+							$xl ^= self::$_p[17-$i];
154
+			}
155 155
 
156 156
 			// perform F() on the left half, and XOR with the right half
157 157
 			$xr = $this->F($xl) ^ $xr;
@@ -172,8 +172,7 @@  discard block
 block discarded – undo
172 172
 		{
173 173
 			$xr ^= self::$_p[16];
174 174
 			$xl  = $xl ^ self::$_p[17];
175
-		}
176
-		else // parent::DECRYPT
175
+		} else // parent::DECRYPT
177 176
 		{
178 177
 			$xr ^= self::$_p[1];
179 178
 			$xl ^= self::$_p[0];
@@ -243,23 +242,19 @@  discard block
 block discarded – undo
243 242
 			{
244 243
 				self::$_p[$i] = $z0;
245 244
 				self::$_p[$i + 1] = $z1;
246
-			}
247
-			else if($i >= 18 && $i < 274)
245
+			} else if($i >= 18 && $i < 274)
248 246
 			{
249 247
 				self::$_sbox1[$i - 18] = $z0;
250 248
 				self::$_sbox1[$i - 18 + 1] = $z1;
251
-			}
252
-			else if($i >= 274 && $i < 530)
249
+			} else if($i >= 274 && $i < 530)
253 250
 			{
254 251
 				self::$_sbox2[$i - 274] = $z0;
255 252
 				self::$_sbox2[$i - 274 + 1] = $z1;
256
-			}
257
-			else if($i >= 530 && $i < 786)
253
+			} else if($i >= 530 && $i < 786)
258 254
 			{
259 255
 				self::$_sbox3[$i - 530] = $z0;
260 256
 				self::$_sbox3[$i - 530 + 1] = $z1;
261
-			}
262
-			else if($i >= 786 && $i < 1042)
257
+			} else if($i >= 786 && $i < 1042)
263 258
 			{
264 259
 				self::$_sbox4[$i -786] = $z0;
265 260
 				self::$_sbox4[$i - 786 + 1] = $z1;
@@ -284,8 +279,9 @@  discard block
 block discarded – undo
284 279
 	 */
285 280
 	private function keyChunk($size = 1, $reset = false)
286 281
 	{
287
-		if($reset || $this->key_pos >= $this->keySize())
288
-			$this->key_pos = 0;
282
+		if($reset || $this->key_pos >= $this->keySize()) {
283
+					$this->key_pos = 0;
284
+		}
289 285
 
290 286
 		$bytes = substr($this->key(), $this->key_pos, $size);
291 287
 		$len = strlen($bytes);
@@ -293,9 +289,9 @@  discard block
 block discarded – undo
293 289
 		{
294 290
 			$bytes .= substr($this->key(), 0, $size - $len);
295 291
 			$this->key_pos = $size - $len;
292
+		} else {
293
+					$this->key_pos += $size;
296 294
 		}
297
-		else
298
-			$this->key_pos += $size;
299 295
 
300 296
 		return $bytes;
301 297
 	}
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/AES192.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -38,35 +38,35 @@
 block discarded – undo
38 38
  */
39 39
 class Cipher_AES_192 extends Cipher_Rijndael_128
40 40
 {
41
-	/** @type integer BYTES_BLOCK The size of the block, in bytes */
42
-	const BYTES_BLOCK = 16; // 128 bits;
41
+    /** @type integer BYTES_BLOCK The size of the block, in bytes */
42
+    const BYTES_BLOCK = 16; // 128 bits;
43 43
 
44
-	/** @type integer BYTES_KEY The size of the key, in bytes */
45
-	const BYTES_KEY = 24; // 192 bits;
44
+    /** @type integer BYTES_KEY The size of the key, in bytes */
45
+    const BYTES_KEY = 24; // 192 bits;
46 46
 
47
-	/**
48
-	 * Constructor
49
-	 * Sets the key used for encryption.
50
-	 *
51
-	 * @param string $key string containing the user supplied encryption key
52
-	 * @return void
53
-	 */
54
-	public function __construct($key)
55
-	{
56
-		// Setup AES by calling the second constructor in Rijndael_128
57
-		// The block size is set here too, since all AES implementations use 128 bit blocks
58
-		parent::__construct1(PHP_Crypt::CIPHER_AES_192, $key, self::BYTES_KEY);
59
-	}
47
+    /**
48
+     * Constructor
49
+     * Sets the key used for encryption.
50
+     *
51
+     * @param string $key string containing the user supplied encryption key
52
+     * @return void
53
+     */
54
+    public function __construct($key)
55
+    {
56
+        // Setup AES by calling the second constructor in Rijndael_128
57
+        // The block size is set here too, since all AES implementations use 128 bit blocks
58
+        parent::__construct1(PHP_Crypt::CIPHER_AES_192, $key, self::BYTES_KEY);
59
+    }
60 60
 
61 61
 
62
-	/**
63
-	 * Destructor
64
-	 *
65
-	 * @return void
66
-	 */
67
-	public function __destruct()
68
-	{
69
-		parent::__destruct();
70
-	}
62
+    /**
63
+     * Destructor
64
+     *
65
+     * @return void
66
+     */
67
+    public function __destruct()
68
+    {
69
+        parent::__destruct();
70
+    }
71 71
 }
72 72
 ?>
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/Rijndael128.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -38,61 +38,61 @@
 block discarded – undo
38 38
  */
39 39
 class Cipher_Rijndael_128 extends Cipher_Rijndael
40 40
 {
41
-	/** @type integer BITS_BLOCK The size of the block, in bits */
42
-	const BYTES_BLOCK = 16;
41
+    /** @type integer BITS_BLOCK The size of the block, in bits */
42
+    const BYTES_BLOCK = 16;
43 43
 
44
-	//const BITS_KEY = 0;
44
+    //const BITS_KEY = 0;
45 45
 
46 46
 
47
-	/**
48
-	 * Constructor
49
-	 * Sets the key used for encryption. Also sets the requied block size
50
-	 * This should only be used when calling this class directly, for classes
51
-	 * that extend this class, they should call __construct1()
52
-	 *
53
-	 * @param string $key string containing the user supplied encryption key
54
-	 * @return void
55
-	 */
56
-	public function __construct($key)
57
-	{
58
-		// Set up the key
59
-		parent::__construct(PHP_Crypt::CIPHER_RIJNDAEL_128, $key);
47
+    /**
48
+     * Constructor
49
+     * Sets the key used for encryption. Also sets the requied block size
50
+     * This should only be used when calling this class directly, for classes
51
+     * that extend this class, they should call __construct1()
52
+     *
53
+     * @param string $key string containing the user supplied encryption key
54
+     * @return void
55
+     */
56
+    public function __construct($key)
57
+    {
58
+        // Set up the key
59
+        parent::__construct(PHP_Crypt::CIPHER_RIJNDAEL_128, $key);
60 60
 
61
-		// required block size in bits
62
-		$this->blockSize(self::BYTES_BLOCK);
61
+        // required block size in bits
62
+        $this->blockSize(self::BYTES_BLOCK);
63 63
 
64
-		// expand the key
65
-		$this->expandKey();
66
-	}
64
+        // expand the key
65
+        $this->expandKey();
66
+    }
67 67
 
68 68
 
69
-	/**
70
-	 * Constructor, used only by classes that extend this class
71
-	 *
72
-	 * @param string $cipher_name The pre-defined cipher name of the child class
73
-	 * @param string $key The key used for encryption/decryption
74
-	 * @param integer $req_key_len The required key length, in bits
75
-	 * @return void
76
-	 */
77
-	protected function __construct1($cipher_name, $key, $req_key_len)
78
-	{
79
-		parent::__construct($cipher_name, $key, $req_key_len);
69
+    /**
70
+     * Constructor, used only by classes that extend this class
71
+     *
72
+     * @param string $cipher_name The pre-defined cipher name of the child class
73
+     * @param string $key The key used for encryption/decryption
74
+     * @param integer $req_key_len The required key length, in bits
75
+     * @return void
76
+     */
77
+    protected function __construct1($cipher_name, $key, $req_key_len)
78
+    {
79
+        parent::__construct($cipher_name, $key, $req_key_len);
80 80
 
81
-		// required block size in bits
82
-		$this->blockSize(self::BYTES_BLOCK);
81
+        // required block size in bits
82
+        $this->blockSize(self::BYTES_BLOCK);
83 83
 
84
-		// expand the key
85
-		$this->expandKey();
86
-	}
84
+        // expand the key
85
+        $this->expandKey();
86
+    }
87 87
 
88 88
 
89
-	/**
90
-	 * Destructor
91
-	 *
92
-	 * @return void
93
-	 */
94
-	public function __destruct()
95
-	{
96
-		parent::__destruct();
97
-	}
89
+    /**
90
+     * Destructor
91
+     *
92
+     * @return void
93
+     */
94
+    public function __destruct()
95
+    {
96
+        parent::__destruct();
97
+    }
98 98
 }
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/RC2.php 3 patches
Indentation   +273 added lines, -273 removed lines patch added patch discarded remove patch
@@ -44,298 +44,298 @@
 block discarded – undo
44 44
  */
45 45
 class Cipher_RC2 extends Cipher
46 46
 {
47
-	/** @type integer BYTES_BLOCK The size of the block, in bytes */
48
-	const BYTES_BLOCK = 8; // 64 bits
49
-
50
-	// rc2 has a variable length key, between 1 - 128 bytes (8-1024 bits)
51
-	//const BYTES_KEY = 0;
52
-
53
-	/** @type array $_sbox RC2's sBox, initialized in initTables() */
54
-	private static $_sbox = array();
55
-
56
-	/** @type string $xkey The expanded key */
57
-	private $xkey = "";
58
-
59
-
60
-	/**
61
-	 * Constructor
62
-	 *
63
-	 * @param string $key The key used for Encryption/Decryption
64
-	 * @return void
65
-	 */
66
-	public function __construct($key)
67
-	{
68
-		// the key must be between 1 and 128 bytes, keys larger than
69
-		// 128 bytes are truncated in expandedKey()
70
-		$keylen = strlen($key);
71
-		if($keylen < 1)
72
-		{
73
-			$err = "Key size is $keylen bits, Key size must be between 1 and 128 bytes";
74
-			trigger_error($err, E_USER_WARNING);
75
-		}
76
-
77
-		// set the key
78
-		parent::__construct(PHP_Crypt::CIPHER_RC2, $key, $keylen);
79
-
80
-		// set the block size
81
-		$this->blockSize(self::BYTES_BLOCK);
82
-
83
-		// initialize the tables
84
-		$this->initTables();
85
-
86
-		// expand the key to 128 bytes
87
-		$this->expandKey();
88
-	}
89
-
90
-
91
-	/**
92
-	 * Destructor
93
-	 *
94
-	 * @return void
95
-	 */
96
-	public function __destruct()
97
-	{
98
-		parent::__destruct();
99
-	}
100
-
101
-
102
-	/**
103
-	 * Encrypt plain text data using RC2
104
-	 *
105
-	 * @param string $text A 64 bit (8 byte) plain text string
106
-	 * @return boolean Returns true
107
-	 */
108
-	public function encrypt(&$text)
109
-	{
110
-		$this->operation(parent::ENCRYPT);
111
-
112
-		// split up the message and key into 4 16 bit parts (2 byte words),
113
-		// then convert each array element to an integer
114
-		$w = self::splitBytes($text);
115
-		$k = self::splitBytes($this->xkey);
116
-		$j = 0; // the key index
117
-
118
-		for($i = 0; $i < 16; ++$i)
119
-		{
120
-			$j = $i * 4;
121
-
122
-			/* This is where it gets ugly, RC2 relies on unsigned ints. PHP does
47
+    /** @type integer BYTES_BLOCK The size of the block, in bytes */
48
+    const BYTES_BLOCK = 8; // 64 bits
49
+
50
+    // rc2 has a variable length key, between 1 - 128 bytes (8-1024 bits)
51
+    //const BYTES_KEY = 0;
52
+
53
+    /** @type array $_sbox RC2's sBox, initialized in initTables() */
54
+    private static $_sbox = array();
55
+
56
+    /** @type string $xkey The expanded key */
57
+    private $xkey = "";
58
+
59
+
60
+    /**
61
+     * Constructor
62
+     *
63
+     * @param string $key The key used for Encryption/Decryption
64
+     * @return void
65
+     */
66
+    public function __construct($key)
67
+    {
68
+        // the key must be between 1 and 128 bytes, keys larger than
69
+        // 128 bytes are truncated in expandedKey()
70
+        $keylen = strlen($key);
71
+        if($keylen < 1)
72
+        {
73
+            $err = "Key size is $keylen bits, Key size must be between 1 and 128 bytes";
74
+            trigger_error($err, E_USER_WARNING);
75
+        }
76
+
77
+        // set the key
78
+        parent::__construct(PHP_Crypt::CIPHER_RC2, $key, $keylen);
79
+
80
+        // set the block size
81
+        $this->blockSize(self::BYTES_BLOCK);
82
+
83
+        // initialize the tables
84
+        $this->initTables();
85
+
86
+        // expand the key to 128 bytes
87
+        $this->expandKey();
88
+    }
89
+
90
+
91
+    /**
92
+     * Destructor
93
+     *
94
+     * @return void
95
+     */
96
+    public function __destruct()
97
+    {
98
+        parent::__destruct();
99
+    }
100
+
101
+
102
+    /**
103
+     * Encrypt plain text data using RC2
104
+     *
105
+     * @param string $text A 64 bit (8 byte) plain text string
106
+     * @return boolean Returns true
107
+     */
108
+    public function encrypt(&$text)
109
+    {
110
+        $this->operation(parent::ENCRYPT);
111
+
112
+        // split up the message and key into 4 16 bit parts (2 byte words),
113
+        // then convert each array element to an integer
114
+        $w = self::splitBytes($text);
115
+        $k = self::splitBytes($this->xkey);
116
+        $j = 0; // the key index
117
+
118
+        for($i = 0; $i < 16; ++$i)
119
+        {
120
+            $j = $i * 4;
121
+
122
+            /* This is where it gets ugly, RC2 relies on unsigned ints. PHP does
123 123
 			 * not have a nice way to handle unsigned ints, so we have to rely on sprintf.
124 124
 			 * To make RC2 compatible with mCrypt, I also forced everything to 32 bit
125 125
 			 * When I test against mcrypt and the original rc2 C source, I get 32 bit
126 126
 			 * results, even on a 64 bit platform
127 127
 			 */
128 128
 
129
-			// 16 rounds of RC2's Mixing algorithm for each 2 byte 'word' as
130
-			// required by RC2
131
-			$w[0] += parent::uInt($w[1] & ~$w[3]) + parent::uInt($w[2] & $w[3]) + $k[$j + 0];
132
-			$w[0]  = sprintf("%u", $w[0] << 1) + sprintf("%u", $w[0] >> 15 & 1);
133
-			$w[0]  = parent::uInt32($w[0]);
134
-
135
-			$w[1] += parent::uInt($w[2] & ~$w[0]) + parent::uInt($w[3] & $w[0]) + $k[$j + 1];
136
-			$w[1]  = parent::uInt($w[1] << 2) + parent::uInt($w[1] >> 14 & 3);
137
-			$w[1]  = parent::uInt32($w[1]);
138
-
139
-			$w[2] += parent::uInt($w[3] & ~$w[1]) + parent::uInt($w[0] & $w[1]) + $k[$j + 2];
140
-			$w[2]  = parent::uInt($w[2] << 3) + parent::uInt($w[2] >> 13 & 7);
141
-			$w[2]  = parent::uInt32($w[2]);
142
-
143
-			$w[3] += parent::uInt($w[0] & ~$w[2]) + parent::uInt($w[1] & $w[2]) + $k[$j + 3];
144
-			$w[3]  = parent::uInt($w[3] << 5) + parent::uInt($w[3] >> 11 & 31);
145
-			$w[3]  = parent::uInt32($w[3]);
146
-
147
-			// rounds 5 and 11 get rc2's Mash
148
-			if($i == 4 || $i == 10)
149
-			{
150
-				$w[0] += $k[$w[3] & 63];
151
-				$w[1] += $k[$w[0] & 63];
152
-				$w[2] += $k[$w[1] & 63];
153
-				$w[3] += $k[$w[2] & 63];
154
-			}
155
-		}
156
-
157
-		/* truthfully, I am not clear why this is required. It was not mentioned
129
+            // 16 rounds of RC2's Mixing algorithm for each 2 byte 'word' as
130
+            // required by RC2
131
+            $w[0] += parent::uInt($w[1] & ~$w[3]) + parent::uInt($w[2] & $w[3]) + $k[$j + 0];
132
+            $w[0]  = sprintf("%u", $w[0] << 1) + sprintf("%u", $w[0] >> 15 & 1);
133
+            $w[0]  = parent::uInt32($w[0]);
134
+
135
+            $w[1] += parent::uInt($w[2] & ~$w[0]) + parent::uInt($w[3] & $w[0]) + $k[$j + 1];
136
+            $w[1]  = parent::uInt($w[1] << 2) + parent::uInt($w[1] >> 14 & 3);
137
+            $w[1]  = parent::uInt32($w[1]);
138
+
139
+            $w[2] += parent::uInt($w[3] & ~$w[1]) + parent::uInt($w[0] & $w[1]) + $k[$j + 2];
140
+            $w[2]  = parent::uInt($w[2] << 3) + parent::uInt($w[2] >> 13 & 7);
141
+            $w[2]  = parent::uInt32($w[2]);
142
+
143
+            $w[3] += parent::uInt($w[0] & ~$w[2]) + parent::uInt($w[1] & $w[2]) + $k[$j + 3];
144
+            $w[3]  = parent::uInt($w[3] << 5) + parent::uInt($w[3] >> 11 & 31);
145
+            $w[3]  = parent::uInt32($w[3]);
146
+
147
+            // rounds 5 and 11 get rc2's Mash
148
+            if($i == 4 || $i == 10)
149
+            {
150
+                $w[0] += $k[$w[3] & 63];
151
+                $w[1] += $k[$w[0] & 63];
152
+                $w[2] += $k[$w[1] & 63];
153
+                $w[3] += $k[$w[2] & 63];
154
+            }
155
+        }
156
+
157
+        /* truthfully, I am not clear why this is required. It was not mentioned
158 158
 		 * in any of the documentation I read, however reading the original RC2 C
159 159
 		 * source code, this was done and in order for me to get the
160 160
 		 * correct results in PHP I needed to do this as well
161 161
 		 */
162
-		$max = count($w);
163
-		for($i = 0; $i < $max; ++$i)
164
-		{
165
-			$pos = $i * 2;
166
-			$text[$pos]   = chr($w[$i]);
167
-			$text[$pos+1] = chr($w[$i] >> 8);
168
-		}
169
-
170
-		return true;
171
-	}
172
-
173
-
174
-	/**
175
-	 * Decrypt a RC2 encrypted string
176
-	 *
177
-	 * @param string $text A RC2 encrypted string
178
-	 * @return boolean Returns true
179
-	 */
180
-	public function decrypt(&$text)
181
-	{
182
-		$this->operation(parent::DECRYPT);
183
-
184
-		// first split up the message into four 16 bit parts (2 bytes),
185
-		// then convert each array element to an integer
186
-		$w = self::splitBytes($text);
187
-		$k = self::splitBytes($this->xkey);
188
-		$j = 0; // the key index
189
-
190
-		for($i = 15; $i >= 0; --$i)
191
-		{
192
-			$j = $i * 4;
193
-
194
-			/* This is where it gets ugly, RC2 relies on unsigned ints. PHP does
162
+        $max = count($w);
163
+        for($i = 0; $i < $max; ++$i)
164
+        {
165
+            $pos = $i * 2;
166
+            $text[$pos]   = chr($w[$i]);
167
+            $text[$pos+1] = chr($w[$i] >> 8);
168
+        }
169
+
170
+        return true;
171
+    }
172
+
173
+
174
+    /**
175
+     * Decrypt a RC2 encrypted string
176
+     *
177
+     * @param string $text A RC2 encrypted string
178
+     * @return boolean Returns true
179
+     */
180
+    public function decrypt(&$text)
181
+    {
182
+        $this->operation(parent::DECRYPT);
183
+
184
+        // first split up the message into four 16 bit parts (2 bytes),
185
+        // then convert each array element to an integer
186
+        $w = self::splitBytes($text);
187
+        $k = self::splitBytes($this->xkey);
188
+        $j = 0; // the key index
189
+
190
+        for($i = 15; $i >= 0; --$i)
191
+        {
192
+            $j = $i * 4;
193
+
194
+            /* This is where it gets ugly, RC2 relies on unsigned ints. PHP does
195 195
 			 * not have a nice way to handle unsigned ints, so we have to rely on sprintf.
196 196
 			 * To make RC2 compatible with mCrypt, I also forced everything to 32 bit
197 197
 			 * When I test against mcrypt and the original rc2 C source, I get 32 bit
198 198
 			 * results, even on a 64 bit platform
199 199
 			 */
200 200
 
201
-			$w[3] &= 65535;
202
-			$w[3]  = parent::uInt($w[3] << 11) + parent::uInt($w[3] >> 5);
203
-			$w[3] -= parent::uInt($w[0] & ~$w[2]) + parent::uInt($w[1] & $w[2]) + $k[$j + 3];
204
-			$w[3]  = parent::uInt32($w[3]);
205
-
206
-			$w[2] &= 65535;
207
-			$w[2]  = parent::uInt($w[2] << 13) + parent::uInt($w[2] >> 3);
208
-			$w[2] -= parent::uInt($w[3] & ~$w[1]) + parent::uInt($w[0] & $w[1]) + $k[$j + 2];
209
-			$w[2]  = parent::uInt32($w[2]);
210
-
211
-			$w[1] &= 65535;
212
-			$w[1]  = parent::uInt($w[1] << 14) + parent::uInt($w[1] >> 2);
213
-			$w[1] -= parent::uInt($w[2] & ~$w[0]) + parent::uInt($w[3] & $w[0]) + $k[$j + 1];
214
-			$w[1]  = parent::uInt32($w[1]);
215
-
216
-			$w[0] &= 65535;
217
-			$w[0]  = parent::uInt($w[0] << 15) + parent::uInt($w[0] >> 1);
218
-			$w[0] -= parent::uInt($w[1] & ~$w[3]) + parent::uInt($w[2] & $w[3]) + $k[$j + 0];
219
-			$w[0]  = parent::uInt32($w[0]);
220
-
221
-			if($i == 5 || $i == 11)
222
-			{
223
-				$w[3] -= $k[$w[2] & 63];
224
-				$w[2] -= $k[$w[1] & 63];
225
-				$w[1] -= $k[$w[0] & 63];
226
-				$w[0] -= $k[$w[3] & 63];
227
-			}
228
-		}
229
-
230
-
231
-		/* I am not clear why this is required. It was not mentioned
201
+            $w[3] &= 65535;
202
+            $w[3]  = parent::uInt($w[3] << 11) + parent::uInt($w[3] >> 5);
203
+            $w[3] -= parent::uInt($w[0] & ~$w[2]) + parent::uInt($w[1] & $w[2]) + $k[$j + 3];
204
+            $w[3]  = parent::uInt32($w[3]);
205
+
206
+            $w[2] &= 65535;
207
+            $w[2]  = parent::uInt($w[2] << 13) + parent::uInt($w[2] >> 3);
208
+            $w[2] -= parent::uInt($w[3] & ~$w[1]) + parent::uInt($w[0] & $w[1]) + $k[$j + 2];
209
+            $w[2]  = parent::uInt32($w[2]);
210
+
211
+            $w[1] &= 65535;
212
+            $w[1]  = parent::uInt($w[1] << 14) + parent::uInt($w[1] >> 2);
213
+            $w[1] -= parent::uInt($w[2] & ~$w[0]) + parent::uInt($w[3] & $w[0]) + $k[$j + 1];
214
+            $w[1]  = parent::uInt32($w[1]);
215
+
216
+            $w[0] &= 65535;
217
+            $w[0]  = parent::uInt($w[0] << 15) + parent::uInt($w[0] >> 1);
218
+            $w[0] -= parent::uInt($w[1] & ~$w[3]) + parent::uInt($w[2] & $w[3]) + $k[$j + 0];
219
+            $w[0]  = parent::uInt32($w[0]);
220
+
221
+            if($i == 5 || $i == 11)
222
+            {
223
+                $w[3] -= $k[$w[2] & 63];
224
+                $w[2] -= $k[$w[1] & 63];
225
+                $w[1] -= $k[$w[0] & 63];
226
+                $w[0] -= $k[$w[3] & 63];
227
+            }
228
+        }
229
+
230
+
231
+        /* I am not clear why this is required. It was not mentioned
232 232
 		 * in any of the documentation I read, however reading the original RC2 C
233 233
 		 * source code, this was done and in order for me to get the
234 234
 		 * correct results in PHP I needed to do this as well
235 235
 		 */
236
-		$max = count($w);
237
-		for($i = 0; $i < $max; ++$i)
238
-		{
239
-			$pos = $i * 2;
240
-			$text[$pos]   = chr($w[$i]);
241
-			$text[$pos+1] = chr($w[$i] >> 8);
242
-		}
243
-
244
-		return true;
245
-	}
246
-
247
-
248
-	/**
249
-	 * Splits an 8 byte string into four array elements of 2 bytes each, swaps the bytes
250
-	 * of each array element, and converts the result into an integer
251
-	 *
252
-	 * @param string $str The 8 byte string to split and convert
253
-	 * @return array An array of 4 elements, each with 2 bytes
254
-	 */
255
-	private static function splitBytes($str)
256
-	{
257
-		$arr = str_split($str, 2);
258
-
259
-		return array_map(function($b){
260
-			return Core::str2Dec($b[1].$b[0]);
261
-		}, $arr);
262
-	}
263
-
264
-
265
-	/**
266
-	 * Expands the key to 128 bits. RC2 uses an initial key size between
267
-	 * 8 - 128 bits, then takes the initial key and expands it out to 128
268
-	 * bits, which is used for encryption
269
-	 *
270
-	 * @return void
271
-	 */
272
-	private function expandKey()
273
-	{
274
-		// start by copying the key to the xkey variable
275
-		$this->xkey = $this->key();
276
-		$len = $this->keySize();
277
-
278
-		// the max length of the key is 128 bytes
279
-		if($len > 128)
280
-			$this->xkey = substr($this->xkey, 0, 128);
281
-
282
-		// now expanded the rest of the key to 128 bytes, using the sbox
283
-		for($i = $len; $i < 128; ++$i)
284
-		{
285
-			$byte1 = ord($this->xkey[$i - $len]);
286
-			$byte2 = ord($this->xkey[$i - 1]);
287
-			$pos = ($byte1 + $byte2);
288
-
289
-			// the sbox is only 255 bytes, so if we extend past that
290
-			// we need to modulo 256 so we have a valid position
291
-			if($pos > 255)
292
-				$pos -= 256;
293
-
294
-			$this->xkey .= chr(self::$_sbox[$pos]);
295
-		}
296
-
297
-		// now replace the first byte of the key with it's position in the sbox
298
-		$pos = ord($this->xkey[0]);
299
-		$this->xkey[0] = chr(self::$_sbox[$pos]);
300
-	}
301
-
302
-
303
-	/**
304
-	 * Initialize tables
305
-	 *
306
-	 * @return void
307
-	 */
308
-	private function initTables()
309
-	{
310
-		self::$_sbox = array(
311
-			0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed, 0x28, 0xe9, 0xfd, 0x79, 0x4a, 0xa0, 0xd8, 0x9d,
312
-			0xc6, 0x7e, 0x37, 0x83, 0x2b, 0x76, 0x53, 0x8e, 0x62, 0x4c, 0x64, 0x88, 0x44, 0x8b, 0xfb, 0xa2,
313
-			0x17, 0x9a, 0x59, 0xf5, 0x87, 0xb3, 0x4f, 0x13, 0x61, 0x45, 0x6d, 0x8d, 0x09, 0x81, 0x7d, 0x32,
314
-			0xbd, 0x8f, 0x40, 0xeb, 0x86, 0xb7, 0x7b, 0x0b, 0xf0, 0x95, 0x21, 0x22, 0x5c, 0x6b, 0x4e, 0x82,
315
-			0x54, 0xd6, 0x65, 0x93, 0xce, 0x60, 0xb2, 0x1c, 0x73, 0x56, 0xc0, 0x14, 0xa7, 0x8c, 0xf1, 0xdc,
316
-			0x12, 0x75, 0xca, 0x1f, 0x3b, 0xbe, 0xe4, 0xd1, 0x42, 0x3d, 0xd4, 0x30, 0xa3, 0x3c, 0xb6, 0x26,
317
-			0x6f, 0xbf, 0x0e, 0xda, 0x46, 0x69, 0x07, 0x57, 0x27, 0xf2, 0x1d, 0x9b, 0xbc, 0x94, 0x43, 0x03,
318
-			0xf8, 0x11, 0xc7, 0xf6, 0x90, 0xef, 0x3e, 0xe7, 0x06, 0xc3, 0xd5, 0x2f, 0xc8, 0x66, 0x1e, 0xd7,
319
-			0x08, 0xe8, 0xea, 0xde, 0x80, 0x52, 0xee, 0xf7, 0x84, 0xaa, 0x72, 0xac, 0x35, 0x4d, 0x6a, 0x2a,
320
-			0x96, 0x1a, 0xd2, 0x71, 0x5a, 0x15, 0x49, 0x74, 0x4b, 0x9f, 0xd0, 0x5e, 0x04, 0x18, 0xa4, 0xec,
321
-			0xc2, 0xe0, 0x41, 0x6e, 0x0f, 0x51, 0xcb, 0xcc, 0x24, 0x91, 0xaf, 0x50, 0xa1, 0xf4, 0x70, 0x39,
322
-			0x99, 0x7c, 0x3a, 0x85, 0x23, 0xb8, 0xb4, 0x7a, 0xfc, 0x02, 0x36, 0x5b, 0x25, 0x55, 0x97, 0x31,
323
-			0x2d, 0x5d, 0xfa, 0x98, 0xe3, 0x8a, 0x92, 0xae, 0x05, 0xdf, 0x29, 0x10, 0x67, 0x6c, 0xba, 0xc9,
324
-			0xd3, 0x00, 0xe6, 0xcf, 0xe1, 0x9e, 0xa8, 0x2c, 0x63, 0x16, 0x01, 0x3f, 0x58, 0xe2, 0x89, 0xa9,
325
-			0x0d, 0x38, 0x34, 0x1b, 0xab, 0x33, 0xff, 0xb0, 0xbb, 0x48, 0x0c, 0x5f, 0xb9, 0xb1, 0xcd, 0x2e,
326
-			0xc5, 0xf3, 0xdb, 0x47, 0xe5, 0xa5, 0x9c, 0x77, 0x0a, 0xa6, 0x20, 0x68, 0xfe, 0x7f, 0xc1, 0xad
327
-		);
328
-	}
329
-
330
-
331
-	/**
332
-	 * Indicates this is a block cipher
333
-	 *
334
-	 * @return integer Returns Cipher::BLOCK
335
-	 */
336
-	public function type()
337
-	{
338
-		return parent::BLOCK;
339
-	}
236
+        $max = count($w);
237
+        for($i = 0; $i < $max; ++$i)
238
+        {
239
+            $pos = $i * 2;
240
+            $text[$pos]   = chr($w[$i]);
241
+            $text[$pos+1] = chr($w[$i] >> 8);
242
+        }
243
+
244
+        return true;
245
+    }
246
+
247
+
248
+    /**
249
+     * Splits an 8 byte string into four array elements of 2 bytes each, swaps the bytes
250
+     * of each array element, and converts the result into an integer
251
+     *
252
+     * @param string $str The 8 byte string to split and convert
253
+     * @return array An array of 4 elements, each with 2 bytes
254
+     */
255
+    private static function splitBytes($str)
256
+    {
257
+        $arr = str_split($str, 2);
258
+
259
+        return array_map(function($b){
260
+            return Core::str2Dec($b[1].$b[0]);
261
+        }, $arr);
262
+    }
263
+
264
+
265
+    /**
266
+     * Expands the key to 128 bits. RC2 uses an initial key size between
267
+     * 8 - 128 bits, then takes the initial key and expands it out to 128
268
+     * bits, which is used for encryption
269
+     *
270
+     * @return void
271
+     */
272
+    private function expandKey()
273
+    {
274
+        // start by copying the key to the xkey variable
275
+        $this->xkey = $this->key();
276
+        $len = $this->keySize();
277
+
278
+        // the max length of the key is 128 bytes
279
+        if($len > 128)
280
+            $this->xkey = substr($this->xkey, 0, 128);
281
+
282
+        // now expanded the rest of the key to 128 bytes, using the sbox
283
+        for($i = $len; $i < 128; ++$i)
284
+        {
285
+            $byte1 = ord($this->xkey[$i - $len]);
286
+            $byte2 = ord($this->xkey[$i - 1]);
287
+            $pos = ($byte1 + $byte2);
288
+
289
+            // the sbox is only 255 bytes, so if we extend past that
290
+            // we need to modulo 256 so we have a valid position
291
+            if($pos > 255)
292
+                $pos -= 256;
293
+
294
+            $this->xkey .= chr(self::$_sbox[$pos]);
295
+        }
296
+
297
+        // now replace the first byte of the key with it's position in the sbox
298
+        $pos = ord($this->xkey[0]);
299
+        $this->xkey[0] = chr(self::$_sbox[$pos]);
300
+    }
301
+
302
+
303
+    /**
304
+     * Initialize tables
305
+     *
306
+     * @return void
307
+     */
308
+    private function initTables()
309
+    {
310
+        self::$_sbox = array(
311
+            0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed, 0x28, 0xe9, 0xfd, 0x79, 0x4a, 0xa0, 0xd8, 0x9d,
312
+            0xc6, 0x7e, 0x37, 0x83, 0x2b, 0x76, 0x53, 0x8e, 0x62, 0x4c, 0x64, 0x88, 0x44, 0x8b, 0xfb, 0xa2,
313
+            0x17, 0x9a, 0x59, 0xf5, 0x87, 0xb3, 0x4f, 0x13, 0x61, 0x45, 0x6d, 0x8d, 0x09, 0x81, 0x7d, 0x32,
314
+            0xbd, 0x8f, 0x40, 0xeb, 0x86, 0xb7, 0x7b, 0x0b, 0xf0, 0x95, 0x21, 0x22, 0x5c, 0x6b, 0x4e, 0x82,
315
+            0x54, 0xd6, 0x65, 0x93, 0xce, 0x60, 0xb2, 0x1c, 0x73, 0x56, 0xc0, 0x14, 0xa7, 0x8c, 0xf1, 0xdc,
316
+            0x12, 0x75, 0xca, 0x1f, 0x3b, 0xbe, 0xe4, 0xd1, 0x42, 0x3d, 0xd4, 0x30, 0xa3, 0x3c, 0xb6, 0x26,
317
+            0x6f, 0xbf, 0x0e, 0xda, 0x46, 0x69, 0x07, 0x57, 0x27, 0xf2, 0x1d, 0x9b, 0xbc, 0x94, 0x43, 0x03,
318
+            0xf8, 0x11, 0xc7, 0xf6, 0x90, 0xef, 0x3e, 0xe7, 0x06, 0xc3, 0xd5, 0x2f, 0xc8, 0x66, 0x1e, 0xd7,
319
+            0x08, 0xe8, 0xea, 0xde, 0x80, 0x52, 0xee, 0xf7, 0x84, 0xaa, 0x72, 0xac, 0x35, 0x4d, 0x6a, 0x2a,
320
+            0x96, 0x1a, 0xd2, 0x71, 0x5a, 0x15, 0x49, 0x74, 0x4b, 0x9f, 0xd0, 0x5e, 0x04, 0x18, 0xa4, 0xec,
321
+            0xc2, 0xe0, 0x41, 0x6e, 0x0f, 0x51, 0xcb, 0xcc, 0x24, 0x91, 0xaf, 0x50, 0xa1, 0xf4, 0x70, 0x39,
322
+            0x99, 0x7c, 0x3a, 0x85, 0x23, 0xb8, 0xb4, 0x7a, 0xfc, 0x02, 0x36, 0x5b, 0x25, 0x55, 0x97, 0x31,
323
+            0x2d, 0x5d, 0xfa, 0x98, 0xe3, 0x8a, 0x92, 0xae, 0x05, 0xdf, 0x29, 0x10, 0x67, 0x6c, 0xba, 0xc9,
324
+            0xd3, 0x00, 0xe6, 0xcf, 0xe1, 0x9e, 0xa8, 0x2c, 0x63, 0x16, 0x01, 0x3f, 0x58, 0xe2, 0x89, 0xa9,
325
+            0x0d, 0x38, 0x34, 0x1b, 0xab, 0x33, 0xff, 0xb0, 0xbb, 0x48, 0x0c, 0x5f, 0xb9, 0xb1, 0xcd, 0x2e,
326
+            0xc5, 0xf3, 0xdb, 0x47, 0xe5, 0xa5, 0x9c, 0x77, 0x0a, 0xa6, 0x20, 0x68, 0xfe, 0x7f, 0xc1, 0xad
327
+        );
328
+    }
329
+
330
+
331
+    /**
332
+     * Indicates this is a block cipher
333
+     *
334
+     * @return integer Returns Cipher::BLOCK
335
+     */
336
+    public function type()
337
+    {
338
+        return parent::BLOCK;
339
+    }
340 340
 }
341 341
 ?>
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		// the key must be between 1 and 128 bytes, keys larger than
69 69
 		// 128 bytes are truncated in expandedKey()
70 70
 		$keylen = strlen($key);
71
-		if($keylen < 1)
71
+		if ($keylen < 1)
72 72
 		{
73 73
 			$err = "Key size is $keylen bits, Key size must be between 1 and 128 bytes";
74 74
 			trigger_error($err, E_USER_WARNING);
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 		$k = self::splitBytes($this->xkey);
116 116
 		$j = 0; // the key index
117 117
 
118
-		for($i = 0; $i < 16; ++$i)
118
+		for ($i = 0; $i < 16; ++$i)
119 119
 		{
120 120
 			$j = $i * 4;
121 121
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 			$w[3]  = parent::uInt32($w[3]);
146 146
 
147 147
 			// rounds 5 and 11 get rc2's Mash
148
-			if($i == 4 || $i == 10)
148
+			if ($i == 4 || $i == 10)
149 149
 			{
150 150
 				$w[0] += $k[$w[3] & 63];
151 151
 				$w[1] += $k[$w[0] & 63];
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 		 * correct results in PHP I needed to do this as well
161 161
 		 */
162 162
 		$max = count($w);
163
-		for($i = 0; $i < $max; ++$i)
163
+		for ($i = 0; $i < $max; ++$i)
164 164
 		{
165 165
 			$pos = $i * 2;
166 166
 			$text[$pos]   = chr($w[$i]);
167
-			$text[$pos+1] = chr($w[$i] >> 8);
167
+			$text[$pos + 1] = chr($w[$i] >> 8);
168 168
 		}
169 169
 
170 170
 		return true;
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 		$k = self::splitBytes($this->xkey);
188 188
 		$j = 0; // the key index
189 189
 
190
-		for($i = 15; $i >= 0; --$i)
190
+		for ($i = 15; $i >= 0; --$i)
191 191
 		{
192 192
 			$j = $i * 4;
193 193
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 			$w[0] -= parent::uInt($w[1] & ~$w[3]) + parent::uInt($w[2] & $w[3]) + $k[$j + 0];
219 219
 			$w[0]  = parent::uInt32($w[0]);
220 220
 
221
-			if($i == 5 || $i == 11)
221
+			if ($i == 5 || $i == 11)
222 222
 			{
223 223
 				$w[3] -= $k[$w[2] & 63];
224 224
 				$w[2] -= $k[$w[1] & 63];
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
 		 * correct results in PHP I needed to do this as well
235 235
 		 */
236 236
 		$max = count($w);
237
-		for($i = 0; $i < $max; ++$i)
237
+		for ($i = 0; $i < $max; ++$i)
238 238
 		{
239 239
 			$pos = $i * 2;
240 240
 			$text[$pos]   = chr($w[$i]);
241
-			$text[$pos+1] = chr($w[$i] >> 8);
241
+			$text[$pos + 1] = chr($w[$i] >> 8);
242 242
 		}
243 243
 
244 244
 		return true;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 	{
257 257
 		$arr = str_split($str, 2);
258 258
 
259
-		return array_map(function($b){
259
+		return array_map(function($b) {
260 260
 			return Core::str2Dec($b[1].$b[0]);
261 261
 		}, $arr);
262 262
 	}
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
 		$len = $this->keySize();
277 277
 
278 278
 		// the max length of the key is 128 bytes
279
-		if($len > 128)
279
+		if ($len > 128)
280 280
 			$this->xkey = substr($this->xkey, 0, 128);
281 281
 
282 282
 		// now expanded the rest of the key to 128 bytes, using the sbox
283
-		for($i = $len; $i < 128; ++$i)
283
+		for ($i = $len; $i < 128; ++$i)
284 284
 		{
285 285
 			$byte1 = ord($this->xkey[$i - $len]);
286 286
 			$byte2 = ord($this->xkey[$i - 1]);
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 
289 289
 			// the sbox is only 255 bytes, so if we extend past that
290 290
 			// we need to modulo 256 so we have a valid position
291
-			if($pos > 255)
291
+			if ($pos > 255)
292 292
 				$pos -= 256;
293 293
 
294 294
 			$this->xkey .= chr(self::$_sbox[$pos]);
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -276,8 +276,9 @@  discard block
 block discarded – undo
276 276
 		$len = $this->keySize();
277 277
 
278 278
 		// the max length of the key is 128 bytes
279
-		if($len > 128)
280
-			$this->xkey = substr($this->xkey, 0, 128);
279
+		if($len > 128) {
280
+					$this->xkey = substr($this->xkey, 0, 128);
281
+		}
281 282
 
282 283
 		// now expanded the rest of the key to 128 bytes, using the sbox
283 284
 		for($i = $len; $i < 128; ++$i)
@@ -288,8 +289,9 @@  discard block
 block discarded – undo
288 289
 
289 290
 			// the sbox is only 255 bytes, so if we extend past that
290 291
 			// we need to modulo 256 so we have a valid position
291
-			if($pos > 255)
292
-				$pos -= 256;
292
+			if($pos > 255) {
293
+							$pos -= 256;
294
+			}
293 295
 
294 296
 			$this->xkey .= chr(self::$_sbox[$pos]);
295 297
 		}
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/Rijndael192.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -38,39 +38,39 @@
 block discarded – undo
38 38
  */
39 39
 class Cipher_Rijndael_192 extends Cipher_Rijndael
40 40
 {
41
-	/** @type integer BYTES_BLOCK The size of the block, in bytes */
42
-	const BYTES_BLOCK = 24; // 192 bits
41
+    /** @type integer BYTES_BLOCK The size of the block, in bytes */
42
+    const BYTES_BLOCK = 24; // 192 bits
43 43
 
44
-	//const BITS_KEY = 0;
44
+    //const BITS_KEY = 0;
45 45
 
46 46
 
47
-	/**
48
-	 * Constructor
49
-	 * Sets the key used for encryption. Also sets the requied block size
50
-	 *
51
-	 * @param string $key string containing the user supplied encryption key
52
-	 * @return void
53
-	 */
54
-	public function __construct($key)
55
-	{
56
-		// Set up the key
57
-		parent::__construct(PHP_CRYPT::CIPHER_RIJNDAEL_192, $key);
47
+    /**
48
+     * Constructor
49
+     * Sets the key used for encryption. Also sets the requied block size
50
+     *
51
+     * @param string $key string containing the user supplied encryption key
52
+     * @return void
53
+     */
54
+    public function __construct($key)
55
+    {
56
+        // Set up the key
57
+        parent::__construct(PHP_CRYPT::CIPHER_RIJNDAEL_192, $key);
58 58
 
59
-		// required block size in bits
60
-		$this->blockSize(self::BYTES_BLOCK);
59
+        // required block size in bits
60
+        $this->blockSize(self::BYTES_BLOCK);
61 61
 
62
-		// expand the key now that we know the key size, and the bit size
63
-		$this->expandKey();
64
-	}
62
+        // expand the key now that we know the key size, and the bit size
63
+        $this->expandKey();
64
+    }
65 65
 
66 66
 
67
-	/**
68
-	 * Destructor
69
-	 *
70
-	 * @return void
71
-	 */
72
-	public function __destruct()
73
-	{
74
-		parent::__destruct();
75
-	}
67
+    /**
68
+     * Destructor
69
+     *
70
+     * @return void
71
+     */
72
+    public function __destruct()
73
+    {
74
+        parent::__destruct();
75
+    }
76 76
 }
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/Cipher.php 3 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -36,222 +36,222 @@
 block discarded – undo
36 36
  */
37 37
 abstract class Cipher extends Core
38 38
 {
39
-	/** @type integer ENCRYPT Indicates when we are in encryption mode */
40
-	const ENCRYPT = 1;
39
+    /** @type integer ENCRYPT Indicates when we are in encryption mode */
40
+    const ENCRYPT = 1;
41 41
 
42
-	/** @type integer DECRYPT Indicates when we are in decryption mode */
43
-	const DECRYPT = 2;
42
+    /** @type integer DECRYPT Indicates when we are in decryption mode */
43
+    const DECRYPT = 2;
44 44
 
45
-	/** @type integer BLOCK Indicates that a cipher is a block cipher */
46
-	const BLOCK = 1;
45
+    /** @type integer BLOCK Indicates that a cipher is a block cipher */
46
+    const BLOCK = 1;
47 47
 
48
-	/** @type integer STREAM Indicates that a cipher is a stream cipher */
49
-	const STREAM = 2;
48
+    /** @type integer STREAM Indicates that a cipher is a stream cipher */
49
+    const STREAM = 2;
50 50
 
51
-	/** @type string $cipher_name Stores the name of the cipher */
52
-	protected $cipher_name = "";
51
+    /** @type string $cipher_name Stores the name of the cipher */
52
+    protected $cipher_name = "";
53 53
 
54
-	/** @type integer $block_size The block size of the cipher in bytes */
55
-	protected $block_size = 0;
54
+    /** @type integer $block_size The block size of the cipher in bytes */
55
+    protected $block_size = 0;
56 56
 
57
-	/**
58
-	 * @type integer $operation Indicates if a cipher is Encrypting or Decrypting
59
-	 * this can be set to either Cipher::ENCRYPT or Cipher::DECRYPT
60
-	 */
61
-	protected $operation = self::ENCRYPT; // can be either Cipher::ENCRYPT | Cipher::DECRYPT;
57
+    /**
58
+     * @type integer $operation Indicates if a cipher is Encrypting or Decrypting
59
+     * this can be set to either Cipher::ENCRYPT or Cipher::DECRYPT
60
+     */
61
+    protected $operation = self::ENCRYPT; // can be either Cipher::ENCRYPT | Cipher::DECRYPT;
62 62
 
63
-	/** @type string $key Stores the key for the Cipher */
64
-	private $key = "";
63
+    /** @type string $key Stores the key for the Cipher */
64
+    private $key = "";
65 65
 
66
-	/** @type integer $key_len Keep track of the key length, so we don't
66
+    /** @type integer $key_len Keep track of the key length, so we don't
67 67
 	have to make repeated calls to strlen() to find the length */
68
-	private $key_len = 0;
68
+    private $key_len = 0;
69 69
 
70 70
 
71
-	/**
72
-	 * Constructor
73
-	 *
74
-	 * @param string $name one of the predefined ciphers
75
-	 * @param string $key The key used for encryption
76
-	 * @param int Optional, the required size of a key for the cipher
77
-	 * @return void
78
-	 */
79
-	protected function __construct($name, $key = "", $required_key_sz = 0)
80
-	{
81
-		$this->name($name);
82
-		$this->key($key, $required_key_sz);
83
-	}
84
-
85
-
86
-	/**
87
-	 * Destructor
88
-	 *
89
-	 * @return void
90
-	 */
91
-	protected function __destruct()
92
-	{
71
+    /**
72
+     * Constructor
73
+     *
74
+     * @param string $name one of the predefined ciphers
75
+     * @param string $key The key used for encryption
76
+     * @param int Optional, the required size of a key for the cipher
77
+     * @return void
78
+     */
79
+    protected function __construct($name, $key = "", $required_key_sz = 0)
80
+    {
81
+        $this->name($name);
82
+        $this->key($key, $required_key_sz);
83
+    }
84
+
93 85
 
94
-	}
86
+    /**
87
+     * Destructor
88
+     *
89
+     * @return void
90
+     */
91
+    protected function __destruct()
92
+    {
95 93
 
94
+    }
96 95
 
97 96
 
98
-	/**********************************************************************
97
+
98
+    /**********************************************************************
99 99
 	 * ABSTRACT METHODS
100 100
 	 *
101 101
 	 * The abstract methods required by inheriting classes to implement
102 102
 	 **********************************************************************/
103 103
 
104
-	/**
105
-	 * The cipher's encryption function. Must be defined
106
-	 * by the class inheriting this Cipher object. This function
107
-	 * will most often be called from within the Mode object
108
-	 *
109
-	 * @param string $text The text to be encrypted
110
-	 * @return boolean Always returns false
111
-	 */
112
-	abstract public function encrypt(&$text);
104
+    /**
105
+     * The cipher's encryption function. Must be defined
106
+     * by the class inheriting this Cipher object. This function
107
+     * will most often be called from within the Mode object
108
+     *
109
+     * @param string $text The text to be encrypted
110
+     * @return boolean Always returns false
111
+     */
112
+    abstract public function encrypt(&$text);
113 113
 
114 114
 
115
-	/**
116
-	 * The cipher's decryption function. Must be defined
117
-	 * by the class inheriting this Cipher object. This function
118
-	 * will most often be called from within the Mode object
119
-	 *
120
-	 * @param string $text The text to decrypt
121
-	 * @return boolean Always returns false
122
-	 */
123
-	abstract public function decrypt(&$text);
115
+    /**
116
+     * The cipher's decryption function. Must be defined
117
+     * by the class inheriting this Cipher object. This function
118
+     * will most often be called from within the Mode object
119
+     *
120
+     * @param string $text The text to decrypt
121
+     * @return boolean Always returns false
122
+     */
123
+    abstract public function decrypt(&$text);
124 124
 
125 125
 
126
-	/**
127
-	 * Indiciates whether the cipher is a block or stream cipher
128
-	 *
129
-	 * @return integer Returns either Cipher::BLOCK or Cipher::STREAM
130
-	 */
131
-	abstract public function type();
126
+    /**
127
+     * Indiciates whether the cipher is a block or stream cipher
128
+     *
129
+     * @return integer Returns either Cipher::BLOCK or Cipher::STREAM
130
+     */
131
+    abstract public function type();
132 132
 
133 133
 
134 134
 
135 135
 
136
-	/**********************************************************************
136
+    /**********************************************************************
137 137
 	 * PUBLIC METHODS
138 138
 	 *
139 139
 	 **********************************************************************/
140 140
 
141
-	/**
142
-	 * Determine if we are Encrypting or Decrypting
143
-	 * Since some ciphers use the same algorithm to Encrypt or Decrypt but with only
144
-	 * slight differences, we need a way to check if we are Encrypting or Decrypting
145
-	 * An example is DES, which uses the same algorithm except that when Decrypting
146
-	 * the sub_keys are reversed
147
-	 *
148
-	 * @param integer $op Sets the operation to Cipher::ENCRYPT or Cipher::DECRYPT
149
-	 * @return integer The current operation, either Cipher::ENCRYPT or Cipher::DECRYPT
150
-	 */
151
-	public function operation($op = 0)
152
-	{
153
-		if($op == self::ENCRYPT || $op == self::DECRYPT)
154
-			$this->operation = $op;
155
-
156
-		return $this->operation;
157
-	}
158
-
159
-
160
-	/**
161
-	 * Return the name of cipher that is currently being used
162
-	 *
163
-	 * @return string The cipher name
164
-	 */
165
-	public function name($name = "")
166
-	{
167
-		if($name != "")
168
-			$this->cipher_name = $name;
169
-
170
-		return $this->cipher_name;
171
-	}
172
-
173
-
174
-	/**
175
-	 * Size of the data in Bits that get used during encryption
176
-	 *
177
-	 * @param integer $bytes Number of bytes each block of data is required by the cipher
178
-	 * @return integer The number of bytes each block of data required by the cipher
179
-	 */
180
-	public function blockSize($bytes = 0)
181
-	{
182
-		if($bytes > 0)
183
-			$this->block_size = $bytes;
184
-
185
-		// in some cases a blockSize is not set, such as stream ciphers.
186
-		// so just return 0 for the block size
187
-		if(!isset($this->block_size))
188
-			return 0;
189
-
190
-		return $this->block_size;
191
-	}
192
-
193
-
194
-	/**
195
-	 * Returns the size (in bytes) required by the cipher.
196
-	 *
197
-	 * @return integer The number of bytes the cipher requires the key to be
198
-	 */
199
-	public function keySize()
200
-	{
201
-		return $this->key_len;
202
-	}
203
-
204
-
205
-	/**
206
-	 * Set the cipher key used for encryption/decryption. This function
207
-	 * may lengthen or shorten the key to meet the size requirements of
208
-	 * the cipher.
209
-	 *
210
-	 * If the $key parameter is not given, this function simply returns the
211
-	 * current key being used.
212
-	 *
213
-	 * @param string $key Optional, A key for the cipher
214
-	 * @param integer $req_sz The byte size required for the key
215
-	 * @return string They key, which may have been modified to fit size
216
-	 *	requirements
217
-	 */
218
-	public function key($key = "", $req_sz = 0)
219
-	{
220
-		if($key != "" && $key != null)
221
-		{
222
-			// in the case where the key is changed changed after
223
-			// creating a new Cipher object and the $req_sz was not
224
-			// given, we need to make sure the new key meets the size
225
-			// requirements. This can be determined from the $this->key_len
226
-			// member set from the previous key
227
-			if($this->key_len > 0 && $req_sz == 0)
228
-				$req_sz = $this->key_len;
229
-			else
230
-				$this->key_len = strlen($key);
231
-
232
-			if($req_sz > 0)
233
-			{
234
-				if($this->key_len > $req_sz)
235
-				{
236
-					// shorten the key length
237
-					$key = substr($key, 0, $req_sz);
238
-					$this->key_len = $req_sz;
239
-				}
240
-				else if($this->key_len < $req_sz)
241
-				{
242
-					// send a notice that the key was too small
243
-					// NEVER PAD THE KEY, THIS WOULD BE INSECURE!!!!!
244
-					$msg = strtoupper($this->name())." requires a $req_sz byte key, {$this->key_len} bytes received";
245
-					trigger_error($msg, E_USER_WARNING);
141
+    /**
142
+     * Determine if we are Encrypting or Decrypting
143
+     * Since some ciphers use the same algorithm to Encrypt or Decrypt but with only
144
+     * slight differences, we need a way to check if we are Encrypting or Decrypting
145
+     * An example is DES, which uses the same algorithm except that when Decrypting
146
+     * the sub_keys are reversed
147
+     *
148
+     * @param integer $op Sets the operation to Cipher::ENCRYPT or Cipher::DECRYPT
149
+     * @return integer The current operation, either Cipher::ENCRYPT or Cipher::DECRYPT
150
+     */
151
+    public function operation($op = 0)
152
+    {
153
+        if($op == self::ENCRYPT || $op == self::DECRYPT)
154
+            $this->operation = $op;
155
+
156
+        return $this->operation;
157
+    }
158
+
159
+
160
+    /**
161
+     * Return the name of cipher that is currently being used
162
+     *
163
+     * @return string The cipher name
164
+     */
165
+    public function name($name = "")
166
+    {
167
+        if($name != "")
168
+            $this->cipher_name = $name;
169
+
170
+        return $this->cipher_name;
171
+    }
172
+
173
+
174
+    /**
175
+     * Size of the data in Bits that get used during encryption
176
+     *
177
+     * @param integer $bytes Number of bytes each block of data is required by the cipher
178
+     * @return integer The number of bytes each block of data required by the cipher
179
+     */
180
+    public function blockSize($bytes = 0)
181
+    {
182
+        if($bytes > 0)
183
+            $this->block_size = $bytes;
184
+
185
+        // in some cases a blockSize is not set, such as stream ciphers.
186
+        // so just return 0 for the block size
187
+        if(!isset($this->block_size))
188
+            return 0;
189
+
190
+        return $this->block_size;
191
+    }
192
+
193
+
194
+    /**
195
+     * Returns the size (in bytes) required by the cipher.
196
+     *
197
+     * @return integer The number of bytes the cipher requires the key to be
198
+     */
199
+    public function keySize()
200
+    {
201
+        return $this->key_len;
202
+    }
203
+
204
+
205
+    /**
206
+     * Set the cipher key used for encryption/decryption. This function
207
+     * may lengthen or shorten the key to meet the size requirements of
208
+     * the cipher.
209
+     *
210
+     * If the $key parameter is not given, this function simply returns the
211
+     * current key being used.
212
+     *
213
+     * @param string $key Optional, A key for the cipher
214
+     * @param integer $req_sz The byte size required for the key
215
+     * @return string They key, which may have been modified to fit size
216
+     *	requirements
217
+     */
218
+    public function key($key = "", $req_sz = 0)
219
+    {
220
+        if($key != "" && $key != null)
221
+        {
222
+            // in the case where the key is changed changed after
223
+            // creating a new Cipher object and the $req_sz was not
224
+            // given, we need to make sure the new key meets the size
225
+            // requirements. This can be determined from the $this->key_len
226
+            // member set from the previous key
227
+            if($this->key_len > 0 && $req_sz == 0)
228
+                $req_sz = $this->key_len;
229
+            else
230
+                $this->key_len = strlen($key);
231
+
232
+            if($req_sz > 0)
233
+            {
234
+                if($this->key_len > $req_sz)
235
+                {
236
+                    // shorten the key length
237
+                    $key = substr($key, 0, $req_sz);
238
+                    $this->key_len = $req_sz;
239
+                }
240
+                else if($this->key_len < $req_sz)
241
+                {
242
+                    // send a notice that the key was too small
243
+                    // NEVER PAD THE KEY, THIS WOULD BE INSECURE!!!!!
244
+                    $msg = strtoupper($this->name())." requires a $req_sz byte key, {$this->key_len} bytes received";
245
+                    trigger_error($msg, E_USER_WARNING);
246 246
 					
247
-					return false;
248
-				}
249
-			}
247
+                    return false;
248
+                }
249
+            }
250 250
 
251
-			$this->key = $key;
252
-		}
251
+            $this->key = $key;
252
+        }
253 253
 
254
-		return $this->key;
255
-	}
254
+        return $this->key;
255
+    }
256 256
 }
257 257
 ?>
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 */
151 151
 	public function operation($op = 0)
152 152
 	{
153
-		if($op == self::ENCRYPT || $op == self::DECRYPT)
153
+		if ($op == self::ENCRYPT || $op == self::DECRYPT)
154 154
 			$this->operation = $op;
155 155
 
156 156
 		return $this->operation;
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 */
165 165
 	public function name($name = "")
166 166
 	{
167
-		if($name != "")
167
+		if ($name != "")
168 168
 			$this->cipher_name = $name;
169 169
 
170 170
 		return $this->cipher_name;
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 	 */
180 180
 	public function blockSize($bytes = 0)
181 181
 	{
182
-		if($bytes > 0)
182
+		if ($bytes > 0)
183 183
 			$this->block_size = $bytes;
184 184
 
185 185
 		// in some cases a blockSize is not set, such as stream ciphers.
186 186
 		// so just return 0 for the block size
187
-		if(!isset($this->block_size))
187
+		if (!isset($this->block_size))
188 188
 			return 0;
189 189
 
190 190
 		return $this->block_size;
@@ -217,27 +217,27 @@  discard block
 block discarded – undo
217 217
 	 */
218 218
 	public function key($key = "", $req_sz = 0)
219 219
 	{
220
-		if($key != "" && $key != null)
220
+		if ($key != "" && $key != null)
221 221
 		{
222 222
 			// in the case where the key is changed changed after
223 223
 			// creating a new Cipher object and the $req_sz was not
224 224
 			// given, we need to make sure the new key meets the size
225 225
 			// requirements. This can be determined from the $this->key_len
226 226
 			// member set from the previous key
227
-			if($this->key_len > 0 && $req_sz == 0)
227
+			if ($this->key_len > 0 && $req_sz == 0)
228 228
 				$req_sz = $this->key_len;
229 229
 			else
230 230
 				$this->key_len = strlen($key);
231 231
 
232
-			if($req_sz > 0)
232
+			if ($req_sz > 0)
233 233
 			{
234
-				if($this->key_len > $req_sz)
234
+				if ($this->key_len > $req_sz)
235 235
 				{
236 236
 					// shorten the key length
237 237
 					$key = substr($key, 0, $req_sz);
238 238
 					$this->key_len = $req_sz;
239 239
 				}
240
-				else if($this->key_len < $req_sz)
240
+				else if ($this->key_len < $req_sz)
241 241
 				{
242 242
 					// send a notice that the key was too small
243 243
 					// NEVER PAD THE KEY, THIS WOULD BE INSECURE!!!!!
Please login to merge, or discard this patch.
Braces   +18 added lines, -14 removed lines patch added patch discarded remove patch
@@ -150,8 +150,9 @@  discard block
 block discarded – undo
150 150
 	 */
151 151
 	public function operation($op = 0)
152 152
 	{
153
-		if($op == self::ENCRYPT || $op == self::DECRYPT)
154
-			$this->operation = $op;
153
+		if($op == self::ENCRYPT || $op == self::DECRYPT) {
154
+					$this->operation = $op;
155
+		}
155 156
 
156 157
 		return $this->operation;
157 158
 	}
@@ -164,8 +165,9 @@  discard block
 block discarded – undo
164 165
 	 */
165 166
 	public function name($name = "")
166 167
 	{
167
-		if($name != "")
168
-			$this->cipher_name = $name;
168
+		if($name != "") {
169
+					$this->cipher_name = $name;
170
+		}
169 171
 
170 172
 		return $this->cipher_name;
171 173
 	}
@@ -179,13 +181,15 @@  discard block
 block discarded – undo
179 181
 	 */
180 182
 	public function blockSize($bytes = 0)
181 183
 	{
182
-		if($bytes > 0)
183
-			$this->block_size = $bytes;
184
+		if($bytes > 0) {
185
+					$this->block_size = $bytes;
186
+		}
184 187
 
185 188
 		// in some cases a blockSize is not set, such as stream ciphers.
186 189
 		// so just return 0 for the block size
187
-		if(!isset($this->block_size))
188
-			return 0;
190
+		if(!isset($this->block_size)) {
191
+					return 0;
192
+		}
189 193
 
190 194
 		return $this->block_size;
191 195
 	}
@@ -224,10 +228,11 @@  discard block
 block discarded – undo
224 228
 			// given, we need to make sure the new key meets the size
225 229
 			// requirements. This can be determined from the $this->key_len
226 230
 			// member set from the previous key
227
-			if($this->key_len > 0 && $req_sz == 0)
228
-				$req_sz = $this->key_len;
229
-			else
230
-				$this->key_len = strlen($key);
231
+			if($this->key_len > 0 && $req_sz == 0) {
232
+							$req_sz = $this->key_len;
233
+			} else {
234
+							$this->key_len = strlen($key);
235
+			}
231 236
 
232 237
 			if($req_sz > 0)
233 238
 			{
@@ -236,8 +241,7 @@  discard block
 block discarded – undo
236 241
 					// shorten the key length
237 242
 					$key = substr($key, 0, $req_sz);
238 243
 					$this->key_len = $req_sz;
239
-				}
240
-				else if($this->key_len < $req_sz)
244
+				} else if($this->key_len < $req_sz)
241 245
 				{
242 246
 					// send a notice that the key was too small
243 247
 					// NEVER PAD THE KEY, THIS WOULD BE INSECURE!!!!!
Please login to merge, or discard this patch.