Source Code Cross Referenced for DES.java in  » Net » jCIFS » jcifs » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » jCIFS » jcifs.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // DesCipher - the DES encryption method
002:        //
003:        // The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
004:        //
005:        // Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
006:        //
007:        // Permission to use, copy, modify, and distribute this software
008:        // and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
009:        // without fee is hereby granted, provided that this copyright notice is kept
010:        // intact.
011:        //
012:        // WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
013:        // OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
014:        // TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
015:        // PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
016:        // FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
017:        // DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
018:        //
019:        // THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
020:        // CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
021:        // PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
022:        // NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
023:        // SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
024:        // SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
025:        // PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  WIDGET WORKSHOP
026:        // SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
027:        // HIGH RISK ACTIVITIES.
028:        //
029:        //
030:        // The rest is:
031:        //
032:        // Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>.  All rights reserved.
033:        //
034:        // Copyright (C) 1996 by Wolfgang Platzer
035:        // email: wplatzer@iaik.tu-graz.ac.at
036:        //
037:        // All rights reserved.
038:        //
039:        // Redistribution and use in source and binary forms, with or without
040:        // modification, are permitted provided that the following conditions
041:        // are met:
042:        // 1. Redistributions of source code must retain the above copyright
043:        //    notice, this list of conditions and the following disclaimer.
044:        // 2. Redistributions in binary form must reproduce the above copyright
045:        //    notice, this list of conditions and the following disclaimer in the
046:        //    documentation and/or other materials provided with the distribution.
047:        //
048:        // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
049:        // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
050:        // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
051:        // ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
052:        // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
053:        // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
054:        // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
055:        // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
056:        // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
057:        // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
058:        // SUCH DAMAGE.
059:        //
060:
061:        package jcifs.util;
062:
063:        import java.io.*;
064:
065:        /**
066:         * This code is derived from the above source
067:         * JCIFS API
068:         * Norbert Hranitzky
069:         *
070:         * <p>and modified again by Michael B. Allen
071:         */
072:
073:        public class DES {
074:
075:            private int[] encryptKeys = new int[32];
076:            private int[] decryptKeys = new int[32];
077:
078:            private int[] tempInts = new int[2];
079:
080:            public DES() {
081:
082:            }
083:
084:            // Constructor, byte-array key.
085:            public DES(byte[] key) {
086:                if (key.length == 7) {
087:                    byte[] key8 = new byte[8];
088:                    makeSMBKey(key, key8);
089:                    setKey(key8);
090:                } else {
091:                    setKey(key);
092:                }
093:            }
094:
095:            public static void makeSMBKey(byte[] key7, byte[] key8) {
096:
097:                int i;
098:
099:                key8[0] = (byte) ((key7[0] >> 1) & 0xff);
100:                key8[1] = (byte) ((((key7[0] & 0x01) << 6) | (((key7[1] & 0xff) >> 2) & 0xff)) & 0xff);
101:                key8[2] = (byte) ((((key7[1] & 0x03) << 5) | (((key7[2] & 0xff) >> 3) & 0xff)) & 0xff);
102:                key8[3] = (byte) ((((key7[2] & 0x07) << 4) | (((key7[3] & 0xff) >> 4) & 0xff)) & 0xff);
103:                key8[4] = (byte) ((((key7[3] & 0x0F) << 3) | (((key7[4] & 0xff) >> 5) & 0xff)) & 0xff);
104:                key8[5] = (byte) ((((key7[4] & 0x1F) << 2) | (((key7[5] & 0xff) >> 6) & 0xff)) & 0xff);
105:                key8[6] = (byte) ((((key7[5] & 0x3F) << 1) | (((key7[6] & 0xff) >> 7) & 0xff)) & 0xff);
106:                key8[7] = (byte) (key7[6] & 0x7F);
107:                for (i = 0; i < 8; i++) {
108:                    key8[i] = (byte) (key8[i] << 1);
109:                }
110:            }
111:
112:            /// Set the key.
113:            public void setKey(byte[] key) {
114:
115:                // CHECK PAROTY TBD
116:                deskey(key, true, encryptKeys);
117:                deskey(key, false, decryptKeys);
118:            }
119:
120:            // Turn an 8-byte key into internal keys.
121:            private void deskey(byte[] keyBlock, boolean encrypting, int[] KnL) {
122:
123:                int i, j, l, m, n;
124:                int[] pc1m = new int[56];
125:                int[] pcr = new int[56];
126:                int[] kn = new int[32];
127:
128:                for (j = 0; j < 56; ++j) {
129:                    l = pc1[j];
130:                    m = l & 07;
131:                    pc1m[j] = ((keyBlock[l >>> 3] & bytebit[m]) != 0) ? 1 : 0;
132:                }
133:
134:                for (i = 0; i < 16; ++i) {
135:
136:                    if (encrypting)
137:                        m = i << 1;
138:                    else
139:                        m = (15 - i) << 1;
140:                    n = m + 1;
141:                    kn[m] = kn[n] = 0;
142:                    for (j = 0; j < 28; ++j) {
143:                        l = j + totrot[i];
144:                        if (l < 28)
145:                            pcr[j] = pc1m[l];
146:                        else
147:                            pcr[j] = pc1m[l - 28];
148:                    }
149:                    for (j = 28; j < 56; ++j) {
150:                        l = j + totrot[i];
151:                        if (l < 56)
152:                            pcr[j] = pc1m[l];
153:                        else
154:                            pcr[j] = pc1m[l - 28];
155:                    }
156:                    for (j = 0; j < 24; ++j) {
157:                        if (pcr[pc2[j]] != 0)
158:                            kn[m] |= bigbyte[j];
159:                        if (pcr[pc2[j + 24]] != 0)
160:                            kn[n] |= bigbyte[j];
161:                    }
162:                }
163:                cookey(kn, KnL);
164:            }
165:
166:            private void cookey(int[] raw, int KnL[]) {
167:                int raw0, raw1;
168:                int rawi, KnLi;
169:                int i;
170:
171:                for (i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
172:                    raw0 = raw[rawi++];
173:                    raw1 = raw[rawi++];
174:                    KnL[KnLi] = (raw0 & 0x00fc0000) << 6;
175:                    KnL[KnLi] |= (raw0 & 0x00000fc0) << 10;
176:                    KnL[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
177:                    KnL[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
178:                    ++KnLi;
179:                    KnL[KnLi] = (raw0 & 0x0003f000) << 12;
180:                    KnL[KnLi] |= (raw0 & 0x0000003f) << 16;
181:                    KnL[KnLi] |= (raw1 & 0x0003f000) >>> 4;
182:                    KnL[KnLi] |= (raw1 & 0x0000003f);
183:                    ++KnLi;
184:                }
185:            }
186:
187:            /// Encrypt a block of eight bytes.
188:            private void encrypt(byte[] clearText, int clearOff,
189:                    byte[] cipherText, int cipherOff) {
190:
191:                squashBytesToInts(clearText, clearOff, tempInts, 0, 2);
192:                des(tempInts, tempInts, encryptKeys);
193:                spreadIntsToBytes(tempInts, 0, cipherText, cipherOff, 2);
194:            }
195:
196:            /// Decrypt a block of eight bytes.
197:            private void decrypt(byte[] cipherText, int cipherOff,
198:                    byte[] clearText, int clearOff) {
199:
200:                squashBytesToInts(cipherText, cipherOff, tempInts, 0, 2);
201:                des(tempInts, tempInts, decryptKeys);
202:                spreadIntsToBytes(tempInts, 0, clearText, clearOff, 2);
203:            }
204:
205:            // The DES function.
206:            private void des(int[] inInts, int[] outInts, int[] keys) {
207:
208:                int fval, work, right, leftt;
209:                int round;
210:                int keysi = 0;
211:
212:                leftt = inInts[0];
213:                right = inInts[1];
214:
215:                work = ((leftt >>> 4) ^ right) & 0x0f0f0f0f;
216:                right ^= work;
217:                leftt ^= (work << 4);
218:
219:                work = ((leftt >>> 16) ^ right) & 0x0000ffff;
220:                right ^= work;
221:                leftt ^= (work << 16);
222:
223:                work = ((right >>> 2) ^ leftt) & 0x33333333;
224:                leftt ^= work;
225:                right ^= (work << 2);
226:
227:                work = ((right >>> 8) ^ leftt) & 0x00ff00ff;
228:                leftt ^= work;
229:                right ^= (work << 8);
230:                right = (right << 1) | ((right >>> 31) & 1);
231:
232:                work = (leftt ^ right) & 0xaaaaaaaa;
233:                leftt ^= work;
234:                right ^= work;
235:                leftt = (leftt << 1) | ((leftt >>> 31) & 1);
236:
237:                for (round = 0; round < 8; ++round) {
238:                    work = (right << 28) | (right >>> 4);
239:                    work ^= keys[keysi++];
240:                    fval = SP7[work & 0x0000003f];
241:                    fval |= SP5[(work >>> 8) & 0x0000003f];
242:                    fval |= SP3[(work >>> 16) & 0x0000003f];
243:                    fval |= SP1[(work >>> 24) & 0x0000003f];
244:                    work = right ^ keys[keysi++];
245:                    fval |= SP8[work & 0x0000003f];
246:                    fval |= SP6[(work >>> 8) & 0x0000003f];
247:                    fval |= SP4[(work >>> 16) & 0x0000003f];
248:                    fval |= SP2[(work >>> 24) & 0x0000003f];
249:                    leftt ^= fval;
250:                    work = (leftt << 28) | (leftt >>> 4);
251:                    work ^= keys[keysi++];
252:                    fval = SP7[work & 0x0000003f];
253:                    fval |= SP5[(work >>> 8) & 0x0000003f];
254:                    fval |= SP3[(work >>> 16) & 0x0000003f];
255:                    fval |= SP1[(work >>> 24) & 0x0000003f];
256:                    work = leftt ^ keys[keysi++];
257:                    fval |= SP8[work & 0x0000003f];
258:                    fval |= SP6[(work >>> 8) & 0x0000003f];
259:                    fval |= SP4[(work >>> 16) & 0x0000003f];
260:                    fval |= SP2[(work >>> 24) & 0x0000003f];
261:                    right ^= fval;
262:                }
263:
264:                right = (right << 31) | (right >>> 1);
265:                work = (leftt ^ right) & 0xaaaaaaaa;
266:                leftt ^= work;
267:                right ^= work;
268:                leftt = (leftt << 31) | (leftt >>> 1);
269:                work = ((leftt >>> 8) ^ right) & 0x00ff00ff;
270:                right ^= work;
271:                leftt ^= (work << 8);
272:                work = ((leftt >>> 2) ^ right) & 0x33333333;
273:                right ^= work;
274:                leftt ^= (work << 2);
275:                work = ((right >>> 16) ^ leftt) & 0x0000ffff;
276:                leftt ^= work;
277:                right ^= (work << 16);
278:                work = ((right >>> 4) ^ leftt) & 0x0f0f0f0f;
279:                leftt ^= work;
280:                right ^= (work << 4);
281:                outInts[0] = right;
282:                outInts[1] = leftt;
283:            }
284:
285:            /// Encrypt a block of bytes.
286:            public void encrypt(byte[] clearText, byte[] cipherText) {
287:                encrypt(clearText, 0, cipherText, 0);
288:            }
289:
290:            /// Decrypt a block of bytes.
291:            public void decrypt(byte[] cipherText, byte[] clearText) {
292:
293:                decrypt(cipherText, 0, clearText, 0);
294:            }
295:
296:            /**
297:             * encrypts an array where the length must be a multiple of 8
298:             */
299:            public byte[] encrypt(byte[] clearText) {
300:
301:                int length = clearText.length;
302:
303:                if (length % 8 != 0) {
304:                    System.out.println("Array must be a multiple of 8");
305:                    return null;
306:                }
307:
308:                byte[] cipherText = new byte[length];
309:                int count = length / 8;
310:
311:                for (int i = 0; i < count; i++)
312:                    encrypt(clearText, i * 8, cipherText, i * 8);
313:
314:                return cipherText;
315:            }
316:
317:            /**
318:             * decrypts an array where the length must be a multiple of 8
319:             */
320:            public byte[] decrypt(byte[] cipherText) {
321:
322:                int length = cipherText.length;
323:
324:                if (length % 8 != 0) {
325:                    System.out.println("Array must be a multiple of 8");
326:                    return null;
327:                }
328:
329:                byte[] clearText = new byte[length];
330:                int count = length / 8;
331:
332:                for (int i = 0; i < count; i++)
333:                    encrypt(cipherText, i * 8, clearText, i * 8);
334:
335:                return clearText;
336:            }
337:
338:            // Tables, permutations, S-boxes, etc.
339:
340:            private static byte[] bytebit = { (byte) 0x80, (byte) 0x40,
341:                    (byte) 0x20, (byte) 0x10, (byte) 0x08, (byte) 0x04,
342:                    (byte) 0x02, (byte) 0x01 };
343:            private static int[] bigbyte = { 0x800000, 0x400000, 0x200000,
344:                    0x100000, 0x080000, 0x040000, 0x020000, 0x010000, 0x008000,
345:                    0x004000, 0x002000, 0x001000, 0x000800, 0x000400, 0x000200,
346:                    0x000100, 0x000080, 0x000040, 0x000020, 0x000010, 0x000008,
347:                    0x000004, 0x000002, 0x000001 };
348:            private static byte[] pc1 = { (byte) 56, (byte) 48, (byte) 40,
349:                    (byte) 32, (byte) 24, (byte) 16, (byte) 8, (byte) 0,
350:                    (byte) 57, (byte) 49, (byte) 41, (byte) 33, (byte) 25,
351:                    (byte) 17, (byte) 9, (byte) 1, (byte) 58, (byte) 50,
352:                    (byte) 42, (byte) 34, (byte) 26, (byte) 18, (byte) 10,
353:                    (byte) 2, (byte) 59, (byte) 51, (byte) 43, (byte) 35,
354:                    (byte) 62, (byte) 54, (byte) 46, (byte) 38, (byte) 30,
355:                    (byte) 22, (byte) 14, (byte) 6, (byte) 61, (byte) 53,
356:                    (byte) 45, (byte) 37, (byte) 29, (byte) 21, (byte) 13,
357:                    (byte) 5, (byte) 60, (byte) 52, (byte) 44, (byte) 36,
358:                    (byte) 28, (byte) 20, (byte) 12, (byte) 4, (byte) 27,
359:                    (byte) 19, (byte) 11, (byte) 3 };
360:            private static int[] totrot = { 1, 2, 4, 6, 8, 10, 12, 14, 15, 17,
361:                    19, 21, 23, 25, 27, 28 };
362:
363:            private static byte[] pc2 = { (byte) 13, (byte) 16, (byte) 10,
364:                    (byte) 23, (byte) 0, (byte) 4, (byte) 2, (byte) 27,
365:                    (byte) 14, (byte) 5, (byte) 20, (byte) 9, (byte) 22,
366:                    (byte) 18, (byte) 11, (byte) 3, (byte) 25, (byte) 7,
367:                    (byte) 15, (byte) 6, (byte) 26, (byte) 19, (byte) 12,
368:                    (byte) 1, (byte) 40, (byte) 51, (byte) 30, (byte) 36,
369:                    (byte) 46, (byte) 54, (byte) 29, (byte) 39, (byte) 50,
370:                    (byte) 44, (byte) 32, (byte) 47, (byte) 43, (byte) 48,
371:                    (byte) 38, (byte) 55, (byte) 33, (byte) 52, (byte) 45,
372:                    (byte) 41, (byte) 49, (byte) 35, (byte) 28, (byte) 31, };
373:
374:            private static int[] SP1 = { 0x01010400, 0x00000000, 0x00010000,
375:                    0x01010404, 0x01010004, 0x00010404, 0x00000004, 0x00010000,
376:                    0x00000400, 0x01010400, 0x01010404, 0x00000400, 0x01000404,
377:                    0x01010004, 0x01000000, 0x00000004, 0x00000404, 0x01000400,
378:                    0x01000400, 0x00010400, 0x00010400, 0x01010000, 0x01010000,
379:                    0x01000404, 0x00010004, 0x01000004, 0x01000004, 0x00010004,
380:                    0x00000000, 0x00000404, 0x00010404, 0x01000000, 0x00010000,
381:                    0x01010404, 0x00000004, 0x01010000, 0x01010400, 0x01000000,
382:                    0x01000000, 0x00000400, 0x01010004, 0x00010000, 0x00010400,
383:                    0x01000004, 0x00000400, 0x00000004, 0x01000404, 0x00010404,
384:                    0x01010404, 0x00010004, 0x01010000, 0x01000404, 0x01000004,
385:                    0x00000404, 0x00010404, 0x01010400, 0x00000404, 0x01000400,
386:                    0x01000400, 0x00000000, 0x00010004, 0x00010400, 0x00000000,
387:                    0x01010004 };
388:            private static int[] SP2 = { 0x80108020, 0x80008000, 0x00008000,
389:                    0x00108020, 0x00100000, 0x00000020, 0x80100020, 0x80008020,
390:                    0x80000020, 0x80108020, 0x80108000, 0x80000000, 0x80008000,
391:                    0x00100000, 0x00000020, 0x80100020, 0x00108000, 0x00100020,
392:                    0x80008020, 0x00000000, 0x80000000, 0x00008000, 0x00108020,
393:                    0x80100000, 0x00100020, 0x80000020, 0x00000000, 0x00108000,
394:                    0x00008020, 0x80108000, 0x80100000, 0x00008020, 0x00000000,
395:                    0x00108020, 0x80100020, 0x00100000, 0x80008020, 0x80100000,
396:                    0x80108000, 0x00008000, 0x80100000, 0x80008000, 0x00000020,
397:                    0x80108020, 0x00108020, 0x00000020, 0x00008000, 0x80000000,
398:                    0x00008020, 0x80108000, 0x00100000, 0x80000020, 0x00100020,
399:                    0x80008020, 0x80000020, 0x00100020, 0x00108000, 0x00000000,
400:                    0x80008000, 0x00008020, 0x80000000, 0x80100020, 0x80108020,
401:                    0x00108000 };
402:            private static int[] SP3 = { 0x00000208, 0x08020200, 0x00000000,
403:                    0x08020008, 0x08000200, 0x00000000, 0x00020208, 0x08000200,
404:                    0x00020008, 0x08000008, 0x08000008, 0x00020000, 0x08020208,
405:                    0x00020008, 0x08020000, 0x00000208, 0x08000000, 0x00000008,
406:                    0x08020200, 0x00000200, 0x00020200, 0x08020000, 0x08020008,
407:                    0x00020208, 0x08000208, 0x00020200, 0x00020000, 0x08000208,
408:                    0x00000008, 0x08020208, 0x00000200, 0x08000000, 0x08020200,
409:                    0x08000000, 0x00020008, 0x00000208, 0x00020000, 0x08020200,
410:                    0x08000200, 0x00000000, 0x00000200, 0x00020008, 0x08020208,
411:                    0x08000200, 0x08000008, 0x00000200, 0x00000000, 0x08020008,
412:                    0x08000208, 0x00020000, 0x08000000, 0x08020208, 0x00000008,
413:                    0x00020208, 0x00020200, 0x08000008, 0x08020000, 0x08000208,
414:                    0x00000208, 0x08020000, 0x00020208, 0x00000008, 0x08020008,
415:                    0x00020200 };
416:            private static int[] SP4 = { 0x00802001, 0x00002081, 0x00002081,
417:                    0x00000080, 0x00802080, 0x00800081, 0x00800001, 0x00002001,
418:                    0x00000000, 0x00802000, 0x00802000, 0x00802081, 0x00000081,
419:                    0x00000000, 0x00800080, 0x00800001, 0x00000001, 0x00002000,
420:                    0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002001,
421:                    0x00002080, 0x00800081, 0x00000001, 0x00002080, 0x00800080,
422:                    0x00002000, 0x00802080, 0x00802081, 0x00000081, 0x00800080,
423:                    0x00800001, 0x00802000, 0x00802081, 0x00000081, 0x00000000,
424:                    0x00000000, 0x00802000, 0x00002080, 0x00800080, 0x00800081,
425:                    0x00000001, 0x00802001, 0x00002081, 0x00002081, 0x00000080,
426:                    0x00802081, 0x00000081, 0x00000001, 0x00002000, 0x00800001,
427:                    0x00002001, 0x00802080, 0x00800081, 0x00002001, 0x00002080,
428:                    0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002000,
429:                    0x00802080 };
430:            private static int[] SP5 = { 0x00000100, 0x02080100, 0x02080000,
431:                    0x42000100, 0x00080000, 0x00000100, 0x40000000, 0x02080000,
432:                    0x40080100, 0x00080000, 0x02000100, 0x40080100, 0x42000100,
433:                    0x42080000, 0x00080100, 0x40000000, 0x02000000, 0x40080000,
434:                    0x40080000, 0x00000000, 0x40000100, 0x42080100, 0x42080100,
435:                    0x02000100, 0x42080000, 0x40000100, 0x00000000, 0x42000000,
436:                    0x02080100, 0x02000000, 0x42000000, 0x00080100, 0x00080000,
437:                    0x42000100, 0x00000100, 0x02000000, 0x40000000, 0x02080000,
438:                    0x42000100, 0x40080100, 0x02000100, 0x40000000, 0x42080000,
439:                    0x02080100, 0x40080100, 0x00000100, 0x02000000, 0x42080000,
440:                    0x42080100, 0x00080100, 0x42000000, 0x42080100, 0x02080000,
441:                    0x00000000, 0x40080000, 0x42000000, 0x00080100, 0x02000100,
442:                    0x40000100, 0x00080000, 0x00000000, 0x40080000, 0x02080100,
443:                    0x40000100 };
444:            private static int[] SP6 = { 0x20000010, 0x20400000, 0x00004000,
445:                    0x20404010, 0x20400000, 0x00000010, 0x20404010, 0x00400000,
446:                    0x20004000, 0x00404010, 0x00400000, 0x20000010, 0x00400010,
447:                    0x20004000, 0x20000000, 0x00004010, 0x00000000, 0x00400010,
448:                    0x20004010, 0x00004000, 0x00404000, 0x20004010, 0x00000010,
449:                    0x20400010, 0x20400010, 0x00000000, 0x00404010, 0x20404000,
450:                    0x00004010, 0x00404000, 0x20404000, 0x20000000, 0x20004000,
451:                    0x00000010, 0x20400010, 0x00404000, 0x20404010, 0x00400000,
452:                    0x00004010, 0x20000010, 0x00400000, 0x20004000, 0x20000000,
453:                    0x00004010, 0x20000010, 0x20404010, 0x00404000, 0x20400000,
454:                    0x00404010, 0x20404000, 0x00000000, 0x20400010, 0x00000010,
455:                    0x00004000, 0x20400000, 0x00404010, 0x00004000, 0x00400010,
456:                    0x20004010, 0x00000000, 0x20404000, 0x20000000, 0x00400010,
457:                    0x20004010 };
458:            private static int[] SP7 = { 0x00200000, 0x04200002, 0x04000802,
459:                    0x00000000, 0x00000800, 0x04000802, 0x00200802, 0x04200800,
460:                    0x04200802, 0x00200000, 0x00000000, 0x04000002, 0x00000002,
461:                    0x04000000, 0x04200002, 0x00000802, 0x04000800, 0x00200802,
462:                    0x00200002, 0x04000800, 0x04000002, 0x04200000, 0x04200800,
463:                    0x00200002, 0x04200000, 0x00000800, 0x00000802, 0x04200802,
464:                    0x00200800, 0x00000002, 0x04000000, 0x00200800, 0x04000000,
465:                    0x00200800, 0x00200000, 0x04000802, 0x04000802, 0x04200002,
466:                    0x04200002, 0x00000002, 0x00200002, 0x04000000, 0x04000800,
467:                    0x00200000, 0x04200800, 0x00000802, 0x00200802, 0x04200800,
468:                    0x00000802, 0x04000002, 0x04200802, 0x04200000, 0x00200800,
469:                    0x00000000, 0x00000002, 0x04200802, 0x00000000, 0x00200802,
470:                    0x04200000, 0x00000800, 0x04000002, 0x04000800, 0x00000800,
471:                    0x00200002 };
472:            private static int[] SP8 = { 0x10001040, 0x00001000, 0x00040000,
473:                    0x10041040, 0x10000000, 0x10001040, 0x00000040, 0x10000000,
474:                    0x00040040, 0x10040000, 0x10041040, 0x00041000, 0x10041000,
475:                    0x00041040, 0x00001000, 0x00000040, 0x10040000, 0x10000040,
476:                    0x10001000, 0x00001040, 0x00041000, 0x00040040, 0x10040040,
477:                    0x10041000, 0x00001040, 0x00000000, 0x00000000, 0x10040040,
478:                    0x10000040, 0x10001000, 0x00041040, 0x00040000, 0x00041040,
479:                    0x00040000, 0x10041000, 0x00001000, 0x00000040, 0x10040040,
480:                    0x00001000, 0x00041040, 0x10001000, 0x00000040, 0x10000040,
481:                    0x10040000, 0x10040040, 0x10000000, 0x00040000, 0x10001040,
482:                    0x00000000, 0x10041040, 0x00040040, 0x10000040, 0x10040000,
483:                    0x10001000, 0x10001040, 0x00000000, 0x10041040, 0x00041000,
484:                    0x00041000, 0x00001040, 0x00001040, 0x00040040, 0x10000000,
485:                    0x10041000 };
486:
487:            /// Squash bytes down to ints.
488:            public static void squashBytesToInts(byte[] inBytes, int inOff,
489:                    int[] outInts, int outOff, int intLen) {
490:
491:                for (int i = 0; i < intLen; ++i)
492:                    outInts[outOff + i] = ((inBytes[inOff + i * 4] & 0xff) << 24)
493:                            | ((inBytes[inOff + i * 4 + 1] & 0xff) << 16)
494:                            | ((inBytes[inOff + i * 4 + 2] & 0xff) << 8)
495:                            | (inBytes[inOff + i * 4 + 3] & 0xff);
496:            }
497:
498:            /// Spread ints into bytes.
499:            public static void spreadIntsToBytes(int[] inInts, int inOff,
500:                    byte[] outBytes, int outOff, int intLen) {
501:
502:                for (int i = 0; i < intLen; ++i) {
503:
504:                    outBytes[outOff + i * 4] = (byte) (inInts[inOff + i] >>> 24);
505:                    outBytes[outOff + i * 4 + 1] = (byte) (inInts[inOff + i] >>> 16);
506:                    outBytes[outOff + i * 4 + 2] = (byte) (inInts[inOff + i] >>> 8);
507:                    outBytes[outOff + i * 4 + 3] = (byte) inInts[inOff + i];
508:                }
509:            }
510:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.