1 // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.kpdus.com/jad.html
3 // Decompiler options: packimports(3) fieldsfirst nonlb space
8 public class DesCipher {
10 private int encryptKeys[];
11 private int decryptKeys[];
12 private int tempInts[];
13 private static byte bytebit[] = {
14 1, 2, 4, 8, 16, 32, 64, -128
16 private static int bigbyte[] = {
17 0x800000, 0x400000, 0x200000, 0x100000, 0x80000, 0x40000, 0x20000, 0x10000, 32768, 16384,
18 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16,
21 private static byte pc1[] = {
22 56, 48, 40, 32, 24, 16, 8, 0, 57, 49,
23 41, 33, 25, 17, 9, 1, 58, 50, 42, 34,
24 26, 18, 10, 2, 59, 51, 43, 35, 62, 54,
25 46, 38, 30, 22, 14, 6, 61, 53, 45, 37,
26 29, 21, 13, 5, 60, 52, 44, 36, 28, 20,
29 private static int totrot[] = {
30 1, 2, 4, 6, 8, 10, 12, 14, 15, 17,
31 19, 21, 23, 25, 27, 28
33 private static byte pc2[] = {
34 13, 16, 10, 23, 0, 4, 2, 27, 14, 5,
35 20, 9, 22, 18, 11, 3, 25, 7, 15, 6,
36 26, 19, 12, 1, 40, 51, 30, 36, 46, 54,
37 29, 39, 50, 44, 32, 47, 43, 48, 38, 55,
38 33, 52, 45, 41, 49, 35, 28, 31
40 private static int SP1[] = {
41 0x1010400, 0, 0x10000, 0x1010404, 0x1010004, 0x10404, 4, 0x10000, 1024, 0x1010400,
42 0x1010404, 1024, 0x1000404, 0x1010004, 0x1000000, 4, 1028, 0x1000400, 0x1000400, 0x10400,
43 0x10400, 0x1010000, 0x1010000, 0x1000404, 0x10004, 0x1000004, 0x1000004, 0x10004, 0, 1028,
44 0x10404, 0x1000000, 0x10000, 0x1010404, 4, 0x1010000, 0x1010400, 0x1000000, 0x1000000, 1024,
45 0x1010004, 0x10000, 0x10400, 0x1000004, 1024, 4, 0x1000404, 0x10404, 0x1010404, 0x10004,
46 0x1010000, 0x1000404, 0x1000004, 1028, 0x10404, 0x1010400, 1028, 0x1000400, 0x1000400, 0,
47 0x10004, 0x10400, 0, 0x1010004
49 private static int SP2[] = {
50 0x80108020, 0x80008000, 32768, 0x108020, 0x100000, 32, 0x80100020, 0x80008020, 0x80000020, 0x80108020,
51 0x80108000, 0x80000000, 0x80008000, 0x100000, 32, 0x80100020, 0x108000, 0x100020, 0x80008020, 0,
52 0x80000000, 32768, 0x108020, 0x80100000, 0x100020, 0x80000020, 0, 0x108000, 32800, 0x80108000,
53 0x80100000, 32800, 0, 0x108020, 0x80100020, 0x100000, 0x80008020, 0x80100000, 0x80108000, 32768,
54 0x80100000, 0x80008000, 32, 0x80108020, 0x108020, 32, 32768, 0x80000000, 32800, 0x80108000,
55 0x100000, 0x80000020, 0x100020, 0x80008020, 0x80000020, 0x100020, 0x108000, 0, 0x80008000, 32800,
56 0x80000000, 0x80100020, 0x80108020, 0x108000
58 private static int SP3[] = {
59 520, 0x8020200, 0, 0x8020008, 0x8000200, 0, 0x20208, 0x8000200, 0x20008, 0x8000008,
60 0x8000008, 0x20000, 0x8020208, 0x20008, 0x8020000, 520, 0x8000000, 8, 0x8020200, 512,
61 0x20200, 0x8020000, 0x8020008, 0x20208, 0x8000208, 0x20200, 0x20000, 0x8000208, 8, 0x8020208,
62 512, 0x8000000, 0x8020200, 0x8000000, 0x20008, 520, 0x20000, 0x8020200, 0x8000200, 0,
63 512, 0x20008, 0x8020208, 0x8000200, 0x8000008, 512, 0, 0x8020008, 0x8000208, 0x20000,
64 0x8000000, 0x8020208, 8, 0x20208, 0x20200, 0x8000008, 0x8020000, 0x8000208, 520, 0x8020000,
65 0x20208, 8, 0x8020008, 0x20200
67 private static int SP4[] = {
68 0x802001, 8321, 8321, 128, 0x802080, 0x800081, 0x800001, 8193, 0, 0x802000,
69 0x802000, 0x802081, 129, 0, 0x800080, 0x800001, 1, 8192, 0x800000, 0x802001,
70 128, 0x800000, 8193, 8320, 0x800081, 1, 8320, 0x800080, 8192, 0x802080,
71 0x802081, 129, 0x800080, 0x800001, 0x802000, 0x802081, 129, 0, 0, 0x802000,
72 8320, 0x800080, 0x800081, 1, 0x802001, 8321, 8321, 128, 0x802081, 129,
73 1, 8192, 0x800001, 8193, 0x802080, 0x800081, 8193, 8320, 0x800000, 0x802001,
74 128, 0x800000, 8192, 0x802080
76 private static int SP5[] = {
77 256, 0x2080100, 0x2080000, 0x42000100, 0x80000, 256, 0x40000000, 0x2080000, 0x40080100, 0x80000,
78 0x2000100, 0x40080100, 0x42000100, 0x42080000, 0x80100, 0x40000000, 0x2000000, 0x40080000, 0x40080000, 0,
79 0x40000100, 0x42080100, 0x42080100, 0x2000100, 0x42080000, 0x40000100, 0, 0x42000000, 0x2080100, 0x2000000,
80 0x42000000, 0x80100, 0x80000, 0x42000100, 256, 0x2000000, 0x40000000, 0x2080000, 0x42000100, 0x40080100,
81 0x2000100, 0x40000000, 0x42080000, 0x2080100, 0x40080100, 256, 0x2000000, 0x42080000, 0x42080100, 0x80100,
82 0x42000000, 0x42080100, 0x2080000, 0, 0x40080000, 0x42000000, 0x80100, 0x2000100, 0x40000100, 0x80000,
83 0, 0x40080000, 0x2080100, 0x40000100
85 private static int SP6[] = {
86 0x20000010, 0x20400000, 16384, 0x20404010, 0x20400000, 16, 0x20404010, 0x400000, 0x20004000, 0x404010,
87 0x400000, 0x20000010, 0x400010, 0x20004000, 0x20000000, 16400, 0, 0x400010, 0x20004010, 16384,
88 0x404000, 0x20004010, 16, 0x20400010, 0x20400010, 0, 0x404010, 0x20404000, 16400, 0x404000,
89 0x20404000, 0x20000000, 0x20004000, 16, 0x20400010, 0x404000, 0x20404010, 0x400000, 16400, 0x20000010,
90 0x400000, 0x20004000, 0x20000000, 16400, 0x20000010, 0x20404010, 0x404000, 0x20400000, 0x404010, 0x20404000,
91 0, 0x20400010, 16, 16384, 0x20400000, 0x404010, 16384, 0x400010, 0x20004010, 0,
92 0x20404000, 0x20000000, 0x400010, 0x20004010
94 private static int SP7[] = {
95 0x200000, 0x4200002, 0x4000802, 0, 2048, 0x4000802, 0x200802, 0x4200800, 0x4200802, 0x200000,
96 0, 0x4000002, 2, 0x4000000, 0x4200002, 2050, 0x4000800, 0x200802, 0x200002, 0x4000800,
97 0x4000002, 0x4200000, 0x4200800, 0x200002, 0x4200000, 2048, 2050, 0x4200802, 0x200800, 2,
98 0x4000000, 0x200800, 0x4000000, 0x200800, 0x200000, 0x4000802, 0x4000802, 0x4200002, 0x4200002, 2,
99 0x200002, 0x4000000, 0x4000800, 0x200000, 0x4200800, 2050, 0x200802, 0x4200800, 2050, 0x4000002,
100 0x4200802, 0x4200000, 0x200800, 0, 2, 0x4200802, 0, 0x200802, 0x4200000, 2048,
101 0x4000002, 0x4000800, 2048, 0x200002
103 private static int SP8[] = {
104 0x10001040, 4096, 0x40000, 0x10041040, 0x10000000, 0x10001040, 64, 0x10000000, 0x40040, 0x10040000,
105 0x10041040, 0x41000, 0x10041000, 0x41040, 4096, 64, 0x10040000, 0x10000040, 0x10001000, 4160,
106 0x41000, 0x40040, 0x10040040, 0x10041000, 4160, 0, 0, 0x10040040, 0x10000040, 0x10001000,
107 0x41040, 0x40000, 0x41040, 0x40000, 0x10041000, 4096, 64, 0x10040040, 4096, 0x41040,
108 0x10001000, 64, 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x40000, 0x10001040, 0, 0x10041040,
109 0x40040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, 0, 0x10041040, 0x41000, 0x41000, 4160,
110 4160, 0x40040, 0x10000000, 0x10041000
113 public DesCipher(byte abyte0[]) {
114 encryptKeys = new int[32];
115 decryptKeys = new int[32];
116 tempInts = new int[2];
120 public void setKey(byte abyte0[]) {
121 deskey(abyte0, true, encryptKeys);
122 deskey(abyte0, false, decryptKeys);
125 private void deskey(byte abyte0[], boolean flag, int ai[]) {
126 int ai1[] = new int[56];
127 int ai2[] = new int[56];
128 int ai3[] = new int[32];
129 for (int j = 0; j < 56; j++) {
132 ai1[j] = (abyte0[byte0 >>> 3] & bytebit[l1]) == 0 ? 0 : 1;
135 for (int i = 0; i < 16; i++) {
142 ai3[i2] = ai3[j2] = 0;
143 for (int k = 0; k < 28; k++) {
144 int j1 = k + totrot[i];
148 ai2[k] = ai1[j1 - 28];
151 for (int l = 28; l < 56; l++) {
152 int k1 = l + totrot[i];
156 ai2[l] = ai1[k1 - 28];
159 for (int i1 = 0; i1 < 24; i1++) {
160 if (ai2[pc2[i1]] != 0)
161 ai3[i2] |= bigbyte[i1];
162 if (ai2[pc2[i1 + 24]] != 0)
163 ai3[j2] |= bigbyte[i1];
171 private void cookey(int ai[], int ai1[]) {
175 for (; i1 < 16; i1++) {
178 ai1[l] = (i & 0xfc0000) << 6;
179 ai1[l] |= (i & 0xfc0) << 10;
180 ai1[l] |= (j & 0xfc0000) >>> 10;
181 ai1[l] |= (j & 0xfc0) >>> 6;
183 ai1[l] = (i & 0x3f000) << 12;
184 ai1[l] |= (i & 0x3f) << 16;
185 ai1[l] |= (j & 0x3f000) >>> 4;
192 public void encrypt(byte abyte0[], int i, byte abyte1[], int j) {
193 squashBytesToInts(abyte0, i, tempInts, 0, 2);
194 des(tempInts, tempInts, encryptKeys);
195 spreadIntsToBytes(tempInts, 0, abyte1, j, 2);
198 public void decrypt(byte abyte0[], int i, byte abyte1[], int j) {
199 squashBytesToInts(abyte0, i, tempInts, 0, 2);
200 des(tempInts, tempInts, decryptKeys);
201 spreadIntsToBytes(tempInts, 0, abyte1, j, 2);
204 private void des(int ai[], int ai1[], int ai2[]) {
208 int j = (l >>> 4 ^ k) & 0xf0f0f0f;
211 j = (l >>> 16 ^ k) & 0xffff;
214 j = (k >>> 2 ^ l) & 0x33333333;
217 j = (k >>> 8 ^ l) & 0xff00ff;
220 k = k << 1 | k >>> 31 & 1;
221 j = (l ^ k) & 0xaaaaaaaa;
224 l = l << 1 | l >>> 31 & 1;
225 for (int i1 = 0; i1 < 8; i1++) {
226 j = k << 28 | k >>> 4;
228 int i = SP7[j & 0x3f];
229 i |= SP5[j >>> 8 & 0x3f];
230 i |= SP3[j >>> 16 & 0x3f];
231 i |= SP1[j >>> 24 & 0x3f];
234 i |= SP6[j >>> 8 & 0x3f];
235 i |= SP4[j >>> 16 & 0x3f];
236 i |= SP2[j >>> 24 & 0x3f];
238 j = l << 28 | l >>> 4;
241 i |= SP5[j >>> 8 & 0x3f];
242 i |= SP3[j >>> 16 & 0x3f];
243 i |= SP1[j >>> 24 & 0x3f];
246 i |= SP6[j >>> 8 & 0x3f];
247 i |= SP4[j >>> 16 & 0x3f];
248 i |= SP2[j >>> 24 & 0x3f];
252 k = k << 31 | k >>> 1;
253 j = (l ^ k) & 0xaaaaaaaa;
256 l = l << 31 | l >>> 1;
257 j = (l >>> 8 ^ k) & 0xff00ff;
260 j = (l >>> 2 ^ k) & 0x33333333;
263 j = (k >>> 16 ^ l) & 0xffff;
266 j = (k >>> 4 ^ l) & 0xf0f0f0f;
273 public static void squashBytesToInts(byte abyte0[], int i, int ai[], int j, int k) {
274 for (int l = 0; l < k; l++)
275 ai[j + l] = (abyte0[i + l * 4] & 0xff) << 24 | (abyte0[i + l * 4 + 1] & 0xff) << 16 | (abyte0[i + l * 4 + 2] & 0xff) << 8 | abyte0[i + l * 4 + 3] & 0xff;
279 public static void spreadIntsToBytes(int ai[], int i, byte abyte0[], int j, int k) {
280 for (int l = 0; l < k; l++) {
281 abyte0[j + l * 4] = (byte)(ai[i + l] >>> 24);
282 abyte0[j + l * 4 + 1] = (byte)(ai[i + l] >>> 16);
283 abyte0[j + l * 4 + 2] = (byte)(ai[i + l] >>> 8);
284 abyte0[j + l * 4 + 3] = (byte)ai[i + l];