24
|
1 package myVncProxy;
|
0
|
2 //
|
|
3 // This DES class has been extracted from package Acme.Crypto for use in VNC.
|
|
4 // The bytebit[] array has been reversed so that the most significant bit
|
|
5 // in each byte of the key is ignored, not the least significant. Also the
|
|
6 // unnecessary odd parity code has been removed.
|
|
7 //
|
|
8 // These changes are:
|
|
9 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
|
10 //
|
|
11 // This software is distributed in the hope that it will be useful,
|
|
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14 //
|
|
15
|
|
16 // DesCipher - the DES encryption method
|
|
17 //
|
|
18 // The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
|
|
19 //
|
|
20 // Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
|
|
21 //
|
|
22 // Permission to use, copy, modify, and distribute this software
|
|
23 // and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
|
|
24 // without fee is hereby granted, provided that this copyright notice is kept
|
|
25 // intact.
|
|
26 //
|
|
27 // WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
|
|
28 // OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
29 // TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
30 // PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
|
|
31 // FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
|
32 // DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
|
33 //
|
|
34 // THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
|
|
35 // CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
|
36 // PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
|
37 // NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
|
38 // SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
|
39 // SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
|
|
40 // PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
|
|
41 // SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
|
|
42 // HIGH RISK ACTIVITIES.
|
|
43 //
|
|
44 //
|
|
45 // The rest is:
|
|
46 //
|
|
47 // Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
|
|
48 //
|
|
49 // Redistribution and use in source and binary forms, with or without
|
|
50 // modification, are permitted provided that the following conditions
|
|
51 // are met:
|
|
52 // 1. Redistributions of source code must retain the above copyright
|
|
53 // notice, this list of conditions and the following disclaimer.
|
|
54 // 2. Redistributions in binary form must reproduce the above copyright
|
|
55 // notice, this list of conditions and the following disclaimer in the
|
|
56 // documentation and/or other materials provided with the distribution.
|
|
57 //
|
|
58 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
59 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
60 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
61 // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
62 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
63 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
64 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
65 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
66 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
67 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
68 // SUCH DAMAGE.
|
|
69 //
|
|
70 // Visit the ACME Labs Java page for up-to-date versions of this and other
|
|
71 // fine Java utilities: http://www.acme.com/java/
|
|
72
|
|
73
|
|
74 import java.io.*;
|
|
75
|
|
76 /// The DES encryption method.
|
|
77 // <P>
|
|
78 // This is surprisingly fast, for pure Java. On a SPARC 20, wrapped
|
|
79 // in Acme.Crypto.EncryptedOutputStream or Acme.Crypto.EncryptedInputStream,
|
|
80 // it does around 7000 bytes/second.
|
|
81 // <P>
|
|
82 // Most of this code is by Dave Zimmerman <dzimm@widget.com>, and is
|
|
83 // Copyright (c) 1996 Widget Workshop, Inc. See the source file for details.
|
|
84 // <P>
|
|
85 // <A HREF="/resources/classes/Acme/Crypto/DesCipher.java">Fetch the software.</A><BR>
|
|
86 // <A HREF="/resources/classes/Acme.tar.Z">Fetch the entire Acme package.</A>
|
|
87 // <P>
|
|
88 // @see Des3Cipher
|
|
89 // @see EncryptedOutputStream
|
|
90 // @see EncryptedInputStream
|
|
91
|
|
92 public class DesCipher
|
|
93 {
|
|
94
|
|
95 // Constructor, byte-array key.
|
|
96 public DesCipher( byte[] key )
|
|
97 {
|
|
98 setKey( key );
|
|
99 }
|
|
100
|
|
101 // Key routines.
|
|
102
|
|
103 private int[] encryptKeys = new int[32];
|
|
104 private int[] decryptKeys = new int[32];
|
|
105
|
|
106 /// Set the key.
|
|
107 public void setKey( byte[] key )
|
|
108 {
|
|
109 deskey( key, true, encryptKeys );
|
|
110 deskey( key, false, decryptKeys );
|
|
111 }
|
|
112
|
|
113 // Turn an 8-byte key into internal keys.
|
|
114 private void deskey( byte[] keyBlock, boolean encrypting, int[] KnL )
|
|
115 {
|
|
116 int i, j, l, m, n;
|
|
117 int[] pc1m = new int[56];
|
|
118 int[] pcr = new int[56];
|
|
119 int[] kn = new int[32];
|
|
120
|
|
121 for ( j = 0; j < 56; ++j )
|
|
122 {
|
|
123 l = pc1[j];
|
|
124 m = l & 07;
|
|
125 pc1m[j] = ( (keyBlock[l >>> 3] & bytebit[m]) != 0 )? 1: 0;
|
|
126 }
|
|
127
|
|
128 for ( i = 0; i < 16; ++i )
|
|
129 {
|
|
130 if ( encrypting )
|
|
131 m = i << 1;
|
|
132 else
|
|
133 m = (15-i) << 1;
|
|
134 n = m+1;
|
|
135 kn[m] = kn[n] = 0;
|
|
136 for ( j = 0; j < 28; ++j )
|
|
137 {
|
|
138 l = j+totrot[i];
|
|
139 if ( l < 28 )
|
|
140 pcr[j] = pc1m[l];
|
|
141 else
|
|
142 pcr[j] = pc1m[l-28];
|
|
143 }
|
|
144 for ( j=28; j < 56; ++j )
|
|
145 {
|
|
146 l = j+totrot[i];
|
|
147 if ( l < 56 )
|
|
148 pcr[j] = pc1m[l];
|
|
149 else
|
|
150 pcr[j] = pc1m[l-28];
|
|
151 }
|
|
152 for ( j = 0; j < 24; ++j )
|
|
153 {
|
|
154 if ( pcr[pc2[j]] != 0 )
|
|
155 kn[m] |= bigbyte[j];
|
|
156 if ( pcr[pc2[j+24]] != 0 )
|
|
157 kn[n] |= bigbyte[j];
|
|
158 }
|
|
159 }
|
|
160 cookey( kn, KnL );
|
|
161 }
|
|
162
|
|
163 private void cookey( int[] raw, int KnL[] )
|
|
164 {
|
|
165 int raw0, raw1;
|
|
166 int rawi, KnLi;
|
|
167 int i;
|
|
168
|
|
169 for ( i = 0, rawi = 0, KnLi = 0; i < 16; ++i )
|
|
170 {
|
|
171 raw0 = raw[rawi++];
|
|
172 raw1 = raw[rawi++];
|
|
173 KnL[KnLi] = (raw0 & 0x00fc0000) << 6;
|
|
174 KnL[KnLi] |= (raw0 & 0x00000fc0) << 10;
|
|
175 KnL[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
|
|
176 KnL[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
|
|
177 ++KnLi;
|
|
178 KnL[KnLi] = (raw0 & 0x0003f000) << 12;
|
|
179 KnL[KnLi] |= (raw0 & 0x0000003f) << 16;
|
|
180 KnL[KnLi] |= (raw1 & 0x0003f000) >>> 4;
|
|
181 KnL[KnLi] |= (raw1 & 0x0000003f);
|
|
182 ++KnLi;
|
|
183 }
|
|
184 }
|
|
185
|
|
186
|
|
187 // Block encryption routines.
|
|
188
|
|
189 private int[] tempInts = new int[2];
|
|
190
|
|
191 /// Encrypt a block of eight bytes.
|
|
192 public void encrypt( byte[] clearText, int clearOff, byte[] cipherText, int cipherOff )
|
|
193 {
|
|
194 squashBytesToInts( clearText, clearOff, tempInts, 0, 2 );
|
|
195 des( tempInts, tempInts, encryptKeys );
|
|
196 spreadIntsToBytes( tempInts, 0, cipherText, cipherOff, 2 );
|
|
197 }
|
|
198
|
|
199 /// Decrypt a block of eight bytes.
|
|
200 public void decrypt( byte[] cipherText, int cipherOff, byte[] clearText, int clearOff )
|
|
201 {
|
|
202 squashBytesToInts( cipherText, cipherOff, tempInts, 0, 2 );
|
|
203 des( tempInts, tempInts, decryptKeys );
|
|
204 spreadIntsToBytes( tempInts, 0, clearText, clearOff, 2 );
|
|
205 }
|
|
206
|
|
207 // The DES function.
|
|
208 private void des( int[] inInts, int[] outInts, int[] keys )
|
|
209 {
|
|
210 int fval, work, right, leftt;
|
|
211 int round;
|
|
212 int keysi = 0;
|
|
213
|
|
214 leftt = inInts[0];
|
|
215 right = inInts[1];
|
|
216
|
|
217 work = ((leftt >>> 4) ^ right) & 0x0f0f0f0f;
|
|
218 right ^= work;
|
|
219 leftt ^= (work << 4);
|
|
220
|
|
221 work = ((leftt >>> 16) ^ right) & 0x0000ffff;
|
|
222 right ^= work;
|
|
223 leftt ^= (work << 16);
|
|
224
|
|
225 work = ((right >>> 2) ^ leftt) & 0x33333333;
|
|
226 leftt ^= work;
|
|
227 right ^= (work << 2);
|
|
228
|
|
229 work = ((right >>> 8) ^ leftt) & 0x00ff00ff;
|
|
230 leftt ^= work;
|
|
231 right ^= (work << 8);
|
|
232 right = (right << 1) | ((right >>> 31) & 1);
|
|
233
|
|
234 work = (leftt ^ right) & 0xaaaaaaaa;
|
|
235 leftt ^= work;
|
|
236 right ^= work;
|
|
237 leftt = (leftt << 1) | ((leftt >>> 31) & 1);
|
|
238
|
|
239 for ( round = 0; round < 8; ++round )
|
|
240 {
|
|
241 work = (right << 28) | (right >>> 4);
|
|
242 work ^= keys[keysi++];
|
|
243 fval = SP7[ work & 0x0000003f ];
|
|
244 fval |= SP5[(work >>> 8) & 0x0000003f ];
|
|
245 fval |= SP3[(work >>> 16) & 0x0000003f ];
|
|
246 fval |= SP1[(work >>> 24) & 0x0000003f ];
|
|
247 work = right ^ keys[keysi++];
|
|
248 fval |= SP8[ work & 0x0000003f ];
|
|
249 fval |= SP6[(work >>> 8) & 0x0000003f ];
|
|
250 fval |= SP4[(work >>> 16) & 0x0000003f ];
|
|
251 fval |= SP2[(work >>> 24) & 0x0000003f ];
|
|
252 leftt ^= fval;
|
|
253 work = (leftt << 28) | (leftt >>> 4);
|
|
254 work ^= keys[keysi++];
|
|
255 fval = SP7[ work & 0x0000003f ];
|
|
256 fval |= SP5[(work >>> 8) & 0x0000003f ];
|
|
257 fval |= SP3[(work >>> 16) & 0x0000003f ];
|
|
258 fval |= SP1[(work >>> 24) & 0x0000003f ];
|
|
259 work = leftt ^ keys[keysi++];
|
|
260 fval |= SP8[ work & 0x0000003f ];
|
|
261 fval |= SP6[(work >>> 8) & 0x0000003f ];
|
|
262 fval |= SP4[(work >>> 16) & 0x0000003f ];
|
|
263 fval |= SP2[(work >>> 24) & 0x0000003f ];
|
|
264 right ^= fval;
|
|
265 }
|
|
266
|
|
267 right = (right << 31) | (right >>> 1);
|
|
268 work = (leftt ^ right) & 0xaaaaaaaa;
|
|
269 leftt ^= work;
|
|
270 right ^= work;
|
|
271 leftt = (leftt << 31) | (leftt >>> 1);
|
|
272 work = ((leftt >>> 8) ^ right) & 0x00ff00ff;
|
|
273 right ^= work;
|
|
274 leftt ^= (work << 8);
|
|
275 work = ((leftt >>> 2) ^ right) & 0x33333333;
|
|
276 right ^= work;
|
|
277 leftt ^= (work << 2);
|
|
278 work = ((right >>> 16) ^ leftt) & 0x0000ffff;
|
|
279 leftt ^= work;
|
|
280 right ^= (work << 16);
|
|
281 work = ((right >>> 4) ^ leftt) & 0x0f0f0f0f;
|
|
282 leftt ^= work;
|
|
283 right ^= (work << 4);
|
|
284 outInts[0] = right;
|
|
285 outInts[1] = leftt;
|
|
286 }
|
|
287
|
|
288
|
|
289 // Tables, permutations, S-boxes, etc.
|
|
290
|
|
291 private static byte[] bytebit = {
|
|
292 (byte)0x01, (byte)0x02, (byte)0x04, (byte)0x08,
|
|
293 (byte)0x10, (byte)0x20, (byte)0x40, (byte)0x80
|
|
294 };
|
|
295 private static int[] bigbyte = {
|
|
296 0x800000, 0x400000, 0x200000, 0x100000,
|
|
297 0x080000, 0x040000, 0x020000, 0x010000,
|
|
298 0x008000, 0x004000, 0x002000, 0x001000,
|
|
299 0x000800, 0x000400, 0x000200, 0x000100,
|
|
300 0x000080, 0x000040, 0x000020, 0x000010,
|
|
301 0x000008, 0x000004, 0x000002, 0x000001
|
|
302 };
|
|
303 private static byte[] pc1 = {
|
|
304 (byte)56, (byte)48, (byte)40, (byte)32, (byte)24, (byte)16, (byte) 8,
|
|
305 (byte) 0, (byte)57, (byte)49, (byte)41, (byte)33, (byte)25, (byte)17,
|
|
306 (byte) 9, (byte) 1, (byte)58, (byte)50, (byte)42, (byte)34, (byte)26,
|
|
307 (byte)18, (byte)10, (byte) 2, (byte)59, (byte)51, (byte)43, (byte)35,
|
|
308 (byte)62, (byte)54, (byte)46, (byte)38, (byte)30, (byte)22, (byte)14,
|
|
309 (byte) 6, (byte)61, (byte)53, (byte)45, (byte)37, (byte)29, (byte)21,
|
|
310 (byte)13, (byte) 5, (byte)60, (byte)52, (byte)44, (byte)36, (byte)28,
|
|
311 (byte)20, (byte)12, (byte) 4, (byte)27, (byte)19, (byte)11, (byte)3
|
|
312 };
|
|
313 private static int[] totrot = {
|
|
314 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28
|
|
315 };
|
|
316
|
|
317 private static byte[] pc2 = {
|
|
318 (byte)13, (byte)16, (byte)10, (byte)23, (byte) 0, (byte) 4,
|
|
319 (byte) 2, (byte)27, (byte)14, (byte) 5, (byte)20, (byte) 9,
|
|
320 (byte)22, (byte)18, (byte)11, (byte)3 , (byte)25, (byte) 7,
|
|
321 (byte)15, (byte) 6, (byte)26, (byte)19, (byte)12, (byte) 1,
|
|
322 (byte)40, (byte)51, (byte)30, (byte)36, (byte)46, (byte)54,
|
|
323 (byte)29, (byte)39, (byte)50, (byte)44, (byte)32, (byte)47,
|
|
324 (byte)43, (byte)48, (byte)38, (byte)55, (byte)33, (byte)52,
|
|
325 (byte)45, (byte)41, (byte)49, (byte)35, (byte)28, (byte)31,
|
|
326 };
|
|
327
|
|
328 private static int[] SP1 = {
|
|
329 0x01010400, 0x00000000, 0x00010000, 0x01010404,
|
|
330 0x01010004, 0x00010404, 0x00000004, 0x00010000,
|
|
331 0x00000400, 0x01010400, 0x01010404, 0x00000400,
|
|
332 0x01000404, 0x01010004, 0x01000000, 0x00000004,
|
|
333 0x00000404, 0x01000400, 0x01000400, 0x00010400,
|
|
334 0x00010400, 0x01010000, 0x01010000, 0x01000404,
|
|
335 0x00010004, 0x01000004, 0x01000004, 0x00010004,
|
|
336 0x00000000, 0x00000404, 0x00010404, 0x01000000,
|
|
337 0x00010000, 0x01010404, 0x00000004, 0x01010000,
|
|
338 0x01010400, 0x01000000, 0x01000000, 0x00000400,
|
|
339 0x01010004, 0x00010000, 0x00010400, 0x01000004,
|
|
340 0x00000400, 0x00000004, 0x01000404, 0x00010404,
|
|
341 0x01010404, 0x00010004, 0x01010000, 0x01000404,
|
|
342 0x01000004, 0x00000404, 0x00010404, 0x01010400,
|
|
343 0x00000404, 0x01000400, 0x01000400, 0x00000000,
|
|
344 0x00010004, 0x00010400, 0x00000000, 0x01010004
|
|
345 };
|
|
346 private static int[] SP2 = {
|
|
347 0x80108020, 0x80008000, 0x00008000, 0x00108020,
|
|
348 0x00100000, 0x00000020, 0x80100020, 0x80008020,
|
|
349 0x80000020, 0x80108020, 0x80108000, 0x80000000,
|
|
350 0x80008000, 0x00100000, 0x00000020, 0x80100020,
|
|
351 0x00108000, 0x00100020, 0x80008020, 0x00000000,
|
|
352 0x80000000, 0x00008000, 0x00108020, 0x80100000,
|
|
353 0x00100020, 0x80000020, 0x00000000, 0x00108000,
|
|
354 0x00008020, 0x80108000, 0x80100000, 0x00008020,
|
|
355 0x00000000, 0x00108020, 0x80100020, 0x00100000,
|
|
356 0x80008020, 0x80100000, 0x80108000, 0x00008000,
|
|
357 0x80100000, 0x80008000, 0x00000020, 0x80108020,
|
|
358 0x00108020, 0x00000020, 0x00008000, 0x80000000,
|
|
359 0x00008020, 0x80108000, 0x00100000, 0x80000020,
|
|
360 0x00100020, 0x80008020, 0x80000020, 0x00100020,
|
|
361 0x00108000, 0x00000000, 0x80008000, 0x00008020,
|
|
362 0x80000000, 0x80100020, 0x80108020, 0x00108000
|
|
363 };
|
|
364 private static int[] SP3 = {
|
|
365 0x00000208, 0x08020200, 0x00000000, 0x08020008,
|
|
366 0x08000200, 0x00000000, 0x00020208, 0x08000200,
|
|
367 0x00020008, 0x08000008, 0x08000008, 0x00020000,
|
|
368 0x08020208, 0x00020008, 0x08020000, 0x00000208,
|
|
369 0x08000000, 0x00000008, 0x08020200, 0x00000200,
|
|
370 0x00020200, 0x08020000, 0x08020008, 0x00020208,
|
|
371 0x08000208, 0x00020200, 0x00020000, 0x08000208,
|
|
372 0x00000008, 0x08020208, 0x00000200, 0x08000000,
|
|
373 0x08020200, 0x08000000, 0x00020008, 0x00000208,
|
|
374 0x00020000, 0x08020200, 0x08000200, 0x00000000,
|
|
375 0x00000200, 0x00020008, 0x08020208, 0x08000200,
|
|
376 0x08000008, 0x00000200, 0x00000000, 0x08020008,
|
|
377 0x08000208, 0x00020000, 0x08000000, 0x08020208,
|
|
378 0x00000008, 0x00020208, 0x00020200, 0x08000008,
|
|
379 0x08020000, 0x08000208, 0x00000208, 0x08020000,
|
|
380 0x00020208, 0x00000008, 0x08020008, 0x00020200
|
|
381 };
|
|
382 private static int[] SP4 = {
|
|
383 0x00802001, 0x00002081, 0x00002081, 0x00000080,
|
|
384 0x00802080, 0x00800081, 0x00800001, 0x00002001,
|
|
385 0x00000000, 0x00802000, 0x00802000, 0x00802081,
|
|
386 0x00000081, 0x00000000, 0x00800080, 0x00800001,
|
|
387 0x00000001, 0x00002000, 0x00800000, 0x00802001,
|
|
388 0x00000080, 0x00800000, 0x00002001, 0x00002080,
|
|
389 0x00800081, 0x00000001, 0x00002080, 0x00800080,
|
|
390 0x00002000, 0x00802080, 0x00802081, 0x00000081,
|
|
391 0x00800080, 0x00800001, 0x00802000, 0x00802081,
|
|
392 0x00000081, 0x00000000, 0x00000000, 0x00802000,
|
|
393 0x00002080, 0x00800080, 0x00800081, 0x00000001,
|
|
394 0x00802001, 0x00002081, 0x00002081, 0x00000080,
|
|
395 0x00802081, 0x00000081, 0x00000001, 0x00002000,
|
|
396 0x00800001, 0x00002001, 0x00802080, 0x00800081,
|
|
397 0x00002001, 0x00002080, 0x00800000, 0x00802001,
|
|
398 0x00000080, 0x00800000, 0x00002000, 0x00802080
|
|
399 };
|
|
400 private static int[] SP5 = {
|
|
401 0x00000100, 0x02080100, 0x02080000, 0x42000100,
|
|
402 0x00080000, 0x00000100, 0x40000000, 0x02080000,
|
|
403 0x40080100, 0x00080000, 0x02000100, 0x40080100,
|
|
404 0x42000100, 0x42080000, 0x00080100, 0x40000000,
|
|
405 0x02000000, 0x40080000, 0x40080000, 0x00000000,
|
|
406 0x40000100, 0x42080100, 0x42080100, 0x02000100,
|
|
407 0x42080000, 0x40000100, 0x00000000, 0x42000000,
|
|
408 0x02080100, 0x02000000, 0x42000000, 0x00080100,
|
|
409 0x00080000, 0x42000100, 0x00000100, 0x02000000,
|
|
410 0x40000000, 0x02080000, 0x42000100, 0x40080100,
|
|
411 0x02000100, 0x40000000, 0x42080000, 0x02080100,
|
|
412 0x40080100, 0x00000100, 0x02000000, 0x42080000,
|
|
413 0x42080100, 0x00080100, 0x42000000, 0x42080100,
|
|
414 0x02080000, 0x00000000, 0x40080000, 0x42000000,
|
|
415 0x00080100, 0x02000100, 0x40000100, 0x00080000,
|
|
416 0x00000000, 0x40080000, 0x02080100, 0x40000100
|
|
417 };
|
|
418 private static int[] SP6 = {
|
|
419 0x20000010, 0x20400000, 0x00004000, 0x20404010,
|
|
420 0x20400000, 0x00000010, 0x20404010, 0x00400000,
|
|
421 0x20004000, 0x00404010, 0x00400000, 0x20000010,
|
|
422 0x00400010, 0x20004000, 0x20000000, 0x00004010,
|
|
423 0x00000000, 0x00400010, 0x20004010, 0x00004000,
|
|
424 0x00404000, 0x20004010, 0x00000010, 0x20400010,
|
|
425 0x20400010, 0x00000000, 0x00404010, 0x20404000,
|
|
426 0x00004010, 0x00404000, 0x20404000, 0x20000000,
|
|
427 0x20004000, 0x00000010, 0x20400010, 0x00404000,
|
|
428 0x20404010, 0x00400000, 0x00004010, 0x20000010,
|
|
429 0x00400000, 0x20004000, 0x20000000, 0x00004010,
|
|
430 0x20000010, 0x20404010, 0x00404000, 0x20400000,
|
|
431 0x00404010, 0x20404000, 0x00000000, 0x20400010,
|
|
432 0x00000010, 0x00004000, 0x20400000, 0x00404010,
|
|
433 0x00004000, 0x00400010, 0x20004010, 0x00000000,
|
|
434 0x20404000, 0x20000000, 0x00400010, 0x20004010
|
|
435 };
|
|
436 private static int[] SP7 = {
|
|
437 0x00200000, 0x04200002, 0x04000802, 0x00000000,
|
|
438 0x00000800, 0x04000802, 0x00200802, 0x04200800,
|
|
439 0x04200802, 0x00200000, 0x00000000, 0x04000002,
|
|
440 0x00000002, 0x04000000, 0x04200002, 0x00000802,
|
|
441 0x04000800, 0x00200802, 0x00200002, 0x04000800,
|
|
442 0x04000002, 0x04200000, 0x04200800, 0x00200002,
|
|
443 0x04200000, 0x00000800, 0x00000802, 0x04200802,
|
|
444 0x00200800, 0x00000002, 0x04000000, 0x00200800,
|
|
445 0x04000000, 0x00200800, 0x00200000, 0x04000802,
|
|
446 0x04000802, 0x04200002, 0x04200002, 0x00000002,
|
|
447 0x00200002, 0x04000000, 0x04000800, 0x00200000,
|
|
448 0x04200800, 0x00000802, 0x00200802, 0x04200800,
|
|
449 0x00000802, 0x04000002, 0x04200802, 0x04200000,
|
|
450 0x00200800, 0x00000000, 0x00000002, 0x04200802,
|
|
451 0x00000000, 0x00200802, 0x04200000, 0x00000800,
|
|
452 0x04000002, 0x04000800, 0x00000800, 0x00200002
|
|
453 };
|
|
454 private static int[] SP8 = {
|
|
455 0x10001040, 0x00001000, 0x00040000, 0x10041040,
|
|
456 0x10000000, 0x10001040, 0x00000040, 0x10000000,
|
|
457 0x00040040, 0x10040000, 0x10041040, 0x00041000,
|
|
458 0x10041000, 0x00041040, 0x00001000, 0x00000040,
|
|
459 0x10040000, 0x10000040, 0x10001000, 0x00001040,
|
|
460 0x00041000, 0x00040040, 0x10040040, 0x10041000,
|
|
461 0x00001040, 0x00000000, 0x00000000, 0x10040040,
|
|
462 0x10000040, 0x10001000, 0x00041040, 0x00040000,
|
|
463 0x00041040, 0x00040000, 0x10041000, 0x00001000,
|
|
464 0x00000040, 0x10040040, 0x00001000, 0x00041040,
|
|
465 0x10001000, 0x00000040, 0x10000040, 0x10040000,
|
|
466 0x10040040, 0x10000000, 0x00040000, 0x10001040,
|
|
467 0x00000000, 0x10041040, 0x00040040, 0x10000040,
|
|
468 0x10040000, 0x10001000, 0x10001040, 0x00000000,
|
|
469 0x10041040, 0x00041000, 0x00041000, 0x00001040,
|
|
470 0x00001040, 0x00040040, 0x10000000, 0x10041000
|
|
471 };
|
|
472
|
|
473 // Routines taken from other parts of the Acme utilities.
|
|
474
|
|
475 /// Squash bytes down to ints.
|
|
476 public static void squashBytesToInts( byte[] inBytes, int inOff, int[] outInts, int outOff, int intLen )
|
|
477 {
|
|
478 for ( int i = 0; i < intLen; ++i )
|
|
479 outInts[outOff + i] =
|
|
480 ( ( inBytes[inOff + i * 4 ] & 0xff ) << 24 ) |
|
|
481 ( ( inBytes[inOff + i * 4 + 1] & 0xff ) << 16 ) |
|
|
482 ( ( inBytes[inOff + i * 4 + 2] & 0xff ) << 8 ) |
|
|
483 ( inBytes[inOff + i * 4 + 3] & 0xff );
|
|
484 }
|
|
485
|
|
486 /// Spread ints into bytes.
|
|
487 public static void spreadIntsToBytes( int[] inInts, int inOff, byte[] outBytes, int outOff, int intLen )
|
|
488 {
|
|
489 for ( int i = 0; i < intLen; ++i )
|
|
490 {
|
|
491 outBytes[outOff + i * 4 ] = (byte) ( inInts[inOff + i] >>> 24 );
|
|
492 outBytes[outOff + i * 4 + 1] = (byte) ( inInts[inOff + i] >>> 16 );
|
|
493 outBytes[outOff + i * 4 + 2] = (byte) ( inInts[inOff + i] >>> 8 );
|
|
494 outBytes[outOff + i * 4 + 3] = (byte) inInts[inOff + i];
|
|
495 }
|
|
496 }
|
|
497 }
|