ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
DES.php
Go to the documentation of this file.
1 <?php
2 
43 namespace phpseclib\Crypt;
44 
46 
54 class DES extends Base
55 {
64  const ENCRYPT = 0;
68  const DECRYPT = 1;
78  var $block_size = 8;
79 
87  var $key_length = 8;
88 
96  var $cipher_name_mcrypt = 'des';
97 
105  var $openssl_mode_names = array(
106  self::MODE_ECB => 'des-ecb',
107  self::MODE_CBC => 'des-cbc',
108  self::MODE_CFB => 'des-cfb',
109  self::MODE_OFB => 'des-ofb'
110  // self::MODE_CTR is undefined for DES
111  );
112 
120  var $cfb_init_len = 500;
121 
132  var $des_rounds = 1;
133 
142 
150  var $keys;
151 
164  var $shuffle = array(
165  "\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\xFF",
166  "\x00\x00\x00\x00\x00\x00\xFF\x00", "\x00\x00\x00\x00\x00\x00\xFF\xFF",
167  "\x00\x00\x00\x00\x00\xFF\x00\x00", "\x00\x00\x00\x00\x00\xFF\x00\xFF",
168  "\x00\x00\x00\x00\x00\xFF\xFF\x00", "\x00\x00\x00\x00\x00\xFF\xFF\xFF",
169  "\x00\x00\x00\x00\xFF\x00\x00\x00", "\x00\x00\x00\x00\xFF\x00\x00\xFF",
170  "\x00\x00\x00\x00\xFF\x00\xFF\x00", "\x00\x00\x00\x00\xFF\x00\xFF\xFF",
171  "\x00\x00\x00\x00\xFF\xFF\x00\x00", "\x00\x00\x00\x00\xFF\xFF\x00\xFF",
172  "\x00\x00\x00\x00\xFF\xFF\xFF\x00", "\x00\x00\x00\x00\xFF\xFF\xFF\xFF",
173  "\x00\x00\x00\xFF\x00\x00\x00\x00", "\x00\x00\x00\xFF\x00\x00\x00\xFF",
174  "\x00\x00\x00\xFF\x00\x00\xFF\x00", "\x00\x00\x00\xFF\x00\x00\xFF\xFF",
175  "\x00\x00\x00\xFF\x00\xFF\x00\x00", "\x00\x00\x00\xFF\x00\xFF\x00\xFF",
176  "\x00\x00\x00\xFF\x00\xFF\xFF\x00", "\x00\x00\x00\xFF\x00\xFF\xFF\xFF",
177  "\x00\x00\x00\xFF\xFF\x00\x00\x00", "\x00\x00\x00\xFF\xFF\x00\x00\xFF",
178  "\x00\x00\x00\xFF\xFF\x00\xFF\x00", "\x00\x00\x00\xFF\xFF\x00\xFF\xFF",
179  "\x00\x00\x00\xFF\xFF\xFF\x00\x00", "\x00\x00\x00\xFF\xFF\xFF\x00\xFF",
180  "\x00\x00\x00\xFF\xFF\xFF\xFF\x00", "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF",
181  "\x00\x00\xFF\x00\x00\x00\x00\x00", "\x00\x00\xFF\x00\x00\x00\x00\xFF",
182  "\x00\x00\xFF\x00\x00\x00\xFF\x00", "\x00\x00\xFF\x00\x00\x00\xFF\xFF",
183  "\x00\x00\xFF\x00\x00\xFF\x00\x00", "\x00\x00\xFF\x00\x00\xFF\x00\xFF",
184  "\x00\x00\xFF\x00\x00\xFF\xFF\x00", "\x00\x00\xFF\x00\x00\xFF\xFF\xFF",
185  "\x00\x00\xFF\x00\xFF\x00\x00\x00", "\x00\x00\xFF\x00\xFF\x00\x00\xFF",
186  "\x00\x00\xFF\x00\xFF\x00\xFF\x00", "\x00\x00\xFF\x00\xFF\x00\xFF\xFF",
187  "\x00\x00\xFF\x00\xFF\xFF\x00\x00", "\x00\x00\xFF\x00\xFF\xFF\x00\xFF",
188  "\x00\x00\xFF\x00\xFF\xFF\xFF\x00", "\x00\x00\xFF\x00\xFF\xFF\xFF\xFF",
189  "\x00\x00\xFF\xFF\x00\x00\x00\x00", "\x00\x00\xFF\xFF\x00\x00\x00\xFF",
190  "\x00\x00\xFF\xFF\x00\x00\xFF\x00", "\x00\x00\xFF\xFF\x00\x00\xFF\xFF",
191  "\x00\x00\xFF\xFF\x00\xFF\x00\x00", "\x00\x00\xFF\xFF\x00\xFF\x00\xFF",
192  "\x00\x00\xFF\xFF\x00\xFF\xFF\x00", "\x00\x00\xFF\xFF\x00\xFF\xFF\xFF",
193  "\x00\x00\xFF\xFF\xFF\x00\x00\x00", "\x00\x00\xFF\xFF\xFF\x00\x00\xFF",
194  "\x00\x00\xFF\xFF\xFF\x00\xFF\x00", "\x00\x00\xFF\xFF\xFF\x00\xFF\xFF",
195  "\x00\x00\xFF\xFF\xFF\xFF\x00\x00", "\x00\x00\xFF\xFF\xFF\xFF\x00\xFF",
196  "\x00\x00\xFF\xFF\xFF\xFF\xFF\x00", "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF",
197  "\x00\xFF\x00\x00\x00\x00\x00\x00", "\x00\xFF\x00\x00\x00\x00\x00\xFF",
198  "\x00\xFF\x00\x00\x00\x00\xFF\x00", "\x00\xFF\x00\x00\x00\x00\xFF\xFF",
199  "\x00\xFF\x00\x00\x00\xFF\x00\x00", "\x00\xFF\x00\x00\x00\xFF\x00\xFF",
200  "\x00\xFF\x00\x00\x00\xFF\xFF\x00", "\x00\xFF\x00\x00\x00\xFF\xFF\xFF",
201  "\x00\xFF\x00\x00\xFF\x00\x00\x00", "\x00\xFF\x00\x00\xFF\x00\x00\xFF",
202  "\x00\xFF\x00\x00\xFF\x00\xFF\x00", "\x00\xFF\x00\x00\xFF\x00\xFF\xFF",
203  "\x00\xFF\x00\x00\xFF\xFF\x00\x00", "\x00\xFF\x00\x00\xFF\xFF\x00\xFF",
204  "\x00\xFF\x00\x00\xFF\xFF\xFF\x00", "\x00\xFF\x00\x00\xFF\xFF\xFF\xFF",
205  "\x00\xFF\x00\xFF\x00\x00\x00\x00", "\x00\xFF\x00\xFF\x00\x00\x00\xFF",
206  "\x00\xFF\x00\xFF\x00\x00\xFF\x00", "\x00\xFF\x00\xFF\x00\x00\xFF\xFF",
207  "\x00\xFF\x00\xFF\x00\xFF\x00\x00", "\x00\xFF\x00\xFF\x00\xFF\x00\xFF",
208  "\x00\xFF\x00\xFF\x00\xFF\xFF\x00", "\x00\xFF\x00\xFF\x00\xFF\xFF\xFF",
209  "\x00\xFF\x00\xFF\xFF\x00\x00\x00", "\x00\xFF\x00\xFF\xFF\x00\x00\xFF",
210  "\x00\xFF\x00\xFF\xFF\x00\xFF\x00", "\x00\xFF\x00\xFF\xFF\x00\xFF\xFF",
211  "\x00\xFF\x00\xFF\xFF\xFF\x00\x00", "\x00\xFF\x00\xFF\xFF\xFF\x00\xFF",
212  "\x00\xFF\x00\xFF\xFF\xFF\xFF\x00", "\x00\xFF\x00\xFF\xFF\xFF\xFF\xFF",
213  "\x00\xFF\xFF\x00\x00\x00\x00\x00", "\x00\xFF\xFF\x00\x00\x00\x00\xFF",
214  "\x00\xFF\xFF\x00\x00\x00\xFF\x00", "\x00\xFF\xFF\x00\x00\x00\xFF\xFF",
215  "\x00\xFF\xFF\x00\x00\xFF\x00\x00", "\x00\xFF\xFF\x00\x00\xFF\x00\xFF",
216  "\x00\xFF\xFF\x00\x00\xFF\xFF\x00", "\x00\xFF\xFF\x00\x00\xFF\xFF\xFF",
217  "\x00\xFF\xFF\x00\xFF\x00\x00\x00", "\x00\xFF\xFF\x00\xFF\x00\x00\xFF",
218  "\x00\xFF\xFF\x00\xFF\x00\xFF\x00", "\x00\xFF\xFF\x00\xFF\x00\xFF\xFF",
219  "\x00\xFF\xFF\x00\xFF\xFF\x00\x00", "\x00\xFF\xFF\x00\xFF\xFF\x00\xFF",
220  "\x00\xFF\xFF\x00\xFF\xFF\xFF\x00", "\x00\xFF\xFF\x00\xFF\xFF\xFF\xFF",
221  "\x00\xFF\xFF\xFF\x00\x00\x00\x00", "\x00\xFF\xFF\xFF\x00\x00\x00\xFF",
222  "\x00\xFF\xFF\xFF\x00\x00\xFF\x00", "\x00\xFF\xFF\xFF\x00\x00\xFF\xFF",
223  "\x00\xFF\xFF\xFF\x00\xFF\x00\x00", "\x00\xFF\xFF\xFF\x00\xFF\x00\xFF",
224  "\x00\xFF\xFF\xFF\x00\xFF\xFF\x00", "\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF",
225  "\x00\xFF\xFF\xFF\xFF\x00\x00\x00", "\x00\xFF\xFF\xFF\xFF\x00\x00\xFF",
226  "\x00\xFF\xFF\xFF\xFF\x00\xFF\x00", "\x00\xFF\xFF\xFF\xFF\x00\xFF\xFF",
227  "\x00\xFF\xFF\xFF\xFF\xFF\x00\x00", "\x00\xFF\xFF\xFF\xFF\xFF\x00\xFF",
228  "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
229  "\xFF\x00\x00\x00\x00\x00\x00\x00", "\xFF\x00\x00\x00\x00\x00\x00\xFF",
230  "\xFF\x00\x00\x00\x00\x00\xFF\x00", "\xFF\x00\x00\x00\x00\x00\xFF\xFF",
231  "\xFF\x00\x00\x00\x00\xFF\x00\x00", "\xFF\x00\x00\x00\x00\xFF\x00\xFF",
232  "\xFF\x00\x00\x00\x00\xFF\xFF\x00", "\xFF\x00\x00\x00\x00\xFF\xFF\xFF",
233  "\xFF\x00\x00\x00\xFF\x00\x00\x00", "\xFF\x00\x00\x00\xFF\x00\x00\xFF",
234  "\xFF\x00\x00\x00\xFF\x00\xFF\x00", "\xFF\x00\x00\x00\xFF\x00\xFF\xFF",
235  "\xFF\x00\x00\x00\xFF\xFF\x00\x00", "\xFF\x00\x00\x00\xFF\xFF\x00\xFF",
236  "\xFF\x00\x00\x00\xFF\xFF\xFF\x00", "\xFF\x00\x00\x00\xFF\xFF\xFF\xFF",
237  "\xFF\x00\x00\xFF\x00\x00\x00\x00", "\xFF\x00\x00\xFF\x00\x00\x00\xFF",
238  "\xFF\x00\x00\xFF\x00\x00\xFF\x00", "\xFF\x00\x00\xFF\x00\x00\xFF\xFF",
239  "\xFF\x00\x00\xFF\x00\xFF\x00\x00", "\xFF\x00\x00\xFF\x00\xFF\x00\xFF",
240  "\xFF\x00\x00\xFF\x00\xFF\xFF\x00", "\xFF\x00\x00\xFF\x00\xFF\xFF\xFF",
241  "\xFF\x00\x00\xFF\xFF\x00\x00\x00", "\xFF\x00\x00\xFF\xFF\x00\x00\xFF",
242  "\xFF\x00\x00\xFF\xFF\x00\xFF\x00", "\xFF\x00\x00\xFF\xFF\x00\xFF\xFF",
243  "\xFF\x00\x00\xFF\xFF\xFF\x00\x00", "\xFF\x00\x00\xFF\xFF\xFF\x00\xFF",
244  "\xFF\x00\x00\xFF\xFF\xFF\xFF\x00", "\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF",
245  "\xFF\x00\xFF\x00\x00\x00\x00\x00", "\xFF\x00\xFF\x00\x00\x00\x00\xFF",
246  "\xFF\x00\xFF\x00\x00\x00\xFF\x00", "\xFF\x00\xFF\x00\x00\x00\xFF\xFF",
247  "\xFF\x00\xFF\x00\x00\xFF\x00\x00", "\xFF\x00\xFF\x00\x00\xFF\x00\xFF",
248  "\xFF\x00\xFF\x00\x00\xFF\xFF\x00", "\xFF\x00\xFF\x00\x00\xFF\xFF\xFF",
249  "\xFF\x00\xFF\x00\xFF\x00\x00\x00", "\xFF\x00\xFF\x00\xFF\x00\x00\xFF",
250  "\xFF\x00\xFF\x00\xFF\x00\xFF\x00", "\xFF\x00\xFF\x00\xFF\x00\xFF\xFF",
251  "\xFF\x00\xFF\x00\xFF\xFF\x00\x00", "\xFF\x00\xFF\x00\xFF\xFF\x00\xFF",
252  "\xFF\x00\xFF\x00\xFF\xFF\xFF\x00", "\xFF\x00\xFF\x00\xFF\xFF\xFF\xFF",
253  "\xFF\x00\xFF\xFF\x00\x00\x00\x00", "\xFF\x00\xFF\xFF\x00\x00\x00\xFF",
254  "\xFF\x00\xFF\xFF\x00\x00\xFF\x00", "\xFF\x00\xFF\xFF\x00\x00\xFF\xFF",
255  "\xFF\x00\xFF\xFF\x00\xFF\x00\x00", "\xFF\x00\xFF\xFF\x00\xFF\x00\xFF",
256  "\xFF\x00\xFF\xFF\x00\xFF\xFF\x00", "\xFF\x00\xFF\xFF\x00\xFF\xFF\xFF",
257  "\xFF\x00\xFF\xFF\xFF\x00\x00\x00", "\xFF\x00\xFF\xFF\xFF\x00\x00\xFF",
258  "\xFF\x00\xFF\xFF\xFF\x00\xFF\x00", "\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF",
259  "\xFF\x00\xFF\xFF\xFF\xFF\x00\x00", "\xFF\x00\xFF\xFF\xFF\xFF\x00\xFF",
260  "\xFF\x00\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF",
261  "\xFF\xFF\x00\x00\x00\x00\x00\x00", "\xFF\xFF\x00\x00\x00\x00\x00\xFF",
262  "\xFF\xFF\x00\x00\x00\x00\xFF\x00", "\xFF\xFF\x00\x00\x00\x00\xFF\xFF",
263  "\xFF\xFF\x00\x00\x00\xFF\x00\x00", "\xFF\xFF\x00\x00\x00\xFF\x00\xFF",
264  "\xFF\xFF\x00\x00\x00\xFF\xFF\x00", "\xFF\xFF\x00\x00\x00\xFF\xFF\xFF",
265  "\xFF\xFF\x00\x00\xFF\x00\x00\x00", "\xFF\xFF\x00\x00\xFF\x00\x00\xFF",
266  "\xFF\xFF\x00\x00\xFF\x00\xFF\x00", "\xFF\xFF\x00\x00\xFF\x00\xFF\xFF",
267  "\xFF\xFF\x00\x00\xFF\xFF\x00\x00", "\xFF\xFF\x00\x00\xFF\xFF\x00\xFF",
268  "\xFF\xFF\x00\x00\xFF\xFF\xFF\x00", "\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF",
269  "\xFF\xFF\x00\xFF\x00\x00\x00\x00", "\xFF\xFF\x00\xFF\x00\x00\x00\xFF",
270  "\xFF\xFF\x00\xFF\x00\x00\xFF\x00", "\xFF\xFF\x00\xFF\x00\x00\xFF\xFF",
271  "\xFF\xFF\x00\xFF\x00\xFF\x00\x00", "\xFF\xFF\x00\xFF\x00\xFF\x00\xFF",
272  "\xFF\xFF\x00\xFF\x00\xFF\xFF\x00", "\xFF\xFF\x00\xFF\x00\xFF\xFF\xFF",
273  "\xFF\xFF\x00\xFF\xFF\x00\x00\x00", "\xFF\xFF\x00\xFF\xFF\x00\x00\xFF",
274  "\xFF\xFF\x00\xFF\xFF\x00\xFF\x00", "\xFF\xFF\x00\xFF\xFF\x00\xFF\xFF",
275  "\xFF\xFF\x00\xFF\xFF\xFF\x00\x00", "\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF",
276  "\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF",
277  "\xFF\xFF\xFF\x00\x00\x00\x00\x00", "\xFF\xFF\xFF\x00\x00\x00\x00\xFF",
278  "\xFF\xFF\xFF\x00\x00\x00\xFF\x00", "\xFF\xFF\xFF\x00\x00\x00\xFF\xFF",
279  "\xFF\xFF\xFF\x00\x00\xFF\x00\x00", "\xFF\xFF\xFF\x00\x00\xFF\x00\xFF",
280  "\xFF\xFF\xFF\x00\x00\xFF\xFF\x00", "\xFF\xFF\xFF\x00\x00\xFF\xFF\xFF",
281  "\xFF\xFF\xFF\x00\xFF\x00\x00\x00", "\xFF\xFF\xFF\x00\xFF\x00\x00\xFF",
282  "\xFF\xFF\xFF\x00\xFF\x00\xFF\x00", "\xFF\xFF\xFF\x00\xFF\x00\xFF\xFF",
283  "\xFF\xFF\xFF\x00\xFF\xFF\x00\x00", "\xFF\xFF\xFF\x00\xFF\xFF\x00\xFF",
284  "\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF",
285  "\xFF\xFF\xFF\xFF\x00\x00\x00\x00", "\xFF\xFF\xFF\xFF\x00\x00\x00\xFF",
286  "\xFF\xFF\xFF\xFF\x00\x00\xFF\x00", "\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF",
287  "\xFF\xFF\xFF\xFF\x00\xFF\x00\x00", "\xFF\xFF\xFF\xFF\x00\xFF\x00\xFF",
288  "\xFF\xFF\xFF\xFF\x00\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF",
289  "\xFF\xFF\xFF\xFF\xFF\x00\x00\x00", "\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF",
290  "\xFF\xFF\xFF\xFF\xFF\x00\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF",
291  "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF",
292  "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
293  );
294 
303  var $ipmap = array(
304  0x00, 0x10, 0x01, 0x11, 0x20, 0x30, 0x21, 0x31,
305  0x02, 0x12, 0x03, 0x13, 0x22, 0x32, 0x23, 0x33,
306  0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71,
307  0x42, 0x52, 0x43, 0x53, 0x62, 0x72, 0x63, 0x73,
308  0x04, 0x14, 0x05, 0x15, 0x24, 0x34, 0x25, 0x35,
309  0x06, 0x16, 0x07, 0x17, 0x26, 0x36, 0x27, 0x37,
310  0x44, 0x54, 0x45, 0x55, 0x64, 0x74, 0x65, 0x75,
311  0x46, 0x56, 0x47, 0x57, 0x66, 0x76, 0x67, 0x77,
312  0x80, 0x90, 0x81, 0x91, 0xA0, 0xB0, 0xA1, 0xB1,
313  0x82, 0x92, 0x83, 0x93, 0xA2, 0xB2, 0xA3, 0xB3,
314  0xC0, 0xD0, 0xC1, 0xD1, 0xE0, 0xF0, 0xE1, 0xF1,
315  0xC2, 0xD2, 0xC3, 0xD3, 0xE2, 0xF2, 0xE3, 0xF3,
316  0x84, 0x94, 0x85, 0x95, 0xA4, 0xB4, 0xA5, 0xB5,
317  0x86, 0x96, 0x87, 0x97, 0xA6, 0xB6, 0xA7, 0xB7,
318  0xC4, 0xD4, 0xC5, 0xD5, 0xE4, 0xF4, 0xE5, 0xF5,
319  0xC6, 0xD6, 0xC7, 0xD7, 0xE6, 0xF6, 0xE7, 0xF7,
320  0x08, 0x18, 0x09, 0x19, 0x28, 0x38, 0x29, 0x39,
321  0x0A, 0x1A, 0x0B, 0x1B, 0x2A, 0x3A, 0x2B, 0x3B,
322  0x48, 0x58, 0x49, 0x59, 0x68, 0x78, 0x69, 0x79,
323  0x4A, 0x5A, 0x4B, 0x5B, 0x6A, 0x7A, 0x6B, 0x7B,
324  0x0C, 0x1C, 0x0D, 0x1D, 0x2C, 0x3C, 0x2D, 0x3D,
325  0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F,
326  0x4C, 0x5C, 0x4D, 0x5D, 0x6C, 0x7C, 0x6D, 0x7D,
327  0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F,
328  0x88, 0x98, 0x89, 0x99, 0xA8, 0xB8, 0xA9, 0xB9,
329  0x8A, 0x9A, 0x8B, 0x9B, 0xAA, 0xBA, 0xAB, 0xBB,
330  0xC8, 0xD8, 0xC9, 0xD9, 0xE8, 0xF8, 0xE9, 0xF9,
331  0xCA, 0xDA, 0xCB, 0xDB, 0xEA, 0xFA, 0xEB, 0xFB,
332  0x8C, 0x9C, 0x8D, 0x9D, 0xAC, 0xBC, 0xAD, 0xBD,
333  0x8E, 0x9E, 0x8F, 0x9F, 0xAE, 0xBE, 0xAF, 0xBF,
334  0xCC, 0xDC, 0xCD, 0xDD, 0xEC, 0xFC, 0xED, 0xFD,
335  0xCE, 0xDE, 0xCF, 0xDF, 0xEE, 0xFE, 0xEF, 0xFF
336  );
337 
345  var $invipmap = array(
346  0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
347  0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
348  0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
349  0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
350  0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
351  0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
352  0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
353  0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
354  0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
355  0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
356  0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
357  0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
358  0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
359  0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
360  0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
361  0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
362  0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
363  0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
364  0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
365  0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
366  0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
367  0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
368  0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
369  0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
370  0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
371  0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
372  0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
373  0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
374  0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
375  0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
376  0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
377  0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
378  );
379 
389  var $sbox1 = array(
390  0x00808200, 0x00000000, 0x00008000, 0x00808202,
391  0x00808002, 0x00008202, 0x00000002, 0x00008000,
392  0x00000200, 0x00808200, 0x00808202, 0x00000200,
393  0x00800202, 0x00808002, 0x00800000, 0x00000002,
394  0x00000202, 0x00800200, 0x00800200, 0x00008200,
395  0x00008200, 0x00808000, 0x00808000, 0x00800202,
396  0x00008002, 0x00800002, 0x00800002, 0x00008002,
397  0x00000000, 0x00000202, 0x00008202, 0x00800000,
398  0x00008000, 0x00808202, 0x00000002, 0x00808000,
399  0x00808200, 0x00800000, 0x00800000, 0x00000200,
400  0x00808002, 0x00008000, 0x00008200, 0x00800002,
401  0x00000200, 0x00000002, 0x00800202, 0x00008202,
402  0x00808202, 0x00008002, 0x00808000, 0x00800202,
403  0x00800002, 0x00000202, 0x00008202, 0x00808200,
404  0x00000202, 0x00800200, 0x00800200, 0x00000000,
405  0x00008002, 0x00008200, 0x00000000, 0x00808002
406  );
407 
414  var $sbox2 = array(
415  0x40084010, 0x40004000, 0x00004000, 0x00084010,
416  0x00080000, 0x00000010, 0x40080010, 0x40004010,
417  0x40000010, 0x40084010, 0x40084000, 0x40000000,
418  0x40004000, 0x00080000, 0x00000010, 0x40080010,
419  0x00084000, 0x00080010, 0x40004010, 0x00000000,
420  0x40000000, 0x00004000, 0x00084010, 0x40080000,
421  0x00080010, 0x40000010, 0x00000000, 0x00084000,
422  0x00004010, 0x40084000, 0x40080000, 0x00004010,
423  0x00000000, 0x00084010, 0x40080010, 0x00080000,
424  0x40004010, 0x40080000, 0x40084000, 0x00004000,
425  0x40080000, 0x40004000, 0x00000010, 0x40084010,
426  0x00084010, 0x00000010, 0x00004000, 0x40000000,
427  0x00004010, 0x40084000, 0x00080000, 0x40000010,
428  0x00080010, 0x40004010, 0x40000010, 0x00080010,
429  0x00084000, 0x00000000, 0x40004000, 0x00004010,
430  0x40000000, 0x40080010, 0x40084010, 0x00084000
431  );
432 
439  var $sbox3 = array(
440  0x00000104, 0x04010100, 0x00000000, 0x04010004,
441  0x04000100, 0x00000000, 0x00010104, 0x04000100,
442  0x00010004, 0x04000004, 0x04000004, 0x00010000,
443  0x04010104, 0x00010004, 0x04010000, 0x00000104,
444  0x04000000, 0x00000004, 0x04010100, 0x00000100,
445  0x00010100, 0x04010000, 0x04010004, 0x00010104,
446  0x04000104, 0x00010100, 0x00010000, 0x04000104,
447  0x00000004, 0x04010104, 0x00000100, 0x04000000,
448  0x04010100, 0x04000000, 0x00010004, 0x00000104,
449  0x00010000, 0x04010100, 0x04000100, 0x00000000,
450  0x00000100, 0x00010004, 0x04010104, 0x04000100,
451  0x04000004, 0x00000100, 0x00000000, 0x04010004,
452  0x04000104, 0x00010000, 0x04000000, 0x04010104,
453  0x00000004, 0x00010104, 0x00010100, 0x04000004,
454  0x04010000, 0x04000104, 0x00000104, 0x04010000,
455  0x00010104, 0x00000004, 0x04010004, 0x00010100
456  );
457 
464  var $sbox4 = array(
465  0x80401000, 0x80001040, 0x80001040, 0x00000040,
466  0x00401040, 0x80400040, 0x80400000, 0x80001000,
467  0x00000000, 0x00401000, 0x00401000, 0x80401040,
468  0x80000040, 0x00000000, 0x00400040, 0x80400000,
469  0x80000000, 0x00001000, 0x00400000, 0x80401000,
470  0x00000040, 0x00400000, 0x80001000, 0x00001040,
471  0x80400040, 0x80000000, 0x00001040, 0x00400040,
472  0x00001000, 0x00401040, 0x80401040, 0x80000040,
473  0x00400040, 0x80400000, 0x00401000, 0x80401040,
474  0x80000040, 0x00000000, 0x00000000, 0x00401000,
475  0x00001040, 0x00400040, 0x80400040, 0x80000000,
476  0x80401000, 0x80001040, 0x80001040, 0x00000040,
477  0x80401040, 0x80000040, 0x80000000, 0x00001000,
478  0x80400000, 0x80001000, 0x00401040, 0x80400040,
479  0x80001000, 0x00001040, 0x00400000, 0x80401000,
480  0x00000040, 0x00400000, 0x00001000, 0x00401040
481  );
482 
489  var $sbox5 = array(
490  0x00000080, 0x01040080, 0x01040000, 0x21000080,
491  0x00040000, 0x00000080, 0x20000000, 0x01040000,
492  0x20040080, 0x00040000, 0x01000080, 0x20040080,
493  0x21000080, 0x21040000, 0x00040080, 0x20000000,
494  0x01000000, 0x20040000, 0x20040000, 0x00000000,
495  0x20000080, 0x21040080, 0x21040080, 0x01000080,
496  0x21040000, 0x20000080, 0x00000000, 0x21000000,
497  0x01040080, 0x01000000, 0x21000000, 0x00040080,
498  0x00040000, 0x21000080, 0x00000080, 0x01000000,
499  0x20000000, 0x01040000, 0x21000080, 0x20040080,
500  0x01000080, 0x20000000, 0x21040000, 0x01040080,
501  0x20040080, 0x00000080, 0x01000000, 0x21040000,
502  0x21040080, 0x00040080, 0x21000000, 0x21040080,
503  0x01040000, 0x00000000, 0x20040000, 0x21000000,
504  0x00040080, 0x01000080, 0x20000080, 0x00040000,
505  0x00000000, 0x20040000, 0x01040080, 0x20000080
506  );
507 
514  var $sbox6 = array(
515  0x10000008, 0x10200000, 0x00002000, 0x10202008,
516  0x10200000, 0x00000008, 0x10202008, 0x00200000,
517  0x10002000, 0x00202008, 0x00200000, 0x10000008,
518  0x00200008, 0x10002000, 0x10000000, 0x00002008,
519  0x00000000, 0x00200008, 0x10002008, 0x00002000,
520  0x00202000, 0x10002008, 0x00000008, 0x10200008,
521  0x10200008, 0x00000000, 0x00202008, 0x10202000,
522  0x00002008, 0x00202000, 0x10202000, 0x10000000,
523  0x10002000, 0x00000008, 0x10200008, 0x00202000,
524  0x10202008, 0x00200000, 0x00002008, 0x10000008,
525  0x00200000, 0x10002000, 0x10000000, 0x00002008,
526  0x10000008, 0x10202008, 0x00202000, 0x10200000,
527  0x00202008, 0x10202000, 0x00000000, 0x10200008,
528  0x00000008, 0x00002000, 0x10200000, 0x00202008,
529  0x00002000, 0x00200008, 0x10002008, 0x00000000,
530  0x10202000, 0x10000000, 0x00200008, 0x10002008
531  );
532 
539  var $sbox7 = array(
540  0x00100000, 0x02100001, 0x02000401, 0x00000000,
541  0x00000400, 0x02000401, 0x00100401, 0x02100400,
542  0x02100401, 0x00100000, 0x00000000, 0x02000001,
543  0x00000001, 0x02000000, 0x02100001, 0x00000401,
544  0x02000400, 0x00100401, 0x00100001, 0x02000400,
545  0x02000001, 0x02100000, 0x02100400, 0x00100001,
546  0x02100000, 0x00000400, 0x00000401, 0x02100401,
547  0x00100400, 0x00000001, 0x02000000, 0x00100400,
548  0x02000000, 0x00100400, 0x00100000, 0x02000401,
549  0x02000401, 0x02100001, 0x02100001, 0x00000001,
550  0x00100001, 0x02000000, 0x02000400, 0x00100000,
551  0x02100400, 0x00000401, 0x00100401, 0x02100400,
552  0x00000401, 0x02000001, 0x02100401, 0x02100000,
553  0x00100400, 0x00000000, 0x00000001, 0x02100401,
554  0x00000000, 0x00100401, 0x02100000, 0x00000400,
555  0x02000001, 0x02000400, 0x00000400, 0x00100001
556  );
557 
564  var $sbox8 = array(
565  0x08000820, 0x00000800, 0x00020000, 0x08020820,
566  0x08000000, 0x08000820, 0x00000020, 0x08000000,
567  0x00020020, 0x08020000, 0x08020820, 0x00020800,
568  0x08020800, 0x00020820, 0x00000800, 0x00000020,
569  0x08020000, 0x08000020, 0x08000800, 0x00000820,
570  0x00020800, 0x00020020, 0x08020020, 0x08020800,
571  0x00000820, 0x00000000, 0x00000000, 0x08020020,
572  0x08000020, 0x08000800, 0x00020820, 0x00020000,
573  0x00020820, 0x00020000, 0x08020800, 0x00000800,
574  0x00000020, 0x08020020, 0x00000800, 0x00020820,
575  0x08000800, 0x00000020, 0x08000020, 0x08020000,
576  0x08020020, 0x08000000, 0x00020000, 0x08000820,
577  0x00000000, 0x08020820, 0x00020020, 0x08000020,
578  0x08020000, 0x08000800, 0x08000820, 0x00000000,
579  0x08020820, 0x00020800, 0x00020800, 0x00000820,
580  0x00000820, 0x00020020, 0x08000000, 0x08020800
581  );
582 
594  {
595  if ($this->key_length_max == 8) {
596  if ($engine == self::ENGINE_OPENSSL) {
597  $this->cipher_name_openssl_ecb = 'des-ecb';
598  $this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode();
599  }
600  }
601 
602  return parent::isValidEngine($engine);
603  }
604 
620  function setKey($key)
621  {
622  // We check/cut here only up to max length of the key.
623  // Key padding to the proper length will be done in _setupKey()
624  if (strlen($key) > $this->key_length_max) {
625  $key = substr($key, 0, $this->key_length_max);
626  }
627 
628  // Sets the key
629  parent::setKey($key);
630  }
631 
642  function _encryptBlock($in)
643  {
644  return $this->_processBlock($in, self::ENCRYPT);
645  }
646 
657  function _decryptBlock($in)
658  {
659  return $this->_processBlock($in, self::DECRYPT);
660  }
661 
676  function _processBlock($block, $mode)
677  {
678  static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
679  if (!$sbox1) {
680  $sbox1 = array_map("intval", $this->sbox1);
681  $sbox2 = array_map("intval", $this->sbox2);
682  $sbox3 = array_map("intval", $this->sbox3);
683  $sbox4 = array_map("intval", $this->sbox4);
684  $sbox5 = array_map("intval", $this->sbox5);
685  $sbox6 = array_map("intval", $this->sbox6);
686  $sbox7 = array_map("intval", $this->sbox7);
687  $sbox8 = array_map("intval", $this->sbox8);
688  /* Merge $shuffle with $[inv]ipmap */
689  for ($i = 0; $i < 256; ++$i) {
690  $shuffleip[] = $this->shuffle[$this->ipmap[$i]];
691  $shuffleinvip[] = $this->shuffle[$this->invipmap[$i]];
692  }
693  }
694 
695  $keys = $this->keys[$mode];
696  $ki = -1;
697 
698  // Do the initial IP permutation.
699  $t = unpack('Nl/Nr', $block);
700  list($l, $r) = array($t['l'], $t['r']);
701  $block = ($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
702  ($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
703  ($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
704  ($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
705  ($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
706  ($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
707  ($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
708  ($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01");
709 
710  // Extract L0 and R0.
711  $t = unpack('Nl/Nr', $block);
712  list($l, $r) = array($t['l'], $t['r']);
713 
714  for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) {
715  // Perform the 16 steps.
716  for ($i = 0; $i < 16; $i++) {
717  // start of "the Feistel (F) function" - see the following URL:
718  // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
719  // Merge key schedule.
720  $b1 = (($r >> 3) & 0x1FFFFFFF) ^ ($r << 29) ^ $keys[++$ki];
721  $b2 = (($r >> 31) & 0x00000001) ^ ($r << 1) ^ $keys[++$ki];
722 
723  // S-box indexing.
724  $t = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
725  $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
726  $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
727  $sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ $l;
728  // end of "the Feistel (F) function"
729 
730  $l = $r;
731  $r = $t;
732  }
733 
734  // Last step should not permute L & R.
735  $t = $l;
736  $l = $r;
737  $r = $t;
738  }
739 
740  // Perform the inverse IP permutation.
741  return ($shuffleinvip[($r >> 24) & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
742  ($shuffleinvip[($l >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
743  ($shuffleinvip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
744  ($shuffleinvip[($l >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
745  ($shuffleinvip[($r >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
746  ($shuffleinvip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
747  ($shuffleinvip[ $r & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
748  ($shuffleinvip[ $l & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01");
749  }
750 
757  function _setupKey()
758  {
759  if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->des_rounds === $this->kl['des_rounds']) {
760  // already expanded
761  return;
762  }
763  $this->kl = array('key' => $this->key, 'des_rounds' => $this->des_rounds);
764 
765  static $shifts = array( // number of key bits shifted per round
766  1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
767  );
768 
769  static $pc1map = array(
770  0x00, 0x00, 0x08, 0x08, 0x04, 0x04, 0x0C, 0x0C,
771  0x02, 0x02, 0x0A, 0x0A, 0x06, 0x06, 0x0E, 0x0E,
772  0x10, 0x10, 0x18, 0x18, 0x14, 0x14, 0x1C, 0x1C,
773  0x12, 0x12, 0x1A, 0x1A, 0x16, 0x16, 0x1E, 0x1E,
774  0x20, 0x20, 0x28, 0x28, 0x24, 0x24, 0x2C, 0x2C,
775  0x22, 0x22, 0x2A, 0x2A, 0x26, 0x26, 0x2E, 0x2E,
776  0x30, 0x30, 0x38, 0x38, 0x34, 0x34, 0x3C, 0x3C,
777  0x32, 0x32, 0x3A, 0x3A, 0x36, 0x36, 0x3E, 0x3E,
778  0x40, 0x40, 0x48, 0x48, 0x44, 0x44, 0x4C, 0x4C,
779  0x42, 0x42, 0x4A, 0x4A, 0x46, 0x46, 0x4E, 0x4E,
780  0x50, 0x50, 0x58, 0x58, 0x54, 0x54, 0x5C, 0x5C,
781  0x52, 0x52, 0x5A, 0x5A, 0x56, 0x56, 0x5E, 0x5E,
782  0x60, 0x60, 0x68, 0x68, 0x64, 0x64, 0x6C, 0x6C,
783  0x62, 0x62, 0x6A, 0x6A, 0x66, 0x66, 0x6E, 0x6E,
784  0x70, 0x70, 0x78, 0x78, 0x74, 0x74, 0x7C, 0x7C,
785  0x72, 0x72, 0x7A, 0x7A, 0x76, 0x76, 0x7E, 0x7E,
786  0x80, 0x80, 0x88, 0x88, 0x84, 0x84, 0x8C, 0x8C,
787  0x82, 0x82, 0x8A, 0x8A, 0x86, 0x86, 0x8E, 0x8E,
788  0x90, 0x90, 0x98, 0x98, 0x94, 0x94, 0x9C, 0x9C,
789  0x92, 0x92, 0x9A, 0x9A, 0x96, 0x96, 0x9E, 0x9E,
790  0xA0, 0xA0, 0xA8, 0xA8, 0xA4, 0xA4, 0xAC, 0xAC,
791  0xA2, 0xA2, 0xAA, 0xAA, 0xA6, 0xA6, 0xAE, 0xAE,
792  0xB0, 0xB0, 0xB8, 0xB8, 0xB4, 0xB4, 0xBC, 0xBC,
793  0xB2, 0xB2, 0xBA, 0xBA, 0xB6, 0xB6, 0xBE, 0xBE,
794  0xC0, 0xC0, 0xC8, 0xC8, 0xC4, 0xC4, 0xCC, 0xCC,
795  0xC2, 0xC2, 0xCA, 0xCA, 0xC6, 0xC6, 0xCE, 0xCE,
796  0xD0, 0xD0, 0xD8, 0xD8, 0xD4, 0xD4, 0xDC, 0xDC,
797  0xD2, 0xD2, 0xDA, 0xDA, 0xD6, 0xD6, 0xDE, 0xDE,
798  0xE0, 0xE0, 0xE8, 0xE8, 0xE4, 0xE4, 0xEC, 0xEC,
799  0xE2, 0xE2, 0xEA, 0xEA, 0xE6, 0xE6, 0xEE, 0xEE,
800  0xF0, 0xF0, 0xF8, 0xF8, 0xF4, 0xF4, 0xFC, 0xFC,
801  0xF2, 0xF2, 0xFA, 0xFA, 0xF6, 0xF6, 0xFE, 0xFE
802  );
803 
804  // Mapping tables for the PC-2 transformation.
805  static $pc2mapc1 = array(
806  0x00000000, 0x00000400, 0x00200000, 0x00200400,
807  0x00000001, 0x00000401, 0x00200001, 0x00200401,
808  0x02000000, 0x02000400, 0x02200000, 0x02200400,
809  0x02000001, 0x02000401, 0x02200001, 0x02200401
810  );
811  static $pc2mapc2 = array(
812  0x00000000, 0x00000800, 0x08000000, 0x08000800,
813  0x00010000, 0x00010800, 0x08010000, 0x08010800,
814  0x00000000, 0x00000800, 0x08000000, 0x08000800,
815  0x00010000, 0x00010800, 0x08010000, 0x08010800,
816  0x00000100, 0x00000900, 0x08000100, 0x08000900,
817  0x00010100, 0x00010900, 0x08010100, 0x08010900,
818  0x00000100, 0x00000900, 0x08000100, 0x08000900,
819  0x00010100, 0x00010900, 0x08010100, 0x08010900,
820  0x00000010, 0x00000810, 0x08000010, 0x08000810,
821  0x00010010, 0x00010810, 0x08010010, 0x08010810,
822  0x00000010, 0x00000810, 0x08000010, 0x08000810,
823  0x00010010, 0x00010810, 0x08010010, 0x08010810,
824  0x00000110, 0x00000910, 0x08000110, 0x08000910,
825  0x00010110, 0x00010910, 0x08010110, 0x08010910,
826  0x00000110, 0x00000910, 0x08000110, 0x08000910,
827  0x00010110, 0x00010910, 0x08010110, 0x08010910,
828  0x00040000, 0x00040800, 0x08040000, 0x08040800,
829  0x00050000, 0x00050800, 0x08050000, 0x08050800,
830  0x00040000, 0x00040800, 0x08040000, 0x08040800,
831  0x00050000, 0x00050800, 0x08050000, 0x08050800,
832  0x00040100, 0x00040900, 0x08040100, 0x08040900,
833  0x00050100, 0x00050900, 0x08050100, 0x08050900,
834  0x00040100, 0x00040900, 0x08040100, 0x08040900,
835  0x00050100, 0x00050900, 0x08050100, 0x08050900,
836  0x00040010, 0x00040810, 0x08040010, 0x08040810,
837  0x00050010, 0x00050810, 0x08050010, 0x08050810,
838  0x00040010, 0x00040810, 0x08040010, 0x08040810,
839  0x00050010, 0x00050810, 0x08050010, 0x08050810,
840  0x00040110, 0x00040910, 0x08040110, 0x08040910,
841  0x00050110, 0x00050910, 0x08050110, 0x08050910,
842  0x00040110, 0x00040910, 0x08040110, 0x08040910,
843  0x00050110, 0x00050910, 0x08050110, 0x08050910,
844  0x01000000, 0x01000800, 0x09000000, 0x09000800,
845  0x01010000, 0x01010800, 0x09010000, 0x09010800,
846  0x01000000, 0x01000800, 0x09000000, 0x09000800,
847  0x01010000, 0x01010800, 0x09010000, 0x09010800,
848  0x01000100, 0x01000900, 0x09000100, 0x09000900,
849  0x01010100, 0x01010900, 0x09010100, 0x09010900,
850  0x01000100, 0x01000900, 0x09000100, 0x09000900,
851  0x01010100, 0x01010900, 0x09010100, 0x09010900,
852  0x01000010, 0x01000810, 0x09000010, 0x09000810,
853  0x01010010, 0x01010810, 0x09010010, 0x09010810,
854  0x01000010, 0x01000810, 0x09000010, 0x09000810,
855  0x01010010, 0x01010810, 0x09010010, 0x09010810,
856  0x01000110, 0x01000910, 0x09000110, 0x09000910,
857  0x01010110, 0x01010910, 0x09010110, 0x09010910,
858  0x01000110, 0x01000910, 0x09000110, 0x09000910,
859  0x01010110, 0x01010910, 0x09010110, 0x09010910,
860  0x01040000, 0x01040800, 0x09040000, 0x09040800,
861  0x01050000, 0x01050800, 0x09050000, 0x09050800,
862  0x01040000, 0x01040800, 0x09040000, 0x09040800,
863  0x01050000, 0x01050800, 0x09050000, 0x09050800,
864  0x01040100, 0x01040900, 0x09040100, 0x09040900,
865  0x01050100, 0x01050900, 0x09050100, 0x09050900,
866  0x01040100, 0x01040900, 0x09040100, 0x09040900,
867  0x01050100, 0x01050900, 0x09050100, 0x09050900,
868  0x01040010, 0x01040810, 0x09040010, 0x09040810,
869  0x01050010, 0x01050810, 0x09050010, 0x09050810,
870  0x01040010, 0x01040810, 0x09040010, 0x09040810,
871  0x01050010, 0x01050810, 0x09050010, 0x09050810,
872  0x01040110, 0x01040910, 0x09040110, 0x09040910,
873  0x01050110, 0x01050910, 0x09050110, 0x09050910,
874  0x01040110, 0x01040910, 0x09040110, 0x09040910,
875  0x01050110, 0x01050910, 0x09050110, 0x09050910
876  );
877  static $pc2mapc3 = array(
878  0x00000000, 0x00000004, 0x00001000, 0x00001004,
879  0x00000000, 0x00000004, 0x00001000, 0x00001004,
880  0x10000000, 0x10000004, 0x10001000, 0x10001004,
881  0x10000000, 0x10000004, 0x10001000, 0x10001004,
882  0x00000020, 0x00000024, 0x00001020, 0x00001024,
883  0x00000020, 0x00000024, 0x00001020, 0x00001024,
884  0x10000020, 0x10000024, 0x10001020, 0x10001024,
885  0x10000020, 0x10000024, 0x10001020, 0x10001024,
886  0x00080000, 0x00080004, 0x00081000, 0x00081004,
887  0x00080000, 0x00080004, 0x00081000, 0x00081004,
888  0x10080000, 0x10080004, 0x10081000, 0x10081004,
889  0x10080000, 0x10080004, 0x10081000, 0x10081004,
890  0x00080020, 0x00080024, 0x00081020, 0x00081024,
891  0x00080020, 0x00080024, 0x00081020, 0x00081024,
892  0x10080020, 0x10080024, 0x10081020, 0x10081024,
893  0x10080020, 0x10080024, 0x10081020, 0x10081024,
894  0x20000000, 0x20000004, 0x20001000, 0x20001004,
895  0x20000000, 0x20000004, 0x20001000, 0x20001004,
896  0x30000000, 0x30000004, 0x30001000, 0x30001004,
897  0x30000000, 0x30000004, 0x30001000, 0x30001004,
898  0x20000020, 0x20000024, 0x20001020, 0x20001024,
899  0x20000020, 0x20000024, 0x20001020, 0x20001024,
900  0x30000020, 0x30000024, 0x30001020, 0x30001024,
901  0x30000020, 0x30000024, 0x30001020, 0x30001024,
902  0x20080000, 0x20080004, 0x20081000, 0x20081004,
903  0x20080000, 0x20080004, 0x20081000, 0x20081004,
904  0x30080000, 0x30080004, 0x30081000, 0x30081004,
905  0x30080000, 0x30080004, 0x30081000, 0x30081004,
906  0x20080020, 0x20080024, 0x20081020, 0x20081024,
907  0x20080020, 0x20080024, 0x20081020, 0x20081024,
908  0x30080020, 0x30080024, 0x30081020, 0x30081024,
909  0x30080020, 0x30080024, 0x30081020, 0x30081024,
910  0x00000002, 0x00000006, 0x00001002, 0x00001006,
911  0x00000002, 0x00000006, 0x00001002, 0x00001006,
912  0x10000002, 0x10000006, 0x10001002, 0x10001006,
913  0x10000002, 0x10000006, 0x10001002, 0x10001006,
914  0x00000022, 0x00000026, 0x00001022, 0x00001026,
915  0x00000022, 0x00000026, 0x00001022, 0x00001026,
916  0x10000022, 0x10000026, 0x10001022, 0x10001026,
917  0x10000022, 0x10000026, 0x10001022, 0x10001026,
918  0x00080002, 0x00080006, 0x00081002, 0x00081006,
919  0x00080002, 0x00080006, 0x00081002, 0x00081006,
920  0x10080002, 0x10080006, 0x10081002, 0x10081006,
921  0x10080002, 0x10080006, 0x10081002, 0x10081006,
922  0x00080022, 0x00080026, 0x00081022, 0x00081026,
923  0x00080022, 0x00080026, 0x00081022, 0x00081026,
924  0x10080022, 0x10080026, 0x10081022, 0x10081026,
925  0x10080022, 0x10080026, 0x10081022, 0x10081026,
926  0x20000002, 0x20000006, 0x20001002, 0x20001006,
927  0x20000002, 0x20000006, 0x20001002, 0x20001006,
928  0x30000002, 0x30000006, 0x30001002, 0x30001006,
929  0x30000002, 0x30000006, 0x30001002, 0x30001006,
930  0x20000022, 0x20000026, 0x20001022, 0x20001026,
931  0x20000022, 0x20000026, 0x20001022, 0x20001026,
932  0x30000022, 0x30000026, 0x30001022, 0x30001026,
933  0x30000022, 0x30000026, 0x30001022, 0x30001026,
934  0x20080002, 0x20080006, 0x20081002, 0x20081006,
935  0x20080002, 0x20080006, 0x20081002, 0x20081006,
936  0x30080002, 0x30080006, 0x30081002, 0x30081006,
937  0x30080002, 0x30080006, 0x30081002, 0x30081006,
938  0x20080022, 0x20080026, 0x20081022, 0x20081026,
939  0x20080022, 0x20080026, 0x20081022, 0x20081026,
940  0x30080022, 0x30080026, 0x30081022, 0x30081026,
941  0x30080022, 0x30080026, 0x30081022, 0x30081026
942  );
943  static $pc2mapc4 = array(
944  0x00000000, 0x00100000, 0x00000008, 0x00100008,
945  0x00000200, 0x00100200, 0x00000208, 0x00100208,
946  0x00000000, 0x00100000, 0x00000008, 0x00100008,
947  0x00000200, 0x00100200, 0x00000208, 0x00100208,
948  0x04000000, 0x04100000, 0x04000008, 0x04100008,
949  0x04000200, 0x04100200, 0x04000208, 0x04100208,
950  0x04000000, 0x04100000, 0x04000008, 0x04100008,
951  0x04000200, 0x04100200, 0x04000208, 0x04100208,
952  0x00002000, 0x00102000, 0x00002008, 0x00102008,
953  0x00002200, 0x00102200, 0x00002208, 0x00102208,
954  0x00002000, 0x00102000, 0x00002008, 0x00102008,
955  0x00002200, 0x00102200, 0x00002208, 0x00102208,
956  0x04002000, 0x04102000, 0x04002008, 0x04102008,
957  0x04002200, 0x04102200, 0x04002208, 0x04102208,
958  0x04002000, 0x04102000, 0x04002008, 0x04102008,
959  0x04002200, 0x04102200, 0x04002208, 0x04102208,
960  0x00000000, 0x00100000, 0x00000008, 0x00100008,
961  0x00000200, 0x00100200, 0x00000208, 0x00100208,
962  0x00000000, 0x00100000, 0x00000008, 0x00100008,
963  0x00000200, 0x00100200, 0x00000208, 0x00100208,
964  0x04000000, 0x04100000, 0x04000008, 0x04100008,
965  0x04000200, 0x04100200, 0x04000208, 0x04100208,
966  0x04000000, 0x04100000, 0x04000008, 0x04100008,
967  0x04000200, 0x04100200, 0x04000208, 0x04100208,
968  0x00002000, 0x00102000, 0x00002008, 0x00102008,
969  0x00002200, 0x00102200, 0x00002208, 0x00102208,
970  0x00002000, 0x00102000, 0x00002008, 0x00102008,
971  0x00002200, 0x00102200, 0x00002208, 0x00102208,
972  0x04002000, 0x04102000, 0x04002008, 0x04102008,
973  0x04002200, 0x04102200, 0x04002208, 0x04102208,
974  0x04002000, 0x04102000, 0x04002008, 0x04102008,
975  0x04002200, 0x04102200, 0x04002208, 0x04102208,
976  0x00020000, 0x00120000, 0x00020008, 0x00120008,
977  0x00020200, 0x00120200, 0x00020208, 0x00120208,
978  0x00020000, 0x00120000, 0x00020008, 0x00120008,
979  0x00020200, 0x00120200, 0x00020208, 0x00120208,
980  0x04020000, 0x04120000, 0x04020008, 0x04120008,
981  0x04020200, 0x04120200, 0x04020208, 0x04120208,
982  0x04020000, 0x04120000, 0x04020008, 0x04120008,
983  0x04020200, 0x04120200, 0x04020208, 0x04120208,
984  0x00022000, 0x00122000, 0x00022008, 0x00122008,
985  0x00022200, 0x00122200, 0x00022208, 0x00122208,
986  0x00022000, 0x00122000, 0x00022008, 0x00122008,
987  0x00022200, 0x00122200, 0x00022208, 0x00122208,
988  0x04022000, 0x04122000, 0x04022008, 0x04122008,
989  0x04022200, 0x04122200, 0x04022208, 0x04122208,
990  0x04022000, 0x04122000, 0x04022008, 0x04122008,
991  0x04022200, 0x04122200, 0x04022208, 0x04122208,
992  0x00020000, 0x00120000, 0x00020008, 0x00120008,
993  0x00020200, 0x00120200, 0x00020208, 0x00120208,
994  0x00020000, 0x00120000, 0x00020008, 0x00120008,
995  0x00020200, 0x00120200, 0x00020208, 0x00120208,
996  0x04020000, 0x04120000, 0x04020008, 0x04120008,
997  0x04020200, 0x04120200, 0x04020208, 0x04120208,
998  0x04020000, 0x04120000, 0x04020008, 0x04120008,
999  0x04020200, 0x04120200, 0x04020208, 0x04120208,
1000  0x00022000, 0x00122000, 0x00022008, 0x00122008,
1001  0x00022200, 0x00122200, 0x00022208, 0x00122208,
1002  0x00022000, 0x00122000, 0x00022008, 0x00122008,
1003  0x00022200, 0x00122200, 0x00022208, 0x00122208,
1004  0x04022000, 0x04122000, 0x04022008, 0x04122008,
1005  0x04022200, 0x04122200, 0x04022208, 0x04122208,
1006  0x04022000, 0x04122000, 0x04022008, 0x04122008,
1007  0x04022200, 0x04122200, 0x04022208, 0x04122208
1008  );
1009  static $pc2mapd1 = array(
1010  0x00000000, 0x00000001, 0x08000000, 0x08000001,
1011  0x00200000, 0x00200001, 0x08200000, 0x08200001,
1012  0x00000002, 0x00000003, 0x08000002, 0x08000003,
1013  0x00200002, 0x00200003, 0x08200002, 0x08200003
1014  );
1015  static $pc2mapd2 = array(
1016  0x00000000, 0x00100000, 0x00000800, 0x00100800,
1017  0x00000000, 0x00100000, 0x00000800, 0x00100800,
1018  0x04000000, 0x04100000, 0x04000800, 0x04100800,
1019  0x04000000, 0x04100000, 0x04000800, 0x04100800,
1020  0x00000004, 0x00100004, 0x00000804, 0x00100804,
1021  0x00000004, 0x00100004, 0x00000804, 0x00100804,
1022  0x04000004, 0x04100004, 0x04000804, 0x04100804,
1023  0x04000004, 0x04100004, 0x04000804, 0x04100804,
1024  0x00000000, 0x00100000, 0x00000800, 0x00100800,
1025  0x00000000, 0x00100000, 0x00000800, 0x00100800,
1026  0x04000000, 0x04100000, 0x04000800, 0x04100800,
1027  0x04000000, 0x04100000, 0x04000800, 0x04100800,
1028  0x00000004, 0x00100004, 0x00000804, 0x00100804,
1029  0x00000004, 0x00100004, 0x00000804, 0x00100804,
1030  0x04000004, 0x04100004, 0x04000804, 0x04100804,
1031  0x04000004, 0x04100004, 0x04000804, 0x04100804,
1032  0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
1033  0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
1034  0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
1035  0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
1036  0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
1037  0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
1038  0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
1039  0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
1040  0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
1041  0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
1042  0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
1043  0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
1044  0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
1045  0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
1046  0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
1047  0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
1048  0x00020000, 0x00120000, 0x00020800, 0x00120800,
1049  0x00020000, 0x00120000, 0x00020800, 0x00120800,
1050  0x04020000, 0x04120000, 0x04020800, 0x04120800,
1051  0x04020000, 0x04120000, 0x04020800, 0x04120800,
1052  0x00020004, 0x00120004, 0x00020804, 0x00120804,
1053  0x00020004, 0x00120004, 0x00020804, 0x00120804,
1054  0x04020004, 0x04120004, 0x04020804, 0x04120804,
1055  0x04020004, 0x04120004, 0x04020804, 0x04120804,
1056  0x00020000, 0x00120000, 0x00020800, 0x00120800,
1057  0x00020000, 0x00120000, 0x00020800, 0x00120800,
1058  0x04020000, 0x04120000, 0x04020800, 0x04120800,
1059  0x04020000, 0x04120000, 0x04020800, 0x04120800,
1060  0x00020004, 0x00120004, 0x00020804, 0x00120804,
1061  0x00020004, 0x00120004, 0x00020804, 0x00120804,
1062  0x04020004, 0x04120004, 0x04020804, 0x04120804,
1063  0x04020004, 0x04120004, 0x04020804, 0x04120804,
1064  0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
1065  0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
1066  0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
1067  0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
1068  0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
1069  0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
1070  0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
1071  0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
1072  0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
1073  0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
1074  0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
1075  0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
1076  0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
1077  0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
1078  0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
1079  0x04020204, 0x04120204, 0x04020A04, 0x04120A04
1080  );
1081  static $pc2mapd3 = array(
1082  0x00000000, 0x00010000, 0x02000000, 0x02010000,
1083  0x00000020, 0x00010020, 0x02000020, 0x02010020,
1084  0x00040000, 0x00050000, 0x02040000, 0x02050000,
1085  0x00040020, 0x00050020, 0x02040020, 0x02050020,
1086  0x00002000, 0x00012000, 0x02002000, 0x02012000,
1087  0x00002020, 0x00012020, 0x02002020, 0x02012020,
1088  0x00042000, 0x00052000, 0x02042000, 0x02052000,
1089  0x00042020, 0x00052020, 0x02042020, 0x02052020,
1090  0x00000000, 0x00010000, 0x02000000, 0x02010000,
1091  0x00000020, 0x00010020, 0x02000020, 0x02010020,
1092  0x00040000, 0x00050000, 0x02040000, 0x02050000,
1093  0x00040020, 0x00050020, 0x02040020, 0x02050020,
1094  0x00002000, 0x00012000, 0x02002000, 0x02012000,
1095  0x00002020, 0x00012020, 0x02002020, 0x02012020,
1096  0x00042000, 0x00052000, 0x02042000, 0x02052000,
1097  0x00042020, 0x00052020, 0x02042020, 0x02052020,
1098  0x00000010, 0x00010010, 0x02000010, 0x02010010,
1099  0x00000030, 0x00010030, 0x02000030, 0x02010030,
1100  0x00040010, 0x00050010, 0x02040010, 0x02050010,
1101  0x00040030, 0x00050030, 0x02040030, 0x02050030,
1102  0x00002010, 0x00012010, 0x02002010, 0x02012010,
1103  0x00002030, 0x00012030, 0x02002030, 0x02012030,
1104  0x00042010, 0x00052010, 0x02042010, 0x02052010,
1105  0x00042030, 0x00052030, 0x02042030, 0x02052030,
1106  0x00000010, 0x00010010, 0x02000010, 0x02010010,
1107  0x00000030, 0x00010030, 0x02000030, 0x02010030,
1108  0x00040010, 0x00050010, 0x02040010, 0x02050010,
1109  0x00040030, 0x00050030, 0x02040030, 0x02050030,
1110  0x00002010, 0x00012010, 0x02002010, 0x02012010,
1111  0x00002030, 0x00012030, 0x02002030, 0x02012030,
1112  0x00042010, 0x00052010, 0x02042010, 0x02052010,
1113  0x00042030, 0x00052030, 0x02042030, 0x02052030,
1114  0x20000000, 0x20010000, 0x22000000, 0x22010000,
1115  0x20000020, 0x20010020, 0x22000020, 0x22010020,
1116  0x20040000, 0x20050000, 0x22040000, 0x22050000,
1117  0x20040020, 0x20050020, 0x22040020, 0x22050020,
1118  0x20002000, 0x20012000, 0x22002000, 0x22012000,
1119  0x20002020, 0x20012020, 0x22002020, 0x22012020,
1120  0x20042000, 0x20052000, 0x22042000, 0x22052000,
1121  0x20042020, 0x20052020, 0x22042020, 0x22052020,
1122  0x20000000, 0x20010000, 0x22000000, 0x22010000,
1123  0x20000020, 0x20010020, 0x22000020, 0x22010020,
1124  0x20040000, 0x20050000, 0x22040000, 0x22050000,
1125  0x20040020, 0x20050020, 0x22040020, 0x22050020,
1126  0x20002000, 0x20012000, 0x22002000, 0x22012000,
1127  0x20002020, 0x20012020, 0x22002020, 0x22012020,
1128  0x20042000, 0x20052000, 0x22042000, 0x22052000,
1129  0x20042020, 0x20052020, 0x22042020, 0x22052020,
1130  0x20000010, 0x20010010, 0x22000010, 0x22010010,
1131  0x20000030, 0x20010030, 0x22000030, 0x22010030,
1132  0x20040010, 0x20050010, 0x22040010, 0x22050010,
1133  0x20040030, 0x20050030, 0x22040030, 0x22050030,
1134  0x20002010, 0x20012010, 0x22002010, 0x22012010,
1135  0x20002030, 0x20012030, 0x22002030, 0x22012030,
1136  0x20042010, 0x20052010, 0x22042010, 0x22052010,
1137  0x20042030, 0x20052030, 0x22042030, 0x22052030,
1138  0x20000010, 0x20010010, 0x22000010, 0x22010010,
1139  0x20000030, 0x20010030, 0x22000030, 0x22010030,
1140  0x20040010, 0x20050010, 0x22040010, 0x22050010,
1141  0x20040030, 0x20050030, 0x22040030, 0x22050030,
1142  0x20002010, 0x20012010, 0x22002010, 0x22012010,
1143  0x20002030, 0x20012030, 0x22002030, 0x22012030,
1144  0x20042010, 0x20052010, 0x22042010, 0x22052010,
1145  0x20042030, 0x20052030, 0x22042030, 0x22052030
1146  );
1147  static $pc2mapd4 = array(
1148  0x00000000, 0x00000400, 0x01000000, 0x01000400,
1149  0x00000000, 0x00000400, 0x01000000, 0x01000400,
1150  0x00000100, 0x00000500, 0x01000100, 0x01000500,
1151  0x00000100, 0x00000500, 0x01000100, 0x01000500,
1152  0x10000000, 0x10000400, 0x11000000, 0x11000400,
1153  0x10000000, 0x10000400, 0x11000000, 0x11000400,
1154  0x10000100, 0x10000500, 0x11000100, 0x11000500,
1155  0x10000100, 0x10000500, 0x11000100, 0x11000500,
1156  0x00080000, 0x00080400, 0x01080000, 0x01080400,
1157  0x00080000, 0x00080400, 0x01080000, 0x01080400,
1158  0x00080100, 0x00080500, 0x01080100, 0x01080500,
1159  0x00080100, 0x00080500, 0x01080100, 0x01080500,
1160  0x10080000, 0x10080400, 0x11080000, 0x11080400,
1161  0x10080000, 0x10080400, 0x11080000, 0x11080400,
1162  0x10080100, 0x10080500, 0x11080100, 0x11080500,
1163  0x10080100, 0x10080500, 0x11080100, 0x11080500,
1164  0x00000008, 0x00000408, 0x01000008, 0x01000408,
1165  0x00000008, 0x00000408, 0x01000008, 0x01000408,
1166  0x00000108, 0x00000508, 0x01000108, 0x01000508,
1167  0x00000108, 0x00000508, 0x01000108, 0x01000508,
1168  0x10000008, 0x10000408, 0x11000008, 0x11000408,
1169  0x10000008, 0x10000408, 0x11000008, 0x11000408,
1170  0x10000108, 0x10000508, 0x11000108, 0x11000508,
1171  0x10000108, 0x10000508, 0x11000108, 0x11000508,
1172  0x00080008, 0x00080408, 0x01080008, 0x01080408,
1173  0x00080008, 0x00080408, 0x01080008, 0x01080408,
1174  0x00080108, 0x00080508, 0x01080108, 0x01080508,
1175  0x00080108, 0x00080508, 0x01080108, 0x01080508,
1176  0x10080008, 0x10080408, 0x11080008, 0x11080408,
1177  0x10080008, 0x10080408, 0x11080008, 0x11080408,
1178  0x10080108, 0x10080508, 0x11080108, 0x11080508,
1179  0x10080108, 0x10080508, 0x11080108, 0x11080508,
1180  0x00001000, 0x00001400, 0x01001000, 0x01001400,
1181  0x00001000, 0x00001400, 0x01001000, 0x01001400,
1182  0x00001100, 0x00001500, 0x01001100, 0x01001500,
1183  0x00001100, 0x00001500, 0x01001100, 0x01001500,
1184  0x10001000, 0x10001400, 0x11001000, 0x11001400,
1185  0x10001000, 0x10001400, 0x11001000, 0x11001400,
1186  0x10001100, 0x10001500, 0x11001100, 0x11001500,
1187  0x10001100, 0x10001500, 0x11001100, 0x11001500,
1188  0x00081000, 0x00081400, 0x01081000, 0x01081400,
1189  0x00081000, 0x00081400, 0x01081000, 0x01081400,
1190  0x00081100, 0x00081500, 0x01081100, 0x01081500,
1191  0x00081100, 0x00081500, 0x01081100, 0x01081500,
1192  0x10081000, 0x10081400, 0x11081000, 0x11081400,
1193  0x10081000, 0x10081400, 0x11081000, 0x11081400,
1194  0x10081100, 0x10081500, 0x11081100, 0x11081500,
1195  0x10081100, 0x10081500, 0x11081100, 0x11081500,
1196  0x00001008, 0x00001408, 0x01001008, 0x01001408,
1197  0x00001008, 0x00001408, 0x01001008, 0x01001408,
1198  0x00001108, 0x00001508, 0x01001108, 0x01001508,
1199  0x00001108, 0x00001508, 0x01001108, 0x01001508,
1200  0x10001008, 0x10001408, 0x11001008, 0x11001408,
1201  0x10001008, 0x10001408, 0x11001008, 0x11001408,
1202  0x10001108, 0x10001508, 0x11001108, 0x11001508,
1203  0x10001108, 0x10001508, 0x11001108, 0x11001508,
1204  0x00081008, 0x00081408, 0x01081008, 0x01081408,
1205  0x00081008, 0x00081408, 0x01081008, 0x01081408,
1206  0x00081108, 0x00081508, 0x01081108, 0x01081508,
1207  0x00081108, 0x00081508, 0x01081108, 0x01081508,
1208  0x10081008, 0x10081408, 0x11081008, 0x11081408,
1209  0x10081008, 0x10081408, 0x11081008, 0x11081408,
1210  0x10081108, 0x10081508, 0x11081108, 0x11081508,
1211  0x10081108, 0x10081508, 0x11081108, 0x11081508
1212  );
1213 
1214  $keys = array();
1215  for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) {
1216  // pad the key and remove extra characters as appropriate.
1217  $key = str_pad(substr($this->key, $des_round * 8, 8), 8, "\0");
1218 
1219  // Perform the PC/1 transformation and compute C and D.
1220  $t = unpack('Nl/Nr', $key);
1221  list($l, $r) = array($t['l'], $t['r']);
1222  $key = ($this->shuffle[$pc1map[ $r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x00") |
1223  ($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") |
1224  ($this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x00") |
1225  ($this->shuffle[$pc1map[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x00") |
1226  ($this->shuffle[$pc1map[ $l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x00") |
1227  ($this->shuffle[$pc1map[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x00") |
1228  ($this->shuffle[$pc1map[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x00") |
1229  ($this->shuffle[$pc1map[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x00");
1230  $key = unpack('Nc/Nd', $key);
1231  $c = ( $key['c'] >> 4) & 0x0FFFFFFF;
1232  $d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F);
1233 
1234  $keys[$des_round] = array(
1235  self::ENCRYPT => array(),
1236  self::DECRYPT => array_fill(0, 32, 0)
1237  );
1238  for ($i = 0, $ki = 31; $i < 16; ++$i, $ki-= 2) {
1239  $c <<= $shifts[$i];
1240  $c = ($c | ($c >> 28)) & 0x0FFFFFFF;
1241  $d <<= $shifts[$i];
1242  $d = ($d | ($d >> 28)) & 0x0FFFFFFF;
1243 
1244  // Perform the PC-2 transformation.
1245  $cp = $pc2mapc1[ $c >> 24 ] | $pc2mapc2[($c >> 16) & 0xFF] |
1246  $pc2mapc3[($c >> 8) & 0xFF] | $pc2mapc4[ $c & 0xFF];
1247  $dp = $pc2mapd1[ $d >> 24 ] | $pc2mapd2[($d >> 16) & 0xFF] |
1248  $pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[ $d & 0xFF];
1249 
1250  // Reorder: odd bytes/even bytes. Push the result in key schedule.
1251  $val1 = ( $cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) |
1252  (($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF);
1253  $val2 = (($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) |
1254  (($dp >> 8) & 0x0000FF00) | ( $dp & 0x000000FF);
1255  $keys[$des_round][self::ENCRYPT][ ] = $val1;
1256  $keys[$des_round][self::DECRYPT][$ki - 1] = $val1;
1257  $keys[$des_round][self::ENCRYPT][ ] = $val2;
1258  $keys[$des_round][self::DECRYPT][$ki ] = $val2;
1259  }
1260  }
1261 
1262  switch ($this->des_rounds) {
1263  case 3: // 3DES keys
1264  $this->keys = array(
1265  self::ENCRYPT => array_merge(
1266  $keys[0][self::ENCRYPT],
1267  $keys[1][self::DECRYPT],
1268  $keys[2][self::ENCRYPT]
1269  ),
1270  self::DECRYPT => array_merge(
1271  $keys[2][self::DECRYPT],
1272  $keys[1][self::ENCRYPT],
1273  $keys[0][self::DECRYPT]
1274  )
1275  );
1276  break;
1277  // case 1: // DES keys
1278  default:
1279  $this->keys = array(
1280  self::ENCRYPT => $keys[0][self::ENCRYPT],
1281  self::DECRYPT => $keys[0][self::DECRYPT]
1282  );
1283  }
1284  }
1285 
1293  {
1294  $lambda_functions =& self::_getLambdaFunctions();
1295 
1296  // Engine configuration for:
1297  // - DES ($des_rounds == 1) or
1298  // - 3DES ($des_rounds == 3)
1299  $des_rounds = $this->des_rounds;
1300 
1301  // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
1302  // (Currently, for DES, one generated $lambda_function cost on php5.5@32bit ~135kb unfreeable mem and ~230kb on php5.5@64bit)
1303  // (Currently, for TripleDES, one generated $lambda_function cost on php5.5@32bit ~240kb unfreeable mem and ~340kb on php5.5@64bit)
1304  // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one
1305  $gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
1306 
1307  // Generation of a uniqe hash for our generated code
1308  $code_hash = "Crypt_DES, $des_rounds, {$this->mode}";
1309  if ($gen_hi_opt_code) {
1310  // For hi-optimized code, we create for each combination of
1311  // $mode, $des_rounds and $this->key its own encrypt/decrypt function.
1312  // After max 10 hi-optimized functions, we create generic
1313  // (still very fast.. but not ultra) functions for each $mode/$des_rounds
1314  // Currently 2 * 5 generic functions will be then max. possible.
1315  $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
1316  }
1317 
1318  // Is there a re-usable $lambda_functions in there? If not, we have to create it.
1319  if (!isset($lambda_functions[$code_hash])) {
1320  // Init code for both, encrypt and decrypt.
1321  $init_crypt = 'static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
1322  if (!$sbox1) {
1323  $sbox1 = array_map("intval", $self->sbox1);
1324  $sbox2 = array_map("intval", $self->sbox2);
1325  $sbox3 = array_map("intval", $self->sbox3);
1326  $sbox4 = array_map("intval", $self->sbox4);
1327  $sbox5 = array_map("intval", $self->sbox5);
1328  $sbox6 = array_map("intval", $self->sbox6);
1329  $sbox7 = array_map("intval", $self->sbox7);
1330  $sbox8 = array_map("intval", $self->sbox8);'
1331  /* Merge $shuffle with $[inv]ipmap */ . '
1332  for ($i = 0; $i < 256; ++$i) {
1333  $shuffleip[] = $self->shuffle[$self->ipmap[$i]];
1334  $shuffleinvip[] = $self->shuffle[$self->invipmap[$i]];
1335  }
1336  }
1337  ';
1338 
1339  switch (true) {
1340  case $gen_hi_opt_code:
1341  // In Hi-optimized code mode, we use our [3]DES key schedule as hardcoded integers.
1342  // No futher initialisation of the $keys schedule is necessary.
1343  // That is the extra performance boost.
1344  $k = array(
1345  self::ENCRYPT => $this->keys[self::ENCRYPT],
1346  self::DECRYPT => $this->keys[self::DECRYPT]
1347  );
1348  $init_encrypt = '';
1349  $init_decrypt = '';
1350  break;
1351  default:
1352  // In generic optimized code mode, we have to use, as the best compromise [currently],
1353  // our key schedule as $ke/$kd arrays. (with hardcoded indexes...)
1354  $k = array(
1355  self::ENCRYPT => array(),
1356  self::DECRYPT => array()
1357  );
1358  for ($i = 0, $c = count($this->keys[self::ENCRYPT]); $i < $c; ++$i) {
1359  $k[self::ENCRYPT][$i] = '$ke[' . $i . ']';
1360  $k[self::DECRYPT][$i] = '$kd[' . $i . ']';
1361  }
1362  $init_encrypt = '$ke = $self->keys[self::ENCRYPT];';
1363  $init_decrypt = '$kd = $self->keys[self::DECRYPT];';
1364  break;
1365  }
1366 
1367  // Creating code for en- and decryption.
1368  $crypt_block = array();
1369  foreach (array(self::ENCRYPT, self::DECRYPT) as $c) {
1370  /* Do the initial IP permutation. */
1371  $crypt_block[$c] = '
1372  $in = unpack("N*", $in);
1373  $l = $in[1];
1374  $r = $in[2];
1375  $in = unpack("N*",
1376  ($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
1377  ($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
1378  ($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
1379  ($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
1380  ($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
1381  ($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
1382  ($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
1383  ($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01")
1384  );
1385  ' . /* Extract L0 and R0 */ '
1386  $l = $in[1];
1387  $r = $in[2];
1388  ';
1389 
1390  $l = '$l';
1391  $r = '$r';
1392 
1393  // Perform DES or 3DES.
1394  for ($ki = -1, $des_round = 0; $des_round < $des_rounds; ++$des_round) {
1395  // Perform the 16 steps.
1396  for ($i = 0; $i < 16; ++$i) {
1397  // start of "the Feistel (F) function" - see the following URL:
1398  // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
1399  // Merge key schedule.
1400  $crypt_block[$c].= '
1401  $b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . ';
1402  $b2 = ((' . $r . ' >> 31) & 0x00000001) ^ (' . $r . ' << 1) ^ ' . $k[$c][++$ki] . ';' .
1403  /* S-box indexing. */
1404  $l . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
1405  $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
1406  $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
1407  $sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ ' . $l . ';
1408  ';
1409  // end of "the Feistel (F) function"
1410 
1411  // swap L & R
1412  list($l, $r) = array($r, $l);
1413  }
1414  list($l, $r) = array($r, $l);
1415  }
1416 
1417  // Perform the inverse IP permutation.
1418  $crypt_block[$c].= '$in =
1419  ($shuffleinvip[($l >> 24) & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
1420  ($shuffleinvip[($r >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
1421  ($shuffleinvip[($l >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
1422  ($shuffleinvip[($r >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
1423  ($shuffleinvip[($l >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
1424  ($shuffleinvip[($r >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
1425  ($shuffleinvip[ $l & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
1426  ($shuffleinvip[ $r & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01");
1427  ';
1428  }
1429 
1430  // Creates the inline-crypt function
1431  $lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
1432  array(
1433  'init_crypt' => $init_crypt,
1434  'init_encrypt' => $init_encrypt,
1435  'init_decrypt' => $init_decrypt,
1436  'encrypt_block' => $crypt_block[self::ENCRYPT],
1437  'decrypt_block' => $crypt_block[self::DECRYPT]
1438  )
1439  );
1440  }
1441 
1442  // Set the inline-crypt function as callback in: $this->inline_crypt
1443  $this->inline_crypt = $lambda_functions[$code_hash];
1444  }
1445 }
_setupInlineCrypt()
Setup the performance-optimized function for de/encrypt()
Definition: DES.php:1292
_hashInlineCryptFunction($bytes)
Generates a digest from $bytes.
Definition: Base.php:2523
_setupKey()
Creates the key schedule.
Definition: DES.php:757
_openssl_translate_mode()
phpseclib <-> OpenSSL Mode Mapper
Definition: Base.php:1423
_decryptBlock($in)
Decrypts a block.
Definition: DES.php:657
Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic...
Definition: AES.php:50
$r
Definition: example_031.php:79
_processBlock($block, $mode)
Encrypts or decrypts a 64-bit block.
Definition: DES.php:676
_createInlineCryptFunction($cipher_code)
Creates the performance-optimized function for en/decrypt()
Definition: Base.php:2142
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
global $l
Definition: afr.php:30
_encryptBlock($in)
Encrypts a block.
Definition: DES.php:642
$i
Definition: disco.tpl.php:19
Base Class for all * cipher classes.
const DECRYPT
Contains $keys[self::DECRYPT].
Definition: DES.php:68
setKey($key)
Sets the key.
Definition: DES.php:620
Pure-PHP implementation of DES.
const ENCRYPT
#+ private
Definition: DES.php:64
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
isValidEngine($engine)
Test for engine validity.
Definition: DES.php:593