oracle_ebs_authentication 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ Oracle E-Business Suite authentication
2
+ ======================================
3
+
4
+ This plugin provides Oracle E-Business Suite user authentication functionality.
5
+
6
+ ## Installation
7
+
8
+ gem install oracle_ebs_authentication
9
+
10
+ ## Setup
11
+
12
+ 1. Grant execute on `apps.fnd_encrypted_pwd` to your database user.
13
+ 2. Setup [ruby-plsql](https://rubygems.org/gems/ruby-plsql) connection for your database.
14
+
15
+ ## Examples
16
+
17
+ Simple example how to use the plugin for Oracle E-Business Suite user authentication:
18
+
19
+ authenticator = OracleEbsAuthentication::Authenticator.new
20
+ if authenticator.validate_user_password(username, password)
21
+ FndUser.find_by_username(username.upcase)
22
+ end
23
+
24
+ See other usage examples in RSpec examples in `spec/`.
25
+
26
+ ## Credits
27
+
28
+ Copyright (C) 2007-2011 Raimonds Simanovskis, Edgars Beigarts.
29
+
30
+ Oracle E-Business Suite authentication encryption algorythm was taken from
31
+ [Jira eBusiness Suite Authenticator](http://code.google.com/p/jebusinessauth/) and
32
+ rewritten in Ruby by Raimonds Simanovskis.
@@ -0,0 +1,6 @@
1
+ require "active_support"
2
+ require "active_support/core_ext/string/multibyte"
3
+
4
+ require "oracle_ebs_authentication/authenticator"
5
+ require "oracle_ebs_authentication/security"
6
+ require "oracle_ebs_authentication/version"
@@ -0,0 +1,25 @@
1
+ require "ruby_plsql"
2
+
3
+ module OracleEbsAuthentication
4
+ class Authenticator
5
+ def initialize
6
+ @security = OracleEbsAuthentication::Security.new
7
+ end
8
+
9
+ def get_fnd_password(username, password)
10
+ username &&= username.upcase
11
+ result = plsql.apps.fnd_security_pkg.fnd_encrypted_pwd(username, nil, nil, nil)
12
+ if result[:p_password]
13
+ @security.decrypt(username + "/" + password, result[:p_password], false)
14
+ end
15
+ rescue OCIError
16
+ nil
17
+ end
18
+
19
+ def validate_user_password(username, password)
20
+ if username && password
21
+ !! get_fnd_password(username, password)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2170 @@
1
+ # The Java original source code was taken form http://www.milci.com/eappsjira
2
+ # Original Java source is included in comments followed by corresponding Ruby code.
3
+ # As original Java source is not documented then Ruby source code was done
4
+ # as similar as possible to Java code to avoid differences in functionality.
5
+ #
6
+ # http://code.google.com/p/jebusinessauth/source/browse/trunk/src/com/milci/ebusinesssuite/eBusinessSuiteSecurity.java
7
+ #
8
+
9
+ require "digest/sha1"
10
+
11
+ module OracleEbsAuthentication
12
+
13
+ # public class eBusinessSuiteSecurity {
14
+ class Security
15
+
16
+ # public eBusinessSuiteSecurity() {
17
+ # }
18
+ def initialize
19
+ end
20
+
21
+ # static String control(String s1, int i1, String s2) {
22
+ # return newControl(s1, s2, i1, 0);
23
+ # }
24
+ def control(s1, i1, s2)
25
+ return new_control(s1, s2, i1, 0)
26
+ end
27
+
28
+ #private static int[] a(byte abyte0[], int i1) {
29
+ def a(abyte0, i1)
30
+ # int ai[] = new int[16];
31
+ ai = [nil]*16
32
+ # int ai1[] = new int[5];
33
+ ai1 = [nil]*5
34
+ # u(ai1, null);
35
+ u(ai1, nil)
36
+ # int l1 = ai.length;
37
+ l1 = ai.length
38
+ # int k1 = 0;
39
+ k1 = 0
40
+ # int j2 = 0;
41
+ j2 = 0
42
+ # int j1;
43
+ # for (j1 = 0; j1 < (i1 & -4); j1 += 4) {
44
+ j1 = 0
45
+ while j1 < (i1 & -4)
46
+ # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
47
+ # abyte0[j2 + 3] << 24;
48
+ ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
49
+ abyte0[j2 + 3] << 24) & 0xffffffff
50
+ # if (++k1 == l1) {
51
+ # u(ai1, ai);
52
+ # k1 = 0;
53
+ # }
54
+ k1 +=1
55
+ if (k1 == l1)
56
+ u(ai1, ai)
57
+ k1 = 0
58
+ end
59
+ # j2 += 4;
60
+ j2 += 4
61
+ # }
62
+ j1 += 4
63
+ end
64
+ #
65
+ # j1 = i1 - j1;
66
+ j1 = i1 - j1
67
+ # if (j1 == 1) {
68
+ # ai[k1] = abyte0[j2] & 0xff | 0x8000;
69
+ # }
70
+ if (j1 == 1)
71
+ ai[k1] = abyte0[j2] & 0xff | 0x8000
72
+ # else
73
+ # if (j1 == 2) {
74
+ # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | 0x800000;
75
+ # }
76
+ elsif (j1 == 2)
77
+ ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | 0x800000) & 0xffffffff
78
+ # else
79
+ # if (j1 == 3) {
80
+ # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
81
+ # 0x80000000;
82
+ # }
83
+ elsif (j1 == 3)
84
+ ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 | 0x80000000) & 0xffffffff
85
+ # else {
86
+ # ai[k1] = 128;
87
+ # }
88
+ else
89
+ ai[k1] = 128
90
+ end
91
+ # if (++k1 >= l1 - 2) {
92
+ # while (k1 < l1) {
93
+ # ai[k1++] = 0;
94
+ # }
95
+ # u(ai1, ai);
96
+ # k1 = 0;
97
+ # }
98
+ k1 += 1
99
+ if (k1 >= l1 - 2)
100
+ while (k1 < l1)
101
+ ai[k1] = 0
102
+ k1 += 1
103
+ end
104
+ u(ai1,ai)
105
+ k1 = 0
106
+ end
107
+ # while (k1 < l1 - 2) {
108
+ # ai[k1++] = 0;
109
+ # }
110
+ while (k1 < l1 - 2)
111
+ ai[k1] = 0
112
+ k1 += 1
113
+ end
114
+ # int i2 = i1;
115
+ i2 = i1
116
+ # ai[k1++] = i2 >> 29 & 7;
117
+ ai[k1] = i2 >> 29 & 7
118
+ k1 += 1
119
+ # ai[k1] = i2 << 3;
120
+ ai[k1] = (i2 << 3) & 0xffffffff
121
+ # u(ai1, ai);
122
+ u(ai1, ai)
123
+ # return ai1;
124
+ return ai1
125
+ #}
126
+ end
127
+
128
+
129
+ # static String newCheck(String s1, String s2, boolean flag) {
130
+ def new_check(s1, s2, flag)
131
+ # if (s1 == null || s2 == null ||
132
+ # s2.length() >= "ZG_ENCRYPT_FAILED_".length() &&
133
+ # s2.substring(0,
134
+ # "ZG_ENCRYPT_FAILED_".length()).equals("ZG_ENCRYPT_FAILED_")) {
135
+ # return null;
136
+ # }
137
+ if (s1 == nil || s2 == nil ||
138
+ s2.length >= "ZG_ENCRYPT_FAILED_".length &&
139
+ s2[0, "ZG_ENCRYPT_FAILED_".length] == "ZG_ENCRYPT_FAILED_")
140
+ return nil
141
+ end
142
+ # byte abyte0[];
143
+ # try {
144
+ # abyte0 = s1.getBytes("UTF8");
145
+ # }
146
+ # catch (UnsupportedEncodingException _ex) {
147
+ # return null;
148
+ # }
149
+ abyte0 = s1.dup
150
+ # int l2 = abyte0.length;
151
+ l2 = abyte0.length
152
+ # int i3 = s2.length();
153
+ i3 = s2.length
154
+ # int i1 = 1;
155
+ i1 = 1
156
+ # byte byte0 = 2;
157
+ byte0 = 2
158
+ # int j1 = i3 - 2 - i1 * 2;
159
+ j1 = i3 - 2 - i1 * 2
160
+ # if (j1 <= 0) {
161
+ # return null;
162
+ # }
163
+ if (j1 <= 0)
164
+ return nil
165
+ end
166
+ # int k1 = (j1 / 16) * 8;
167
+ k1 = (j1 / 16) * 8
168
+ # if (k1 <= 0) {
169
+ # return null;
170
+ # }
171
+ if (k1 <= 0)
172
+ return nil
173
+ end
174
+ # int l1 = (j1 % 16) / 2;
175
+ l1 = (j1 % 16) / 2
176
+ # int i2 = l1 + i1;
177
+ i2 = l1 + i1
178
+ # int j2 = k1 - 1 - byte0;
179
+ j2 = k1 - 1 - byte0
180
+ # if (j2 <= 0) {
181
+ # return null;
182
+ # }
183
+ if (j2 <= 0)
184
+ return nil
185
+ end
186
+ # if (!s2.substring(0, 2).equals("ZG")) {
187
+ # return null;
188
+ # }
189
+ if (not s2[0, 2] == "ZG")
190
+ return nil
191
+ end
192
+ # String s3 = s2.substring(2);
193
+ s3 = s2[2..-1]
194
+ # byte abyte1[] = p(s3);
195
+ abyte1 = p(s3)
196
+ # byte abyte2[] = new byte[abyte1.length - i2];
197
+ abyte2 = "\0"*(abyte1.length - i2)
198
+ # byte abyte3[] = new byte[i2];
199
+ abyte3 = "\0"*i2
200
+ # System.arraycopy(abyte1, 0, abyte2, 0, abyte1.length - i2);
201
+ abyte2[0, abyte1.length - i2] = abyte1[0, abyte1.length - i2]
202
+ # System.arraycopy(abyte1, abyte1.length - i2, abyte3, 0, i2);
203
+ abyte3[0, i2] = abyte1[abyte1.length - i2, i2]
204
+ # byte abyte4[] = new byte[i2 + l2];
205
+ abyte4 = "\0"*(i2 + l2)
206
+ # System.arraycopy(abyte3, 0, abyte4, 0, i2);
207
+ abyte4[0, i2] = abyte3[0, i2]
208
+ # System.arraycopy(abyte0, 0, abyte4, i2, l2);
209
+ abyte4[i2, l2] = abyte0[0, l2]
210
+ # byte abyte5[] = v(null, abyte4, abyte2);
211
+ # puts "<br/>DEBUG new_check: abyte4=#{abyte4.inspect} abyte2=#{abyte2.unpack("H*")[0]}"
212
+ abyte5 = v(nil, abyte4, abyte2)
213
+ # if (abyte5 == null) {
214
+ # return null;
215
+ # }
216
+ if (abyte5 == nil)
217
+ # puts "<br/>DEBUG new_check: :nil6"
218
+ return nil
219
+ end
220
+ # int j3 = abyte5.length;
221
+ j3 = abyte5.length
222
+ # for (int k2 = byte0; k2 < abyte5.length; k2++) {
223
+ # if (abyte5[k2] != 0) {
224
+ # continue;
225
+ # }
226
+ # j3 = k2;
227
+ # break;
228
+ # }
229
+ for k2 in byte0...abyte5.length
230
+ if (abyte5[k2] != 0)
231
+ next
232
+ end
233
+ j3 = k2
234
+ break
235
+ end
236
+ #
237
+ # byte abyte6[] = new byte[j3 - byte0];
238
+ abyte6 = "\0"*(j3 - byte0)
239
+ # System.arraycopy(abyte5, byte0, abyte6, 0, j3 - byte0);
240
+ abyte6[0, j3 - byte0] = abyte5[byte0, j3 - byte0]
241
+ # String s4;
242
+ # try {
243
+ # s4 = new String(abyte6, "UTF8");
244
+ # }
245
+ # catch (UnsupportedEncodingException _ex) {
246
+ # return null;
247
+ # }
248
+ s4 = abyte6
249
+ # if (s4 != null && flag) {
250
+ # return w(s4, 0, flag);
251
+ # }
252
+ if (s4 != nil && flag)
253
+ return w(s4, 0, flag)
254
+ # else {
255
+ # return s4;
256
+ # }
257
+ else
258
+ return s4
259
+ end
260
+ # }
261
+ end
262
+
263
+ # private static void c(int ai[]) {
264
+ # ai[4] = j(ai[0], 5) + s(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x8f1bbcdc;
265
+ # ai[2] = j(ai[1], 30);
266
+ # }
267
+ def c(ai)
268
+ ai[4] = j(ai[0], 5) + s(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x8f1bbcdc
269
+ ai[2] = j(ai[1], 30)
270
+ end
271
+
272
+ # private static void d(byte abyte0[], int ai[]) {
273
+ # int ai1[] = new int[2];
274
+ # t(abyte0, ai1);
275
+ # F(ai1, ai);
276
+ # x(ai1, abyte0);
277
+ # }
278
+ def d(abyte0, ai)
279
+ ai1 = [nil]*2
280
+ t(abyte0, ai1)
281
+ # puts "<br/>DEBUG d: after t abyte0=#{abyte0.unpack("H*")[0]}"
282
+ # puts "<br/>DEBUG d: after t ai1=#{ai1.join(",")}"
283
+ f_(ai1, ai)
284
+ # puts "<br/>DEBUG d: after F ai1=#{ai1.join(",")}"
285
+ # puts "<br/>DEBUG d: after F ai=#{ai.join(",")}"
286
+ x(ai1, abyte0)
287
+ # puts "<br/>DEBUG d: after x ai1=#{ai1.join(",")}"
288
+ # puts "<br/>DEBUG d: after x abyte0=#{abyte0.unpack("H*")[0]}"
289
+ end
290
+
291
+ # private static byte[] e(int ai[]) {
292
+ # byte abyte0[] = new byte[4];
293
+ # byte abyte1[] = null;
294
+ # if (ai != null) {
295
+ # abyte1 = new byte[ai.length];
296
+ # for (int i1 = 0; i1 < ai.length; i1++) {
297
+ # abyte0[3] = (byte) (ai[i1] & 0xff);
298
+ # abyte0[2] = (byte) ( (ai[i1] & 0xff00) >> 8);
299
+ # abyte0[1] = (byte) ( (ai[i1] & 0xff0000) >> 16);
300
+ # abyte0[0] = (byte) ( (ai[i1] & 0xff000000) >> 24);
301
+ # abyte1[i1] = (byte) (abyte0[0] ^ abyte0[1] ^ abyte0[2] ^ abyte0[3]);
302
+ # }
303
+ #
304
+ # }
305
+ # return abyte1;
306
+ # }
307
+ def e(ai)
308
+ abyte0 = "\0"*4
309
+ abyte1 = nil
310
+ if (ai != nil)
311
+ abyte1 = "\0"*(ai.length)
312
+ for i1 in 0...ai.length
313
+ abyte0[3] = (ai[i1] & 0xff)
314
+ abyte0[2] = ( (ai[i1] & 0xff00) >> 8)
315
+ abyte0[1] = ( (ai[i1] & 0xff0000) >> 16)
316
+ abyte0[0] = ( (ai[i1] & 0xff000000) >> 24)
317
+ abyte1[i1] = (abyte0[0] ^ abyte0[1] ^ abyte0[2] ^ abyte0[3])
318
+ end
319
+ end
320
+ return abyte1
321
+ end
322
+
323
+ # private static byte f(int i1) {
324
+ # byte byte0 = 0;
325
+ # int j1 = (char) i1 & 0x40;
326
+ # if (j1 >= 1) {
327
+ # byte0 = (byte) ( (char) i1 - 55);
328
+ # }
329
+ # else {
330
+ # byte0 = (byte) ( (char) i1 & 0xf);
331
+ # }
332
+ # return byte0;
333
+ # }
334
+ def f(i1)
335
+ byte0 = 0
336
+ j1 = i1 & 0x40
337
+ if (j1 >= 1)
338
+ byte0 = i1 - 55
339
+ else
340
+ byte0 = i1 & 0xf
341
+ end
342
+ return byte0
343
+ end
344
+
345
+ # private static byte[] g(byte abyte0[], byte abyte1[]) {
346
+ def g(abyte0, abyte1)
347
+ # if (abyte0.length < 32) {
348
+ # return null;
349
+ # }
350
+ if (abyte0.length < 32)
351
+ # puts "<br/>DEBUG g: nil1"
352
+ return nil
353
+ end
354
+ # if (abyte1.length % 8 != 0) {
355
+ # return null;
356
+ # }
357
+ if (abyte1.length % 8 != 0)
358
+ # puts "<br/>DEBUG g: nil2"
359
+ return nil
360
+ end
361
+ # int i1 = abyte1.length / 8;
362
+ i1 = abyte1.length / 8
363
+ # byte abyte3[] = new byte[8];
364
+ abyte3 = "\0"*8
365
+ # byte abyte4[] = new byte[8];
366
+ abyte4 = "\0"*8
367
+ # byte abyte5[] = new byte[8];
368
+ abyte5 = "\0"*8
369
+ # byte abyte2[] = new byte[8];
370
+ abyte2 = "\0"*8
371
+ # System.arraycopy(abyte0, 0, abyte3, 0, 8);
372
+ abyte3[0,8] = abyte0[0, 8]
373
+ # System.arraycopy(abyte0, 8, abyte4, 0, 8);
374
+ abyte4[0,8] = abyte0[8, 8]
375
+ # System.arraycopy(abyte0, 16, abyte5, 0, 8);
376
+ abyte5[0,8] = abyte0[16, 8]
377
+ # System.arraycopy(abyte0, 24, abyte2, 0, 8);
378
+ abyte2[0,8] = abyte0[24, 8]
379
+ # int ai[] = l(abyte3, false);
380
+ ai = l(abyte3, false)
381
+ # int ai1[] = l(abyte4, true);
382
+ ai1 = l(abyte4, true)
383
+ # int ai2[] = l(abyte5, false);
384
+ ai2 = l(abyte5, false)
385
+ # byte abyte6[] = new byte[abyte1.length];
386
+ abyte6 = "\0"*(abyte1.length)
387
+ # int j1 = 0;
388
+ j1 = 0
389
+ # for (int k1 = 0; j1 < i1; k1 += 8) {
390
+ k1 = 0
391
+ while (j1 < i1)
392
+ # q(abyte1, k1, abyte6, k1, ai, ai1, ai2, abyte2, false);
393
+ q(abyte1, k1, abyte6, k1, ai, ai1, ai2, abyte2, false)
394
+ # puts "<br/>DEBUG g: after q() abyte6=#{abyte6.unpack("H*")[0]}"
395
+ # j1++;
396
+ j1 += 1
397
+ # }
398
+ k1 += 8
399
+ end
400
+ #
401
+ # byte byte0 = abyte6[abyte1.length - 1];
402
+ byte0 = abyte6[abyte1.length - 1]
403
+ # puts "<br/>DEBUG g: abyte1=#{abyte1.unpack("H*")[0]}"
404
+ # puts "<br/>DEBUG g: abyte1.length=#{abyte1.length}"
405
+ # puts "<br/>DEBUG g: abyte6=#{abyte6.unpack("H*")[0]}"
406
+ # if (byte0 < 1 || byte0 > 8) {
407
+ # return null;
408
+ # }
409
+ if (byte0 < 1 || byte0 > 8)
410
+ # puts "<br/>DEBUG g: nil3"
411
+ # puts "<br/>DEBUG g: byte0=#{byte0}"
412
+ return nil
413
+ end
414
+ # for (int l1 = abyte1.length - byte0; l1 < abyte1.length; l1++) {
415
+ for l1 in (abyte1.length-byte0)...abyte1.length
416
+ # if (abyte6[l1] != byte0) {
417
+ # return null;
418
+ # }
419
+ if (abyte6[l1] != byte0)
420
+ # puts "<br/>DEBUG g: nil4"
421
+ return nil
422
+ end
423
+ # }
424
+ end
425
+ #
426
+ # byte abyte7[] = new byte[abyte1.length - byte0];
427
+ abyte7 = "\0"*(abyte1.length - byte0)
428
+ # System.arraycopy(abyte6, 0, abyte7, 0, abyte1.length - byte0);
429
+ abyte7[0, abyte1.length - byte0] = abyte6[0, abyte1.length - byte0]
430
+ # return abyte7;
431
+ # puts "<br/>DEBUG g: abyte7=#{abyte7.unpack("H*")[0]}"
432
+ return abyte7
433
+ # }
434
+ end
435
+
436
+ # private static void h(int ai[]) {
437
+ # ai[4] = j(ai[0], 5) + o(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0xca62c1d6;
438
+ # ai[2] = j(ai[1], 30);
439
+ # }
440
+ def h(ai)
441
+ ai[4] = j(ai[0], 5) + o(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0xca62c1d6
442
+ ai[2] = j(ai[1], 30)
443
+ end
444
+
445
+ # private static byte[] i(byte abyte0[], byte abyte1[], byte abyte2[]) {
446
+ # return G(y(abyte0, abyte1), abyte2);
447
+ # }
448
+ def i(abyte0, abyte1, abyte2)
449
+ return g_(y(abyte0, abyte1), abyte2)
450
+ end
451
+
452
+ # private static int j(int i1, int j1) {
453
+ # return i1 << j1 | i1 >>> 32 - j1;
454
+ # }
455
+ # TODO: check impact of >>> substitution with >>
456
+ def j(i1, j1)
457
+ return (i1 << j1 | i1 >> 32 - j1) & 0xffffffff
458
+ end
459
+
460
+ # private static byte[] k(byte abyte0[], byte abyte1[], int i1) {
461
+ def k(abyte0, abyte1, i1)
462
+ # if (abyte0 == null || abyte1 == null) {
463
+ # return null;
464
+ # }
465
+ if (abyte0 == nil || abyte1 == nil)
466
+ return nil
467
+ # else {
468
+ # int ai[] = a(abyte0, abyte0.length);
469
+ # byte abyte2[] = e(ai);
470
+ # byte abyte3[] = new byte[258];
471
+ # B(abyte3, abyte2, null, 5);
472
+ # byte abyte4[] = new byte[i1];
473
+ # B(abyte3, abyte1, abyte4, i1);
474
+ # return abyte4;
475
+ # }
476
+ else
477
+ ai = a(abyte0, abyte0.length)
478
+ abyte2 = e(ai)
479
+ abyte3 = "\0"*258
480
+ b_(abyte3, abyte2, nil, 5)
481
+ abyte4 = "\0"*i1
482
+ b_(abyte3, abyte1, abyte4, i1)
483
+ return abyte4
484
+ end
485
+ # }
486
+ end
487
+
488
+ # private static int[] l(byte abyte0[], boolean flag) {
489
+ def l(abyte0, flag)
490
+ # byte abyte1[] = new byte[56];
491
+ abyte1 = "\0"*56
492
+ # byte abyte2[] = new byte[56];
493
+ abyte2 = "\0"*56
494
+ # int ai[] = new int[32];
495
+ ai = [nil]*32
496
+ # for (int j1 = 0; j1 < 56; j1++) {
497
+ # byte byte0 = V[j1];
498
+ # int l2 = byte0 & 7;
499
+ # abyte1[j1] = (byte) ( (abyte0[byte0 >>> 3] & bi[l2]) == 0 ? 0 : 1);
500
+ # }
501
+ # TODO: check impact of >>> substitution with >>
502
+ for j1 in 0...56
503
+ byte0 = V[j1]
504
+ l2 = byte0 & 7
505
+ abyte1[j1] = ( (abyte0[byte0 >> 3] & Bi[l2]) == 0 ? 0 : 1)
506
+ end
507
+ #
508
+ # for (int i1 = 0; i1 < 16; i1++) {
509
+ for i1 in 0...16
510
+ # int i3;
511
+ # if (flag) {
512
+ # i3 = i1 << 1;
513
+ # }
514
+ if (flag)
515
+ i3 = i1 << 1
516
+ # else {
517
+ # i3 = 15 - i1 << 1;
518
+ # }
519
+ else
520
+ i3 = 15 - i1 << 1
521
+ end
522
+ # int j3 = i3 + 1;
523
+ j3 = i3 + 1
524
+ # ai[i3] = ai[j3] = 0;
525
+ ai[i3] = ai[j3] = 0
526
+ # for (int k1 = 0; k1 < 28; k1++) {
527
+ for k1 in 0...28
528
+ # int j2 = k1 + bb[i1];
529
+ j2 = k1 + Bb[i1]
530
+ # if (j2 < 28) {
531
+ # abyte2[k1] = abyte1[j2];
532
+ # }
533
+ if (j2 < 28)
534
+ abyte2[k1] = abyte1[j2]
535
+ # else {
536
+ # abyte2[k1] = abyte1[j2 - 28];
537
+ # }
538
+ else
539
+ abyte2[k1] = abyte1[j2 - 28]
540
+ end
541
+ # }
542
+ end
543
+ #
544
+ # for (int l1 = 28; l1 < 56; l1++) {
545
+ for l1 in 28...56
546
+ # int k2 = l1 + bb[i1];
547
+ k2 = l1 + Bb[i1]
548
+ # if (k2 < 56) {
549
+ # abyte2[l1] = abyte1[k2];
550
+ # }
551
+ if (k2 < 56)
552
+ abyte2[l1] = abyte1[k2]
553
+ # else {
554
+ # abyte2[l1] = abyte1[k2 - 28];
555
+ # }
556
+ else
557
+ abyte2[l1] = abyte1[k2 - 28]
558
+ end
559
+ # }
560
+ end
561
+ #
562
+ # for (int i2 = 0; i2 < 24; i2++) {
563
+ for i2 in 0...24
564
+ # if (abyte2[S[i2]] != 0) {
565
+ # ai[i3] |= W[i2];
566
+ # }
567
+ if (abyte2[S[i2]] != 0)
568
+ ai[i3] |= W[i2]
569
+ end
570
+ # if (abyte2[S[i2 + 24]] != 0) {
571
+ # ai[j3] |= W[i2];
572
+ # }
573
+ if (abyte2[S[i2 + 24]] != 0)
574
+ ai[j3] |= W[i2]
575
+ end
576
+ # }
577
+ end
578
+ #
579
+ # }
580
+ end
581
+ #
582
+ # return C(ai);
583
+ return c_(ai)
584
+ # }
585
+ end
586
+
587
+ # static String oldControl(String s1, String s2, int i1) {
588
+ def old_control(s1, s2, i1)
589
+ # if (s1 == null || s2 == null) {
590
+ # return null;
591
+ # }
592
+ if (s1 == nil || s2 == nil)
593
+ return nil
594
+ end
595
+ # byte abyte0[] = A(s1.toCharArray());
596
+ abyte0 = a_(s1.dup)
597
+ # int j1 = s2.length();
598
+ #j1 = s2.mb_chars.length
599
+ j1 = s2.length
600
+
601
+ # if (j1 > i1 - 1) {
602
+ # j1 = i1 - 1;
603
+ # }
604
+ if (j1 > i1 - 1)
605
+ j1 = i1 - 1
606
+ end
607
+ # Random random = new Random();
608
+ # RSI: no need to create object here
609
+ # int k1 = i1 - j1 - 1;
610
+ k1 = i1 - j1 - 1
611
+ # int ai[] = new int[k1];
612
+ ai = [nil]*k1
613
+ # for (int l1 = 0; l1 < k1; l1++) {
614
+ # ai[l1] = random.nextInt();
615
+ #
616
+ # }
617
+ # TODO: substitute Java random.nextInt() with ruby
618
+ for l1 in 0..k1
619
+ # simulation of random.nextInt()
620
+ ai[l1] = rand(2**32)-2**31
621
+ end
622
+ # byte abyte1[] = e(ai);
623
+ abyte1 = e(ai)
624
+ # byte abyte2[] = A( (new String(s2 + '\0')).toCharArray());
625
+ abyte2 = a_( (s2 + "\0") )
626
+ # byte abyte3[] = new byte[k1 + abyte2.length];
627
+ abyte3 = "\0"*(k1 + abyte2.length)
628
+ # System.arraycopy(abyte2, 0, abyte3, 0, abyte2.length);
629
+ abyte3[0, abyte2.length] = abyte2[0, abyte2.length]
630
+ # System.arraycopy(abyte1, 0, abyte3, abyte2.length, k1);
631
+ abyte3[abyte2.length, k1] = abyte1[0, k1]
632
+ # byte abyte4[] = k(abyte0, abyte3, i1);
633
+ abyte4 = k(abyte0, abyte3, i1)
634
+ # return z(abyte4);
635
+ return z(abyte4)
636
+ # }
637
+ end
638
+
639
+ # private static char[] m(byte abyte0[]) {
640
+ def m(abyte0)
641
+ # char ac1[];
642
+ # label0: {
643
+ while true
644
+ # if (abyte0 == null) {
645
+ # return null;
646
+ # }
647
+ if (abyte0 == nil)
648
+ return nil
649
+ end
650
+ # char ac[] = new char[abyte0.length];
651
+ ac = "\0"*(abyte0.length)
652
+ # int i1 = 0;
653
+ i1 = 0
654
+ # boolean flag = false;
655
+ flag = false
656
+ # boolean flag1 = false;
657
+ flag1 = false
658
+ # ac1 = null;
659
+ ac1 = nil
660
+ # try {
661
+ begin
662
+ # for (int j1 = 0; j1 < abyte0.length; j1++) {
663
+ break_value = for j1 in 0...abyte0.length do
664
+ # byte byte0 = abyte0[j1];
665
+ byte0 = abyte0[j1]
666
+ # if ( (byte0 & 0x80) == 0) {
667
+ # ac[i1++] = (char) byte0;
668
+ # if ( (char) byte0 == 0) {
669
+ # break;
670
+ # }
671
+ # continue;
672
+ # }
673
+ if ( (byte0 & 0x80) == 0)
674
+ ac[i1] = byte0
675
+ i1 += 1
676
+ if ( byte0 == 0)
677
+ break
678
+ end
679
+ next
680
+ end
681
+ # if ( (byte0 & 0xe0) == 192) {
682
+ # char c1 = (char) ( (byte0 & 0x1f) << 6 & 0x7c0);
683
+ # byte0 = abyte0[++j1];
684
+ # if ( (byte0 & 0x80) == 128) {
685
+ # c1 |= byte0 & 0x3f;
686
+ # ac[i1++] = c1;
687
+ # continue;
688
+ # }
689
+ # break label0;
690
+ # }
691
+ if ( (byte0 & 0xe0) == 192)
692
+ c1 = ( (byte0 & 0x1f) << 6 & 0x7c0)
693
+ j1 += 1
694
+ byte0 = abyte0[j1]
695
+ if ( (byte0 & 0x80) == 128)
696
+ c1 |= byte0 & 0x3f
697
+ ac[i1] = c1
698
+ i1 += 1
699
+ next
700
+ end
701
+ break :label0
702
+ end
703
+ # if ( (byte0 & 0xf0) != 224) {
704
+ # continue;
705
+ # }
706
+ if ( (byte0 & 0xf0) != 224)
707
+ continue
708
+ end
709
+ # char c2 = (char) ( (byte0 & 0xf) << 12 & 0xf000);
710
+ c2 = ( (byte0 & 0xf) << 12 & 0xf000)
711
+ # byte0 = abyte0[++j1];
712
+ j1 += 1
713
+ byte0 = abyte0[j1]
714
+ # if ( (byte0 & 0x80) != 128) {
715
+ # break label0;
716
+ # }
717
+ if ( (byte0 & 0x80) != 128)
718
+ break :label0
719
+ end
720
+ # c2 |= (byte0 & 0x3f) << 6 & 0xfc0;
721
+ c2 |= (byte0 & 0x3f) << 6 & 0xfc0
722
+ # byte0 = abyte0[++j1];
723
+ j1 += 1
724
+ byte0 = abyte0[j1]
725
+ # if ( (byte0 & 0x80) != 128) {
726
+ # break label0;
727
+ # }
728
+ if ( (byte0 & 0x80) != 128)
729
+ break :label0
730
+ end
731
+ # c2 |= byte0 & 0x3f;
732
+ c2 |= byte0 & 0x3f
733
+ # ac[i1++] = c2;
734
+ ac[i1] = c2
735
+ i1 += 1
736
+ # }
737
+ end
738
+ # RSI: jump back to label0 if brake was called with :label0
739
+ if break_value == :label0
740
+ next
741
+ end
742
+ #
743
+ # ac1 = new char[i1];
744
+ ac1 = "\0"*i1
745
+ # System.arraycopy(ac, 0, ac1, 0, i1);
746
+ ac1[0,i1] = ac[0,i1]
747
+ # }
748
+ # catch (ArrayIndexOutOfBoundsException _ex) {
749
+ # ac1 = null;
750
+ # }
751
+ end
752
+ # TODO: when this exception could happen?
753
+ # }
754
+ # return ac1;
755
+ # }
756
+ # RSI: if we are here then we should return value and escape endless loop
757
+ return ac1
758
+ end
759
+ end
760
+
761
+
762
+ # private static int n(int i1, int j1, int k1) {
763
+ # return i1 ^ j1 ^ k1;
764
+ # }
765
+ def n(i1, j1, k1)
766
+ return i1 ^ j1 ^ k1
767
+ end
768
+
769
+ # private static int o(int i1, int j1, int k1) {
770
+ # return i1 ^ j1 ^ k1;
771
+ # }
772
+ def o(i1, j1, k1)
773
+ return i1 ^ j1 ^ k1
774
+ end
775
+
776
+ # static String control(String s1, String s2, int i1) {
777
+ # return newControl(s1, s2, 0, i1);
778
+ # }
779
+ def control(s1, s2, i1)
780
+ return new_control(s1, s2, 0, i1)
781
+ end
782
+
783
+ # private static byte[] p(String s1) {
784
+ def p(s1)
785
+ # boolean flag = false;
786
+ flag = false
787
+ # boolean flag1 = false;
788
+ flag1 = false
789
+ # int i1 = 0;
790
+ i1 = 0
791
+ # int j1 = 0;
792
+ j1 = 0
793
+ # byte abyte0[] = null;
794
+ abyte0 = nil
795
+ # if (s1 == null) {
796
+ # return null;
797
+ # }
798
+ if (s1 == nil)
799
+ return nil
800
+ end
801
+ # int k1 = s1.length() / 2;
802
+ k1 = s1.length / 2
803
+ # if (k1 > 0) {
804
+ if (k1 > 0)
805
+ # abyte0 = new byte[k1];
806
+ abyte0 = "\0"*k1
807
+ # for (; k1 > 0; k1--) {
808
+ while (k1 > 0)
809
+ # char c1 = s1.charAt(i1++);
810
+ #c1 = s1.chars[i1]
811
+ c1 = s1[i1]
812
+ i1 += 1
813
+ # char c2 = s1.charAt(i1++);
814
+ #c2 = s1.chars[i1]
815
+ c2 = s1[i1]
816
+ i1 += 1
817
+ # abyte0[j1++] = (byte) (f(c1) << 4 | f(c2));
818
+ abyte0[j1] = (f(c1) << 4 | f(c2)) & 0xffffffff
819
+ j1 += 1
820
+ # }
821
+ k1 -= 1
822
+ end
823
+ #
824
+ # }
825
+ end
826
+ # return abyte0;
827
+ return abyte0
828
+ # }
829
+ end
830
+
831
+ # private static void q(byte abyte0[], int i1, byte abyte1[], int j1, int ai[],
832
+ # int ai1[], int ai2[], byte abyte2[],
833
+ # boolean flag) {
834
+ def q(abyte0, i1, abyte1, j1, ai,
835
+ ai1, ai2, abyte2,
836
+ flag)
837
+ # byte abyte3[] = new byte[8];
838
+ abyte3 = "\0"*8
839
+ # System.arraycopy(abyte0, i1, abyte3, 0, 8);
840
+ abyte3[0, 8] = abyte0[i1, 8]
841
+ # if (!flag) {
842
+ # d(abyte3, ai2);
843
+ # d(abyte3, ai1);
844
+ # d(abyte3, ai);
845
+ # D(abyte3, abyte2, abyte1, j1);
846
+ # System.arraycopy(abyte0, i1, abyte2, 0, 8);
847
+ # return;
848
+ # }
849
+ if (!flag)
850
+ # puts "<br/>DEBUG q: initial abyte3=#{abyte3.unpack("H*")[0]}"
851
+ # puts "<br/>DEBUG q: initial ai2=#{ai2.join(',')}"
852
+ # puts "<br/>DEBUG q: initial ai1=#{ai1.join(',')}"
853
+ # puts "<br/>DEBUG q: initial ai=#{ai.join(',')}"
854
+ d(abyte3, ai2)
855
+ # puts "<br/>DEBUG q: abyte3=#{abyte3.unpack("H*")[0]}"
856
+ d(abyte3, ai1)
857
+ # puts "<br/>DEBUG q: abyte3=#{abyte3.unpack("H*")[0]}"
858
+ d(abyte3, ai)
859
+ # puts "<br/>DEBUG q: abyte3=#{abyte3.unpack("H*")[0]}"
860
+ d_(abyte3, abyte2, abyte1, j1)
861
+ # puts "<br/>DEBUG q: abyte3=#{abyte3.unpack("H*")[0]}"
862
+ # puts "<br/>DEBUG q: abyte2=#{abyte2.unpack("H*")[0]}"
863
+ # puts "<br/>DEBUG q: abyte1=#{abyte1.unpack("H*")[0]}"
864
+ abyte2[0, 8] = abyte0[i1, 8]
865
+ return
866
+ # else {
867
+ # D(abyte3, abyte2, abyte3, 0);
868
+ # d(abyte3, ai);
869
+ # d(abyte3, ai1);
870
+ # d(abyte3, ai2);
871
+ # System.arraycopy(abyte3, 0, abyte2, 0, 8);
872
+ # System.arraycopy(abyte3, 0, abyte1, j1, 8);
873
+ # return;
874
+ # }
875
+ else
876
+ d_(abyte3, abyte2, abyte3, 0);
877
+ d(abyte3, ai);
878
+ d(abyte3, ai1);
879
+ d(abyte3, ai2);
880
+ abyte2[0, 8] = abyte3[0, 8]
881
+ abyte1[j1, 8] = abyte3[0, 8]
882
+ return
883
+ end
884
+ # }
885
+ end
886
+
887
+ # private static int r(int i1, int j1, int k1) {
888
+ # return i1 & j1 | ~i1 & k1;
889
+ # }
890
+ def r(i1, j1, k1)
891
+ return i1 & j1 | ~i1 & k1
892
+ end
893
+
894
+ # private static int s(int i1, int j1, int k1) {
895
+ # return i1 & j1 | i1 & k1 | j1 & k1;
896
+ # }
897
+ def s(i1, j1, k1)
898
+ return i1 & j1 | i1 & k1 | j1 & k1
899
+ end
900
+
901
+ # static String hash(String s1) {
902
+ def hash(s1)
903
+ # if (s1 == null) {
904
+ # return null;
905
+ # }
906
+ if (s1 == nil)
907
+ return nil
908
+ end
909
+ # byte abyte0[];
910
+ # try {
911
+ # abyte0 = s1.getBytes("UTF8");
912
+ # }
913
+ # catch (UnsupportedEncodingException _ex) {
914
+ # return null;
915
+ # }
916
+ abyte0 = s1.dup
917
+ # byte abyte1[] = y(null, abyte0);
918
+ abyte1 = y(nil, abyte0)
919
+ # return z(abyte1);
920
+ return z(abyte1)
921
+ # }
922
+ end
923
+
924
+ # static String newControl(String s1, String s2, int i1, int j1) {
925
+ def new_control(s1, s2, i1, j1)
926
+ # if (s1 == null || s2 == null) {
927
+ # return "ZG_ENCRYPT_FAILED_BADINPUT";
928
+ # }
929
+ if (s1 == nil || s2 == nil)
930
+ return "ZG_ENCRYPT_FAILED_BADINPUT"
931
+ end
932
+ # int k1;
933
+ # if (i1 > 0) {
934
+ # k1 = i1;
935
+ # }
936
+ if (i1 > 0)
937
+ k1 = i1
938
+ # else
939
+ # if (j1 == 32) {
940
+ # k1 = 100;
941
+ # }
942
+ elsif (j1 == 32)
943
+ k1 = 100
944
+ # else
945
+ # if (j1 < 32 && j1 == s2.length()) {
946
+ # k1 = 100;
947
+ # }
948
+ elsif (j1 < 32 && j1 == s2.length())
949
+ k1 = 100
950
+ # else {
951
+ # byte abyte1[];
952
+ # try {
953
+ # abyte1 = s2.getBytes("UTF8");
954
+ # }
955
+ # catch (UnsupportedEncodingException _ex) {
956
+ # return "ZG_ENCRYPT_FAILED_MISC";
957
+ # }
958
+ # k1 = ( (abyte1.length + 10) / 8) * 16 + 4 + 14;
959
+ # }
960
+ else
961
+ abyte1 = s2.dup
962
+ k1 = ( (abyte1.length + 10) / 8) * 16 + 4 + 14
963
+ end
964
+ # int l1 = 1;
965
+ l1 = 1
966
+ # byte byte0 = 2;
967
+ byte0 = 2
968
+ # int i2 = k1 - 2 - l1 * 2;
969
+ i2 = k1 - 2 - l1 * 2
970
+ # if (i2 <= 0) {
971
+ # return "ZG_ENCRYPT_FAILED_SMALLBUF";
972
+ # }
973
+ if (i2 <= 0)
974
+ return "ZG_ENCRYPT_FAILED_SMALLBUF"
975
+ end
976
+ # int j2 = (i2 / 16) * 8;
977
+ j2 = (i2 / 16) * 8
978
+ # if (j2 <= 0) {
979
+ # return "ZG_ENCRYPT_FAILED_SMALLBUF";
980
+ # }
981
+ if (j2 <= 0)
982
+ return "ZG_ENCRYPT_FAILED_SMALLBUF"
983
+ end
984
+ # int k2 = (i2 % 16) / 2;
985
+ k2 = (i2 % 16) / 2
986
+ # int l2 = k2 + l1;
987
+ l2 = k2 + l1
988
+ # int i3 = j2 - 1 - byte0;
989
+ i3 = j2 - 1 - byte0
990
+ # if (i3 <= 0) {
991
+ # return "ZG_ENCRYPT_FAILED_SMALLBUF";
992
+ # }
993
+ if (i3 <= 0)
994
+ return "ZG_ENCRYPT_FAILED_SMALLBUF"
995
+ end
996
+ # byte abyte0[];
997
+ # byte abyte2[];
998
+ # try {
999
+ # abyte0 = s1.getBytes("UTF8");
1000
+ # abyte2 = s2.getBytes("UTF8");
1001
+ # }
1002
+ # catch (UnsupportedEncodingException _ex) {
1003
+ # return "ZG_ENCRYPT_FAILED_MISC";
1004
+ # }
1005
+ abyte0 = s1.dup
1006
+ abyte2 = s2.dup
1007
+ # int j3 = abyte0.length;
1008
+ j3 = abyte0.length
1009
+ # int k3 = abyte2.length;
1010
+ k3 = abyte2.length
1011
+ # if (k3 > i3) {
1012
+ # return "ZG_ENCRYPT_FAILED_CHARSET_CLIP";
1013
+ # }
1014
+ if (k3 > i3)
1015
+ return "ZG_ENCRYPT_FAILED_CHARSET_CLIP"
1016
+ end
1017
+ # Random random = new Random();
1018
+ # int ai[] = new int[l2];
1019
+ ai = [nil]*l2
1020
+ # for (int l3 = 0; l3 < l2; l3++) {
1021
+ # ai[l3] = random.nextInt();
1022
+ #
1023
+ # }
1024
+ for l3 in 0...l2
1025
+ ai[l3] = rand(2**32)-2**31
1026
+ end
1027
+ # byte abyte3[] = e(ai);
1028
+ abyte3 = e(ai)
1029
+ # ai = null;
1030
+ ai = nil
1031
+ # byte byte1 = byte0;
1032
+ byte1 = byte0
1033
+ # ai = new int[byte1];
1034
+ ai = [nil]*byte1
1035
+ # for (int i4 = 0; i4 < byte1; i4++) {
1036
+ # ai[i4] = random.nextInt();
1037
+ #
1038
+ # }
1039
+ for i4 in 0...byte1
1040
+ ai[i4] = rand(2**32)-2**31
1041
+ end
1042
+ # byte abyte4[] = e(ai);
1043
+ abyte4 = e(ai)
1044
+ # ai = null;
1045
+ ai = nil
1046
+ # int j4 = i3 - k3;
1047
+ j4 = i3 - k3
1048
+ # ai = new int[j4];
1049
+ ai = [nil]*j4
1050
+ # for (int k4 = 0; k4 < j4; k4++) {
1051
+ for k4 in 0...j4
1052
+ # if (k4 == 0) {
1053
+ # ai[k4] = 0;
1054
+ # }
1055
+ if (k4 == 0)
1056
+ ai[k4] = 0
1057
+ # else {
1058
+ # ai[k4] = random.nextInt();
1059
+ #
1060
+ # }
1061
+ else
1062
+ ai[k4] = rand(2**32)-2**31
1063
+ end
1064
+ # }
1065
+ end
1066
+ # byte abyte5[] = e(ai);
1067
+ abyte5 = e(ai)
1068
+ # ai = null;
1069
+ ai = nil
1070
+ # byte abyte6[] = new byte[byte1 + j4 + k3];
1071
+ abyte6 = "\0"*(byte1 + j4 + k3)
1072
+ # System.arraycopy(abyte4, 0, abyte6, 0, byte1);
1073
+ abyte6[0, byte1] = abyte4[0, byte1]
1074
+ # System.arraycopy(abyte2, 0, abyte6, byte1, k3);
1075
+ abyte6[byte1, k3] = abyte2[0, k3]
1076
+ # System.arraycopy(abyte5, 0, abyte6, byte1 + k3, j4);
1077
+ abyte6[byte1+k3, j4] = abyte5[0, j4]
1078
+ # byte abyte7[] = new byte[l2 + j3];
1079
+ abyte7 = "\0"*(l2 + j3)
1080
+ # System.arraycopy(abyte3, 0, abyte7, 0, l2);
1081
+ abyte7[0, l2] = abyte3[0, l2]
1082
+ # System.arraycopy(abyte0, 0, abyte7, l2, j3);
1083
+ abyte7[l2, j3] = abyte0[0, j3]
1084
+ # byte abyte8[] = i(null, abyte7, abyte6);
1085
+ abyte8 = i(nil, abyte7, abyte6)
1086
+ # if (abyte8 == null) {
1087
+ # return "ZG_ENCRYPT_FAILED_MISC";
1088
+ # }
1089
+ if (abyte8 == nil)
1090
+ return "ZG_ENCRYPT_FAILED_MISC"
1091
+ # else {
1092
+ # byte abyte9[] = new byte[abyte8.length + l2];
1093
+ # System.arraycopy(abyte8, 0, abyte9, 0, abyte8.length);
1094
+ # System.arraycopy(abyte3, 0, abyte9, abyte8.length, l2);
1095
+ # String s3 = z(abyte9);
1096
+ # return "ZG" + s3;
1097
+ # }
1098
+ else
1099
+ abyte9 = "\0"*(abyte8.length + l2)
1100
+ abyte9[0, abyte8.length] = abyte8[0, abyte8.length]
1101
+ abyte9[abyte8.length, l2] = abyte3[0, l2]
1102
+ s3 = z(abyte9)
1103
+ return "ZG" + s3
1104
+ end
1105
+ # }
1106
+ end
1107
+
1108
+ # private static void t(byte abyte0[], int ai[]) {
1109
+ def t(abyte0, ai)
1110
+ # int i1 = 0;
1111
+ i1 = 0
1112
+ # ai[0] = (abyte0[i1] & 0xff) << 24;
1113
+ ai[0] = ((abyte0[i1] & 0xff) << 24) & 0xffffffff
1114
+ # i1++;
1115
+ i1 += 1
1116
+ # ai[0] |= (abyte0[i1] & 0xff) << 16;
1117
+ ai[0] |= ((abyte0[i1] & 0xff) << 16) & 0xffffffff
1118
+ # i1++;
1119
+ i1 += 1
1120
+ # ai[0] |= (abyte0[i1] & 0xff) << 8;
1121
+ ai[0] |= ((abyte0[i1] & 0xff) << 8) & 0xffffffff
1122
+ # i1++;
1123
+ i1 += 1
1124
+ # ai[0] |= abyte0[i1] & 0xff;
1125
+ ai[0] |= abyte0[i1] & 0xff
1126
+ # i1++;
1127
+ i1 += 1
1128
+ # ai[1] = (abyte0[i1] & 0xff) << 24;
1129
+ ai[1] = ((abyte0[i1] & 0xff) << 24) & 0xffffffff
1130
+ # i1++;
1131
+ i1 += 1
1132
+ # ai[1] |= (abyte0[i1] & 0xff) << 16;
1133
+ ai[1] |= ((abyte0[i1] & 0xff) << 16) & 0xffffffff
1134
+ # i1++;
1135
+ i1 += 1
1136
+ # ai[1] |= (abyte0[i1] & 0xff) << 8;
1137
+ ai[1] |= ((abyte0[i1] & 0xff) << 8) & 0xffffffff
1138
+ # i1++;
1139
+ i1 += 1
1140
+ # ai[1] |= abyte0[i1] & 0xff;
1141
+ ai[1] |= abyte0[i1] & 0xff
1142
+ # }
1143
+ end
1144
+
1145
+ # private static int u(int ai[], int ai1[]) {
1146
+ def u(ai, ai1)
1147
+ # boolean flag = false;
1148
+ flag = false
1149
+ # boolean flag1 = false;
1150
+ flag1 = false
1151
+ # int ai2[] = new int[80];
1152
+ ai2 = [nil]*80
1153
+ # int l1 = 0;
1154
+ l1 = 0
1155
+ # int ai3[] = new int[5];
1156
+ ai3 = [nil]*5
1157
+ # int ai4[] = new int[6];
1158
+ ai4 = [nil]*6
1159
+ # int ai5[] = new int[5];
1160
+ ai5 = [nil]*5
1161
+ # ai3[0] = 0x67452301;
1162
+ # ai3[1] = 0xefcdab89;
1163
+ # ai3[2] = 0x98badcfe;
1164
+ # ai3[3] = 0x10325476;
1165
+ # ai3[4] = 0xc3d2e1f0;
1166
+ ai3[0] = 0x67452301
1167
+ ai3[1] = 0xefcdab89
1168
+ ai3[2] = 0x98badcfe
1169
+ ai3[3] = 0x10325476
1170
+ ai3[4] = 0xc3d2e1f0
1171
+ # if (ai1 != null) {
1172
+ if (ai1 != nil)
1173
+ # if (ai != null) {
1174
+ # System.arraycopy(ai, 0, ai4, 0, 5);
1175
+ # }
1176
+ if (ai != nil)
1177
+ ai4[0, 5] = ai[0, 5]
1178
+ end
1179
+ # byte byte0 = 80;
1180
+ byte0 = 80
1181
+ # int i1;
1182
+ # for (i1 = 0; i1 < 16; i1++) {
1183
+ # ai2[i1] = ai1[i1];
1184
+ #
1185
+ # }
1186
+ for i1 in 0...16
1187
+ ai2[i1] = ai1[i1]
1188
+ end
1189
+ # for (; i1 < byte0; i1++) {
1190
+ # ai2[i1] = ai2[i1 - 3] ^ ai2[i1 - 8] ^ ai2[i1 - 14] ^ ai2[i1 - 16];
1191
+ #
1192
+ # }
1193
+ while (i1 < byte0)
1194
+ ai2[i1] = ai2[i1 - 3] ^ ai2[i1 - 8] ^ ai2[i1 - 14] ^ ai2[i1 - 16]
1195
+ i1 += 1
1196
+ end
1197
+ # for (int j1 = 0; j1 < 80; j1++) {
1198
+ for j1 in 0...80
1199
+ # if (j1 != 0) {
1200
+ # System.arraycopy(ai4, 0, ai5, 0, 5);
1201
+ # ai4[0] = ai5[4];
1202
+ # ai4[1] = ai5[0];
1203
+ # ai4[2] = ai5[1];
1204
+ # ai4[3] = ai5[2];
1205
+ # ai4[4] = ai5[3];
1206
+ # }
1207
+ if (j1 != 0)
1208
+ ai5[0, 5] = ai4[0, 5]
1209
+ ai4[0] = ai5[4];
1210
+ ai4[1] = ai5[0];
1211
+ ai4[2] = ai5[1];
1212
+ ai4[3] = ai5[2];
1213
+ ai4[4] = ai5[3];
1214
+ end
1215
+ # ai4[5] = ai2[j1];
1216
+ ai4[5] = ai2[j1]
1217
+ # if (j1 < 20) {
1218
+ # H(ai4);
1219
+ # }
1220
+ if (j1 < 20)
1221
+ h_(ai4)
1222
+ # else
1223
+ # if (j1 < 40) {
1224
+ # I(ai4);
1225
+ # }
1226
+ elsif (j1 < 40)
1227
+ i_(ai4)
1228
+ # else
1229
+ # if (j1 < 60) {
1230
+ # c(ai4);
1231
+ # }
1232
+ elsif (j1 < 60)
1233
+ c(ai4)
1234
+ # else
1235
+ # if (j1 < 80) {
1236
+ # h(ai4);
1237
+ # }
1238
+ elsif (j1 < 80)
1239
+ h(ai4)
1240
+ end
1241
+ # }
1242
+ end
1243
+ #
1244
+ # ai3[0] = ai4[4];
1245
+ # ai3[1] = ai4[0];
1246
+ # ai3[2] = ai4[1];
1247
+ # ai3[3] = ai4[2];
1248
+ # ai3[4] = ai4[3];
1249
+ ai3[0] = ai4[4];
1250
+ ai3[1] = ai4[0];
1251
+ ai3[2] = ai4[1];
1252
+ ai3[3] = ai4[2];
1253
+ ai3[4] = ai4[3];
1254
+ # for (int k1 = 0; k1 < byte0; k1++) {
1255
+ # ai2[k1] = 0;
1256
+ #
1257
+ # }
1258
+ for k1 in 0...byte0
1259
+ ai2[k1] = 0
1260
+ end
1261
+ # }
1262
+ end
1263
+ # if (ai != null) {
1264
+ # ai[0] = ai3[0];
1265
+ # ai[1] = ai3[1];
1266
+ # ai[2] = ai3[2];
1267
+ # ai[3] = ai3[3];
1268
+ # ai[4] = ai3[4];
1269
+ # }
1270
+ if (ai != nil)
1271
+ ai[0] = ai3[0];
1272
+ ai[1] = ai3[1];
1273
+ ai[2] = ai3[2];
1274
+ ai[3] = ai3[3];
1275
+ ai[4] = ai3[4];
1276
+ end
1277
+ # l1 = ai3[0] ^ ai3[1] ^ ai3[2] ^ ai3[3] ^ ai3[4];
1278
+ l1 = ai3[0] ^ ai3[1] ^ ai3[2] ^ ai3[3] ^ ai3[4]
1279
+ # return l1;
1280
+ return l1
1281
+ # }
1282
+ end
1283
+
1284
+ # private static byte[] v(byte abyte0[], byte abyte1[], byte abyte2[]) {
1285
+ # return g(y(abyte0, abyte1), abyte2);
1286
+ # }
1287
+ def v(abyte0, abyte1, abyte2)
1288
+ return g(y(abyte0, abyte1), abyte2)
1289
+ end
1290
+
1291
+ # private static String w(String s1, int i1, boolean flag) {
1292
+ def w(s1, i1, flag)
1293
+ # if (s1 == null) {
1294
+ # return "";
1295
+ # }
1296
+ if (s1 == nil)
1297
+ return ""
1298
+ end
1299
+ # int j1 = s1.length();
1300
+ # TODO: should String be converted to Ruby Unicode chars string?
1301
+ j1 = s1.length
1302
+ # int k1 = s1.indexOf('\0');
1303
+ k1 = s1.index("\0")
1304
+ # if (k1 > -1) {
1305
+ # j1 = k1;
1306
+ # }
1307
+ if (k1 > -1)
1308
+ j1 = k1
1309
+ end
1310
+ # int l1;
1311
+ # if (j1 > i1 && i1 > 0) {
1312
+ # l1 = i1;
1313
+ # }
1314
+ if (j1 > i1 && i1 > 0)
1315
+ l1 = i1
1316
+ # else {
1317
+ # l1 = j1;
1318
+ # }
1319
+ else
1320
+ l1 = j1
1321
+ end
1322
+ # if (flag) {
1323
+ # return new String(s1.substring(0, l1).toUpperCase(Locale.US));
1324
+ # }
1325
+ if (flag)
1326
+ # TODO: should we do Unicode upcase?
1327
+ return s1[0, l1].upcase
1328
+ # else {
1329
+ # return new String(s1.substring(0, l1));
1330
+ # }
1331
+ else
1332
+ return s1[0, l1]
1333
+ end
1334
+ # }
1335
+ end
1336
+
1337
+ # private static void x(int ai[], byte abyte0[]) {
1338
+ def x(ai, abyte0)
1339
+ # int i1 = 0;
1340
+ i1 = 0
1341
+ # abyte0[i1] = (byte) (ai[0] >> 24 & 0xff);
1342
+ abyte0[i1] = (ai[0] >> 24 & 0xff)
1343
+ # i1++;
1344
+ i1 += 1
1345
+ # abyte0[i1] = (byte) (ai[0] >> 16 & 0xff);
1346
+ abyte0[i1] = (ai[0] >> 16 & 0xff)
1347
+ # i1++;
1348
+ i1 += 1
1349
+ # abyte0[i1] = (byte) (ai[0] >> 8 & 0xff);
1350
+ abyte0[i1] = (ai[0] >> 8 & 0xff)
1351
+ # i1++;
1352
+ i1 += 1
1353
+ # abyte0[i1] = (byte) (ai[0] & 0xff);
1354
+ abyte0[i1] = (ai[0] & 0xff)
1355
+ # i1++;
1356
+ i1 += 1
1357
+ # abyte0[i1] = (byte) (ai[1] >> 24 & 0xff);
1358
+ abyte0[i1] = (ai[1] >> 24 & 0xff)
1359
+ # i1++;
1360
+ i1 += 1
1361
+ # abyte0[i1] = (byte) (ai[1] >> 16 & 0xff);
1362
+ abyte0[i1] = (ai[1] >> 16 & 0xff)
1363
+ # i1++;
1364
+ i1 += 1
1365
+ # abyte0[i1] = (byte) (ai[1] >> 8 & 0xff);
1366
+ abyte0[i1] = (ai[1] >> 8 & 0xff)
1367
+ # i1++;
1368
+ i1 += 1
1369
+ # abyte0[i1] = (byte) (ai[1] & 0xff);
1370
+ abyte0[i1] = (ai[1] & 0xff)
1371
+ # }
1372
+ end
1373
+
1374
+ # static String oldCheck(String s1, String s2, boolean flag) {
1375
+ def old_check(s1, s2, flag)
1376
+ # byte abyte0[] = A(s1.toCharArray());
1377
+ abyte0 = a_(s1.dup)
1378
+ # byte abyte1[] = p(s2);
1379
+ abyte1 = p(s2)
1380
+ # byte abyte2[] = k(abyte0, abyte1, abyte1.length);
1381
+ abyte2 = k(abyte0, abyte1, abyte1.length)
1382
+ # char ac[] = m(abyte2);
1383
+ ac = m(abyte2)
1384
+ # if (ac != null) {
1385
+ # String s3 = new String(ac);
1386
+ # return w(s3, 0, flag);
1387
+ # }
1388
+ if (ac != nil)
1389
+ s3 = ac.to_s
1390
+ # else {
1391
+ # return null;
1392
+ # }
1393
+ else
1394
+ return nil
1395
+ end
1396
+ # }
1397
+ end
1398
+
1399
+ # private static byte[] y(byte abyte0[], byte abyte1[]) {
1400
+ def y(abyte0, abyte1)
1401
+ # puts "<br/>DEBUG y: abyte0=#{abyte0.nil? ? "nil" : abyte0.unpack("H*")[0]}"
1402
+ # puts "<br/>DEBUG y: abyte1=#{abyte1.nil? ? "nil" : abyte1.unpack("H*")[0]}"
1403
+ # byte abyte2[] = new byte[32];
1404
+ abyte2 = "\0"*32
1405
+ # MessageDigest messagedigest;
1406
+ # try {
1407
+ # messagedigest = MessageDigest.getInstance("SHA");
1408
+ # }
1409
+ # catch (NoSuchAlgorithmException _ex) {
1410
+ # return null;
1411
+ # }
1412
+ messagedigest = Digest::SHA1.new
1413
+ # messagedigest.reset();
1414
+ messagedigest.reset
1415
+ # byte byte0 = 20;
1416
+ byte0 = 20
1417
+ # if (abyte0 != null && abyte0.length > 0) {
1418
+ # messagedigest.update(abyte0);
1419
+ # }
1420
+ if (abyte0 != nil && abyte0.length > 0)
1421
+ messagedigest.update(abyte0)
1422
+ end
1423
+ # if (abyte1 != null && abyte1.length > 0) {
1424
+ # messagedigest.update(abyte1);
1425
+ # }
1426
+ if (abyte1 != nil && abyte1.length > 0)
1427
+ messagedigest.update(abyte1)
1428
+ end
1429
+ # messagedigest.update( (byte) 1);
1430
+ messagedigest.update(1.chr)
1431
+ # byte abyte3[] = messagedigest.digest();
1432
+ abyte3 = messagedigest.digest
1433
+ # puts "<br/>DEBUG y: abyte3=#{abyte3.nil? ? "nil" : abyte3.unpack("H*")[0]}"
1434
+ # System.arraycopy(abyte3, 0, abyte2, 0, byte0);
1435
+ abyte2[0, byte0] = abyte3[0, byte0]
1436
+ # messagedigest.reset();
1437
+ messagedigest.reset()
1438
+ # if (abyte0 != null && abyte0.length > 0) {
1439
+ # messagedigest.update(abyte0);
1440
+ # }
1441
+ if (abyte0 != nil && abyte0.length > 0)
1442
+ messagedigest.update(abyte0)
1443
+ end
1444
+ # if (abyte1 != null && abyte1.length > 0) {
1445
+ # messagedigest.update(abyte1);
1446
+ # }
1447
+ if (abyte1 != nil && abyte1.length > 0)
1448
+ messagedigest.update(abyte1)
1449
+ end
1450
+ # messagedigest.update( (byte) 2);
1451
+ messagedigest.update( 2.chr )
1452
+ # abyte3 = messagedigest.digest();
1453
+ abyte3 = messagedigest.digest
1454
+ # System.arraycopy(abyte3, 0, abyte2, byte0, 32 - byte0);
1455
+ abyte2[byte0, 32 - byte0] = abyte3[0, 32 - byte0]
1456
+ # return abyte2;
1457
+ # puts "<br/>DEBUG y: abyte2=#{abyte2.unpack("H*")[0]}"
1458
+ return abyte2
1459
+ # }
1460
+ end
1461
+
1462
+ # private static String z(byte abyte0[]) {
1463
+ def z(abyte0)
1464
+ # # if (abyte0 == null) {
1465
+ # # return null;
1466
+ # # }
1467
+ # if (abyte0 == nil)
1468
+ # return nil
1469
+ # end
1470
+ # # String s1 = "0123456789ABCDEF";
1471
+ # s1 = "0123456789ABCDEF"
1472
+ # # StringBuffer stringbuffer = new StringBuffer(abyte0.length * 2);
1473
+ # stringbuffer = ""
1474
+ # # int i1 = 0;
1475
+ # i1 = 0
1476
+ # # for (int j1 = abyte0.length; j1 > 0; ) {
1477
+ # j1 = abyte0.length
1478
+ # while (j1 > 0)
1479
+ # # byte byte0 = abyte0[i1];
1480
+ # byte0 = abyte0[i1]
1481
+ # # stringbuffer.append(s1.charAt(byte0 >> 4 & 0xf));
1482
+ # stringbuffer << s1[byte0 >> 4 & 0xf]
1483
+ # # stringbuffer.append(s1.charAt(byte0 & 0xf));
1484
+ # stringbuffer << s1[byte0 & 0xf]
1485
+ # # j1--;
1486
+ # j1 -= 1
1487
+ # # i1++;
1488
+ # i1 += 1
1489
+ # # }
1490
+ # end
1491
+ # #
1492
+ # # return stringbuffer.toString();
1493
+ # return stringbuffer
1494
+ # # }
1495
+ abyte0.unpack("H*")[0].upcase
1496
+ end
1497
+
1498
+ # private static byte[] A(char ac[]) {
1499
+ def a_(ac)
1500
+ # RSI: if we receive String then return the same value (as it should already be in UTF-8)
1501
+ return ac if ac.is_a? String
1502
+ # byte abyte0[] = new byte[ac.length * 3];
1503
+ abyte0 = "\0"*(ac.length * 3)
1504
+ # int i1 = 0;
1505
+ i1 = 0
1506
+ # boolean flag = false;
1507
+ flag = false
1508
+ # for (int j1 = 0; j1 < ac.length; j1++) {
1509
+ for j1 in 0...ac.length
1510
+ # char c1 = ac[j1];
1511
+ c1 = ac[j1]
1512
+ # if (c1 >= 0 && c1 <= '\177') {
1513
+ # abyte0[i1++] = (byte) (c1 & 0x7f);
1514
+ # }
1515
+ if (c1 >= 0 && c1 <= 0177)
1516
+ abyte0[i1] = (c1 & 0x7f)
1517
+ i1 += 1
1518
+ # else
1519
+ # if (c1 >= '\200' && c1 <= '\u07FF') {
1520
+ # abyte0[i1++] = (byte) ( (c1 & 0x7c0) >> 6 | 0xc0);
1521
+ # abyte0[i1++] = (byte) (c1 & 0x3f | 0x80);
1522
+ # }
1523
+ elsif (c1 >= 0200 && c1 <= 0x07FF)
1524
+ abyte0[i1] = ( (c1 & 0x7c0) >> 6 | 0xc0)
1525
+ i1 += 1
1526
+ abyte0[i1] = (c1 & 0x3f | 0x80)
1527
+ i1 += 1
1528
+ # else
1529
+ # if (c1 >= '\u0800' && c1 <= '\uFFFF') {
1530
+ # abyte0[i1++] = (byte) ( (c1 & 0xf000) >> 12 | 0xe0);
1531
+ # abyte0[i1++] = (byte) ( (c1 & 0xfc0) >> 6 | 0x80);
1532
+ # abyte0[i1++] = (byte) (c1 & 0x3f | 0x80);
1533
+ # }
1534
+ elsif (c1 >= 0x0800 && c1 <= 0xFFFF)
1535
+ abyte0[i1] = ( (c1 & 0xf000) >> 12 | 0xe0)
1536
+ i1 += 1
1537
+ abyte0[i1] = ( (c1 & 0xfc0) >> 6 | 0x80)
1538
+ i1 += 1
1539
+ abyte0[i1] = (c1 & 0x3f | 0x80)
1540
+ i1 += 1
1541
+ end
1542
+ # }
1543
+ end
1544
+ #
1545
+ # byte abyte1[] = new byte[i1];
1546
+ abyte1 = "\0"*i1
1547
+ # System.arraycopy(abyte0, 0, abyte1, 0, i1);
1548
+ abyte1[0, i1] = abyte0[0, i1]
1549
+ # return abyte1;
1550
+ abyte1
1551
+ # }
1552
+ end
1553
+
1554
+ # private static void B(byte abyte0[], byte abyte1[], byte abyte2[], int i1) {
1555
+ def b_(abyte0, abyte1, abyte2, i1)
1556
+ # if (abyte0 == null) {
1557
+ if (abyte0 == nil)
1558
+ # if (i1 > 0 && abyte1 != null && abyte2 != null) {
1559
+ if (i1 > 0 && abyte1 != nil && abyte2 != nil)
1560
+ # for (int j1 = 0; j1 < i1; j1++) {
1561
+ # abyte2[j1] = abyte1[j1];
1562
+ #
1563
+ # }
1564
+ for j1 in 0...i1
1565
+ abyte2[j1] = abyte1[j1]
1566
+ end
1567
+ # return;
1568
+ return
1569
+ # }
1570
+ end
1571
+ # }
1572
+ # else {
1573
+ # if (abyte2 == null) {
1574
+ else
1575
+ if (abyte2 == nil)
1576
+ # for (int k1 = 0; k1 < 256; k1++) {
1577
+ # abyte0[k1] = (byte) k1;
1578
+ #
1579
+ # }
1580
+ for k1 in 0...256
1581
+ abyte0[k1] = k1
1582
+ end
1583
+ # if (abyte1 != null && i1 > 0) {
1584
+ if (abyte1 != nil && i1 > 0)
1585
+ # int j2 = 0;
1586
+ j2 = 0
1587
+ # int l2 = 0;
1588
+ l2 = 0
1589
+ # for (int l1 = 0; l1 < 256; l1++) {
1590
+ # int j3 = (new Byte(abyte0[l1])).intValue() & 0xff;
1591
+ # j2 = j2 + j3 + ( (new Byte(abyte1[l2])).intValue() & 0xff) & 0xff;
1592
+ # abyte0[l1] = abyte0[j2];
1593
+ # abyte0[j2] = (new Integer(j3 & 0xff)).byteValue();
1594
+ # l2 = (l2 + 1) % i1;
1595
+ # }
1596
+ for l1 in 0...256
1597
+ j3 = abyte0[l1] & 0xff
1598
+ j2 = j2 + j3 + ( abyte1[l2] & 0xff) & 0xff
1599
+ abyte0[l1] = abyte0[j2]
1600
+ abyte0[j2] = j3 & 0xff
1601
+ l2 = (l2 + 1) % i1
1602
+ end
1603
+ #
1604
+ # }
1605
+ end
1606
+ # abyte0[256] = 0;
1607
+ abyte0[256] = 0
1608
+ # abyte0[257] = 0;
1609
+ abyte0[257] = 0
1610
+ # return;
1611
+ return
1612
+ # }
1613
+ end
1614
+ # int i2 = (new Byte(abyte0[256])).intValue() & 0xff;
1615
+ i2 = abyte0[256] & 0xff
1616
+ # int k2 = (new Byte(abyte0[257])).intValue() & 0xff;
1617
+ k2 = abyte0[257] & 0xff
1618
+ # for (int i3 = 0; i3 < i1; i3++) {
1619
+ for i3 in 0...i1
1620
+ # i2 = i2 + 1 & 0xff;
1621
+ i2 = i2 + 1 & 0xff
1622
+ # int k3 = (new Byte(abyte0[i2])).intValue() & 0xff;
1623
+ k3 = abyte0[i2] & 0xff
1624
+ # k2 = k2 + k3 & 0xff;
1625
+ k2 = k2 + k3 & 0xff
1626
+ # abyte0[i2] = abyte0[k2];
1627
+ abyte0[i2] = abyte0[k2]
1628
+ # abyte0[k2] = (new Integer(k3 & 0xff)).byteValue();
1629
+ abyte0[k2] = k3 & 0xff
1630
+ # k3 += (new Byte(abyte0[i2])).intValue() & 0xff;
1631
+ k3 += abyte0[i2] & 0xff
1632
+ # abyte2[i3] = (byte) (abyte1[i3] ^ abyte0[k3 & 0xff]);
1633
+ abyte2[i3] = (abyte1[i3] ^ abyte0[k3 & 0xff])
1634
+ # new String("");
1635
+ ""
1636
+ # }
1637
+ end
1638
+ #
1639
+ # abyte0[256] = (byte) (i2 & 0xff);
1640
+ abyte0[256] = (i2 & 0xff)
1641
+ # abyte0[257] = (byte) (k2 & 0xff);
1642
+ abyte0[257] = (k2 & 0xff)
1643
+ # }
1644
+ end
1645
+ # }
1646
+ end
1647
+
1648
+ # static boolean check(String s1, String s2, boolean flag) {
1649
+ def check(s1, s2, flag)
1650
+ return true if decrypt(s1, s2, flag)
1651
+ false
1652
+ end
1653
+
1654
+ def decrypt(s1, s2, flag)
1655
+ # String cid;
1656
+ # if (s2 != null && s2.length() > 0) {
1657
+ if (s2 != nil && s2.length() > 0)
1658
+ # if (s2.substring(0, 2).equals("ZG")) {
1659
+ # cid = newCheck(s1, s2, flag);
1660
+ # }
1661
+ if (s2[0, 2] == "ZG")
1662
+ # EBEI: Upcase case-insensitive passwords
1663
+ cid = new_check(s1.mb_chars.upcase.to_s, s2, flag)
1664
+ # EBEI: Support case sensitive passwords in R12
1665
+ elsif s2[0, 2] == "ZH"
1666
+ cid = new_check(s1, s2.gsub(/^ZH/, 'ZG'), flag)
1667
+ # else {
1668
+ # cid= oldCheck(s1, s2, flag);
1669
+ # }
1670
+ else
1671
+ cid = old_check(s1, s2, flag)
1672
+ end
1673
+ # }
1674
+ # else {
1675
+ # return false;
1676
+ # }
1677
+ else
1678
+ return false
1679
+ end
1680
+ # if (cid==null) {
1681
+ # return false;
1682
+ # } else {
1683
+ # return true;
1684
+ # }
1685
+ return cid
1686
+ # }
1687
+ end
1688
+
1689
+ # private static int[] C(int ai[]) {
1690
+ def c_(ai)
1691
+ # int ai1[] = new int[32];
1692
+ ai1 = [nil]*32
1693
+ # int ai2[] = ai;
1694
+ ai2 = ai
1695
+ # int i1 = 0;
1696
+ i1 = 0
1697
+ # boolean flag = false;
1698
+ flag = false
1699
+ # int k1 = 0;
1700
+ k1 = 0
1701
+ # int l1 = 0;
1702
+ l1 = 0
1703
+ # while (i1 < 16) {
1704
+ while (i1 < 16)
1705
+ # int j1 = k1++;
1706
+ j1 = k1
1707
+ k1 += 1
1708
+ # ai1[l1] = (ai2[j1] & 0xfc0000) << 6;
1709
+ ai1[l1] = (ai2[j1] & 0xfc0000) << 6
1710
+ # ai1[l1] |= (ai2[j1] & 0xfc0) << 10;
1711
+ ai1[l1] |= (ai2[j1] & 0xfc0) << 10
1712
+ # ai1[l1] |= (ai[k1] & 0xfc0000) >> 10;
1713
+ ai1[l1] |= (ai[k1] & 0xfc0000) >> 10
1714
+ # ai1[l1] |= (ai[k1] & 0xfc0) >> 6;
1715
+ ai1[l1] |= (ai[k1] & 0xfc0) >> 6
1716
+ # l1++;
1717
+ l1 += 1
1718
+ # ai1[l1] = (ai2[j1] & 0x3f000) << 12;
1719
+ ai1[l1] = (ai2[j1] & 0x3f000) << 12
1720
+ # ai1[l1] |= (ai2[j1] & 0x3f) << 16;
1721
+ ai1[l1] |= (ai2[j1] & 0x3f) << 16
1722
+ # ai1[l1] |= (ai[k1] & 0x3f000) >> 4;
1723
+ ai1[l1] |= (ai[k1] & 0x3f000) >> 4
1724
+ # ai1[l1] |= ai[k1] & 0x3f;
1725
+ ai1[l1] |= ai[k1] & 0x3f
1726
+ # l1++;
1727
+ l1 += 1
1728
+ # i1++;
1729
+ i1 += 1
1730
+ # k1++;
1731
+ k1 += 1
1732
+ # }
1733
+ end
1734
+ # return ai1;
1735
+ return ai1
1736
+ # }
1737
+ end
1738
+
1739
+ # private static void D(byte abyte0[], byte abyte1[], byte abyte2[], int i1) {
1740
+ def d_(abyte0, abyte1, abyte2, i1)
1741
+ # for (int j1 = 0; j1 < 8; j1++) {
1742
+ # abyte2[j1 + i1] = (byte) (abyte0[j1] ^ abyte1[j1]);
1743
+ #
1744
+ # }
1745
+ for j1 in 0...8
1746
+ abyte2[j1 + i1] = (abyte0[j1] ^ abyte1[j1])
1747
+ end
1748
+ # }
1749
+ end
1750
+
1751
+ # private static void E(String s1) {
1752
+ # }
1753
+ def e_(s1)
1754
+ end
1755
+
1756
+ # private static void F(int ai[], int ai1[]) {
1757
+ def f_(ai, ai1)
1758
+ # int j2 = 0;
1759
+ j2 = 0
1760
+ # int l1 = ai[0];
1761
+ l1 = ai[0]
1762
+ # int k1 = ai[1];
1763
+ k1 = ai[1]
1764
+ # int j1 = (l1 >>> 4 ^ k1) & 0xf0f0f0f;
1765
+ # TODO: check that it is safe to replace >>> with >>
1766
+ j1 = (l1 >> 4 ^ k1) & 0xf0f0f0f
1767
+ # k1 ^= j1;
1768
+ k1 ^= j1
1769
+ # l1 ^= j1 << 4;
1770
+ l1 ^= (j1 << 4) & 0xffffffff
1771
+ # j1 = (l1 >>> 16 ^ k1) & 0xffff;
1772
+ # TODO: check that it is safe to replace >>> with >>
1773
+ j1 = (l1 >> 16 ^ k1) & 0xffff
1774
+ # k1 ^= j1;
1775
+ k1 ^= j1
1776
+ # l1 ^= j1 << 16;
1777
+ l1 ^= (j1 << 16) & 0xffffffff
1778
+ # j1 = (k1 >>> 2 ^ l1) & 0x33333333;
1779
+ # TODO: check that it is safe to replace >>> with >>
1780
+ j1 = (k1 >> 2 ^ l1) & 0x33333333
1781
+ # l1 ^= j1;
1782
+ l1 ^= j1
1783
+ # k1 ^= j1 << 2;
1784
+ k1 ^= (j1 << 2) & 0xffffffff
1785
+ # j1 = (k1 >>> 8 ^ l1) & 0xff00ff;
1786
+ j1 = (k1 >> 8 ^ l1) & 0xff00ff
1787
+ # l1 ^= j1;
1788
+ l1 ^= j1
1789
+ # k1 ^= j1 << 8;
1790
+ k1 ^= (j1 << 8) & 0xffffffff
1791
+ # k1 = (k1 << 1 | k1 >>> 31 & 1) & -1;
1792
+ # TODO: check that it is safe to replace >>> with >>
1793
+ k1 = (k1 << 1 | k1 >> 31 & 1) & 0xffffffff
1794
+ # j1 = (l1 ^ k1) & 0xaaaaaaaa;
1795
+ j1 = (l1 ^ k1) & 0xaaaaaaaa
1796
+ # l1 ^= j1;
1797
+ l1 ^= j1
1798
+ # k1 ^= j1;
1799
+ k1 ^= j1
1800
+ # l1 = (l1 << 1 | l1 >>> 31 & 1) & -1;
1801
+ # TODO: check that it is safe to replace >>> with >>
1802
+ l1 = (l1 << 1 | l1 >> 31 & 1) & 0xffffffff
1803
+ # for (int i2 = 0; i2 < 8; i2++) {
1804
+ for i2 in 0...8
1805
+ # j1 = k1 << 28 | k1 >>> 4;
1806
+ # TODO: check that it is safe to replace >>> with >>
1807
+ j1 = (k1 << 28 | k1 >> 4) & 0xffffffff
1808
+ # long l2 = 0L;
1809
+ # TODO: check if long integeres are processed automatically
1810
+ l2 = 0
1811
+ # l2 = ai1[j2];
1812
+ l2 = ai1[j2]
1813
+ # j1 ^= ai1[j2];
1814
+ j1 ^= ai1[j2]
1815
+ # j2++;
1816
+ j2 += 1
1817
+ # int i1 = bj[j1 & 0x3f];
1818
+ i1 = Bj[j1 & 0x3f]
1819
+ # i1 |= L[j1 >>> 8 & 0x3f];
1820
+ # TODO: check if long integeres are processed automatically
1821
+ i1 |= L[j1 >> 8 & 0x3f]
1822
+ # i1 |= P[j1 >>> 16 & 0x3f];
1823
+ i1 |= P[j1 >> 16 & 0x3f]
1824
+ # i1 |= T[j1 >>> 24 & 0x3f];
1825
+ i1 |= T[j1 >> 24 & 0x3f]
1826
+ # j1 = k1 ^ ai1[j2];
1827
+ j1 = k1 ^ ai1[j2]
1828
+ # j2++;
1829
+ j2 += 1
1830
+ # i1 |= bg[j1 & 0x3f];
1831
+ i1 |= Bg[j1 & 0x3f]
1832
+ # i1 |= bm[j1 >>> 8 & 0x3f];
1833
+ i1 |= Bm[j1 >> 8 & 0x3f]
1834
+ # i1 |= N[j1 >>> 16 & 0x3f];
1835
+ i1 |= N[j1 >> 16 & 0x3f]
1836
+ # i1 |= R[j1 >>> 24 & 0x3f];
1837
+ i1 |= R[j1 >> 24 & 0x3f]
1838
+ # l1 ^= i1;
1839
+ l1 ^= i1
1840
+ # j1 = l1 << 28 | l1 >>> 4;
1841
+ j1 = (l1 << 28 | l1 >> 4) & 0xffffffff
1842
+ # j1 ^= ai1[j2];
1843
+ j1 ^= ai1[j2]
1844
+ # j2++;
1845
+ j2 += 1
1846
+ # i1 = bj[j1 & 0x3f];
1847
+ i1 = Bj[j1 & 0x3f]
1848
+ # i1 |= L[j1 >>> 8 & 0x3f];
1849
+ i1 |= L[j1 >> 8 & 0x3f]
1850
+ # i1 |= P[j1 >>> 16 & 0x3f];
1851
+ i1 |= P[j1 >> 16 & 0x3f]
1852
+ # i1 |= T[j1 >>> 24 & 0x3f];
1853
+ i1 |= T[j1 >> 24 & 0x3f]
1854
+ # j1 = l1 ^ ai1[j2];
1855
+ j1 = l1 ^ ai1[j2]
1856
+ # j2++;
1857
+ j2 += 1
1858
+ # i1 |= bg[j1 & 0x3f];
1859
+ i1 |= Bg[j1 & 0x3f]
1860
+ # i1 |= bm[j1 >>> 8 & 0x3f];
1861
+ i1 |= Bm[j1 >> 8 & 0x3f]
1862
+ # i1 |= N[j1 >>> 16 & 0x3f];
1863
+ i1 |= N[j1 >> 16 & 0x3f]
1864
+ # i1 |= R[j1 >>> 24 & 0x3f];
1865
+ i1 |= R[j1 >> 24 & 0x3f]
1866
+ # k1 ^= i1;
1867
+ k1 ^= i1
1868
+ # }
1869
+ end
1870
+ #
1871
+ # k1 = k1 << 31 | k1 >>> 1;
1872
+ k1 = (k1 << 31 | k1 >> 1) & 0xffffffff
1873
+ # j1 = (l1 ^ k1) & 0xaaaaaaaa;
1874
+ j1 = (l1 ^ k1) & 0xaaaaaaaa
1875
+ # l1 ^= j1;
1876
+ l1 ^= j1
1877
+ # k1 ^= j1;
1878
+ k1 ^= j1
1879
+ # l1 = l1 << 31 | l1 >>> 1;
1880
+ l1 = l1 << 31 | l1 >> 1
1881
+ # j1 = (l1 >>> 8 ^ k1) & 0xff00ff;
1882
+ j1 = (l1 >> 8 ^ k1) & 0xff00ff
1883
+ # k1 ^= j1;
1884
+ k1 ^= j1
1885
+ # l1 ^= j1 << 8;
1886
+ l1 ^= (j1 << 8) & 0xffffffff
1887
+ # j1 = (l1 >>> 2 ^ k1) & 0x33333333;
1888
+ j1 = (l1 >> 2 ^ k1) & 0x33333333
1889
+ # k1 ^= j1;
1890
+ k1 ^= j1
1891
+ # l1 ^= j1 << 2;
1892
+ l1 ^= (j1 << 2) & 0xffffffff
1893
+ # j1 = (k1 >>> 16 ^ l1) & 0xffff;
1894
+ j1 = (k1 >> 16 ^ l1) & 0xffff
1895
+ # l1 ^= j1;
1896
+ l1 ^= j1
1897
+ # k1 ^= j1 << 16;
1898
+ k1 ^= (j1 << 16) & 0xffffffff
1899
+ # j1 = (k1 >>> 4 ^ l1) & 0xf0f0f0f;
1900
+ j1 = (k1 >> 4 ^ l1) & 0xf0f0f0f
1901
+ # l1 ^= j1;
1902
+ l1 ^= j1
1903
+ # k1 ^= j1 << 4;
1904
+ k1 ^= (j1 << 4) & 0xffffffff
1905
+ # ai[0] = k1;
1906
+ ai[0] = k1
1907
+ # ai[1] = l1;
1908
+ ai[1] = l1
1909
+ # }
1910
+ end
1911
+
1912
+ # private static byte[] G(byte abyte0[], byte abyte1[]) {
1913
+ def g_(abyte0, abyte1)
1914
+ # if (abyte0.length < 32) {
1915
+ # return null;
1916
+ # }
1917
+ if (abyte0.length < 32)
1918
+ return nil
1919
+ end
1920
+ # byte abyte3[] = new byte[8];
1921
+ abyte3 = "\0"*8
1922
+ # byte abyte4[] = new byte[8];
1923
+ abyte4 = "\0"*8
1924
+ # byte abyte5[] = new byte[8];
1925
+ abyte5 = "\0"*8
1926
+ # byte abyte2[] = new byte[8];
1927
+ abyte2 = "\0"*8
1928
+ # System.arraycopy(abyte0, 0, abyte3, 0, 8);
1929
+ abyte3[0, 8] = abyte0[0, 8]
1930
+ # System.arraycopy(abyte0, 8, abyte4, 0, 8);
1931
+ abyte4[0, 8] = abyte0[8, 8]
1932
+ # System.arraycopy(abyte0, 16, abyte5, 0, 8);
1933
+ abyte5[0, 8] = abyte0[16, 8]
1934
+ # System.arraycopy(abyte0, 24, abyte2, 0, 8);
1935
+ abyte2[0, 8] = abyte0[24, 0]
1936
+ # int ai[] = l(abyte3, true);
1937
+ ai = l(abyte3, true)
1938
+ # int ai1[] = l(abyte4, false);
1939
+ ai1 = l(abyte4, false)
1940
+ # int ai2[] = l(abyte5, true);
1941
+ ai2 = l(abyte5, true)
1942
+ # int i1 = abyte1.length % 8;
1943
+ i1 = abyte1.length % 8
1944
+ # byte byte0 = (byte) (8 - i1);
1945
+ byte0 = (8 - i1)
1946
+ # byte abyte6[] = new byte[abyte1.length + byte0];
1947
+ abyte6 = "\0"*(abyte1.length + byte0)
1948
+ # int j1 = abyte6.length / 8 - 1;
1949
+ j1 = abyte6.length / 8 - 1
1950
+ # int k1 = 8 * j1;
1951
+ k1 = 8 * j1
1952
+ # byte abyte7[] = new byte[8];
1953
+ abyte7 = "\0"*8
1954
+ # System.arraycopy(abyte1, k1, abyte7, 0, i1);
1955
+ abyte7[0, i1] = abyte1[k1, i1]
1956
+ # for (int l1 = i1; l1 < 8; l1++) {
1957
+ # abyte7[l1] = byte0;
1958
+ #
1959
+ # }
1960
+ for l1 in i1...8
1961
+ abyte7[l1] = byte0
1962
+ end
1963
+ # int i2 = 0;
1964
+ i2 = 0
1965
+ # for (int j2 = 0; i2 < j1; j2 += 8) {
1966
+ # q(abyte1, j2, abyte6, j2, ai, ai1, ai2, abyte2, true);
1967
+ # i2++;
1968
+ # }
1969
+ j2 = 0
1970
+ while (i2 < j1)
1971
+ q(abyte1, j2, abyte6, j2, ai, ai1, ai2, abyte2, true)
1972
+ i2 += 1
1973
+ j2 += 8
1974
+ end
1975
+ #
1976
+ # q(abyte7, 0, abyte6, k1, ai, ai1, ai2, abyte2, true);
1977
+ q(abyte7, 0, abyte6, k1, ai, ai1, ai2, abyte2, true)
1978
+ # return abyte6;
1979
+ return abyte6
1980
+ # }
1981
+ end
1982
+
1983
+ # private static void H(int ai[]) {
1984
+ # ai[4] = j(ai[0], 5) + r(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x5a827999;
1985
+ # ai[2] = j(ai[1], 30);
1986
+ # }
1987
+ def h_(ai)
1988
+ ai[4] = j(ai[0], 5) + r(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x5a827999
1989
+ ai[2] = j(ai[1], 30)
1990
+ end
1991
+
1992
+ # private static void I(int ai[]) {
1993
+ # ai[4] = j(ai[0], 5) + n(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x6ed9eba1;
1994
+ # ai[2] = j(ai[1], 30);
1995
+ # }
1996
+ def i_(ai)
1997
+ ai[4] = j(ai[0], 5) + n(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x6ed9eba1
1998
+ ai[2] = j(ai[1], 30)
1999
+ end
2000
+
2001
+ J = 2
2002
+ K = 4
2003
+
2004
+ L = [
2005
+ 256, 0x2080100, 0x2080000, 0x42000100, 0x80000, 256, 0x40000000,
2006
+ 0x2080000, 0x40080100, 0x80000,
2007
+ 0x2000100, 0x40080100, 0x42000100, 0x42080000, 0x80100, 0x40000000,
2008
+ 0x2000000, 0x40080000, 0x40080000, 0,
2009
+ 0x40000100, 0x42080100, 0x42080100, 0x2000100, 0x42080000, 0x40000100, 0,
2010
+ 0x42000000, 0x2080100, 0x2000000,
2011
+ 0x42000000, 0x80100, 0x80000, 0x42000100, 256, 0x2000000, 0x40000000,
2012
+ 0x2080000, 0x42000100, 0x40080100,
2013
+ 0x2000100, 0x40000000, 0x42080000, 0x2080100, 0x40080100, 256, 0x2000000,
2014
+ 0x42080000, 0x42080100, 0x80100,
2015
+ 0x42000000, 0x42080100, 0x2080000, 0, 0x40080000, 0x42000000, 0x80100,
2016
+ 0x2000100, 0x40000100, 0x80000,
2017
+ 0, 0x40080000, 0x2080100, 0x40000100
2018
+ ]
2019
+ M = 2
2020
+ N = [
2021
+ 0x802001, 8321, 8321, 128, 0x802080, 0x800081, 0x800001, 8193, 0,
2022
+ 0x802000,
2023
+ 0x802000, 0x802081, 129, 0, 0x800080, 0x800001, 1, 8192, 0x800000,
2024
+ 0x802001,
2025
+ 128, 0x800000, 8193, 8320, 0x800081, 1, 8320, 0x800080, 8192, 0x802080,
2026
+ 0x802081, 129, 0x800080, 0x800001, 0x802000, 0x802081, 129, 0, 0,
2027
+ 0x802000,
2028
+ 8320, 0x800080, 0x800081, 1, 0x802001, 8321, 8321, 128, 0x802081, 129,
2029
+ 1, 8192, 0x800001, 8193, 0x802080, 0x800081, 8193, 8320, 0x800000,
2030
+ 0x802001,
2031
+ 128, 0x800000, 8192, 0x802080
2032
+ ]
2033
+ O = 1
2034
+ P = [
2035
+ 520, 0x8020200, 0, 0x8020008, 0x8000200, 0, 0x20208, 0x8000200, 0x20008,
2036
+ 0x8000008,
2037
+ 0x8000008, 0x20000, 0x8020208, 0x20008, 0x8020000, 520, 0x8000000, 8,
2038
+ 0x8020200, 512,
2039
+ 0x20200, 0x8020000, 0x8020008, 0x20208, 0x8000208, 0x20200, 0x20000,
2040
+ 0x8000208, 8, 0x8020208,
2041
+ 512, 0x8000000, 0x8020200, 0x8000000, 0x20008, 520, 0x20000, 0x8020200,
2042
+ 0x8000200, 0,
2043
+ 512, 0x20008, 0x8020208, 0x8000200, 0x8000008, 512, 0, 0x8020008,
2044
+ 0x8000208, 0x20000,
2045
+ 0x8000000, 0x8020208, 8, 0x20208, 0x20200, 0x8000008, 0x8020000,
2046
+ 0x8000208, 520, 0x8020000,
2047
+ 0x20208, 8, 0x8020008, 0x20200
2048
+ ]
2049
+ Q = 0x8f1bbcdc
2050
+ R = [
2051
+ 0x80108020, 0x80008000, 32768, 0x108020, 0x100000, 32, 0x80100020,
2052
+ 0x80008020, 0x80000020, 0x80108020,
2053
+ 0x80108000, 0x80000000, 0x80008000, 0x100000, 32, 0x80100020, 0x108000,
2054
+ 0x100020, 0x80008020, 0,
2055
+ 0x80000000, 32768, 0x108020, 0x80100000, 0x100020, 0x80000020, 0,
2056
+ 0x108000, 32800, 0x80108000,
2057
+ 0x80100000, 32800, 0, 0x108020, 0x80100020, 0x100000, 0x80008020,
2058
+ 0x80100000, 0x80108000, 32768,
2059
+ 0x80100000, 0x80008000, 32, 0x80108020, 0x108020, 32, 32768, 0x80000000,
2060
+ 32800, 0x80108000,
2061
+ 0x100000, 0x80000020, 0x100020, 0x80008020, 0x80000020, 0x100020,
2062
+ 0x108000, 0, 0x80008000, 32800,
2063
+ 0x80000000, 0x80100020, 0x80108020, 0x108000
2064
+ ]
2065
+ S = [
2066
+ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5,
2067
+ 20, 9, 22, 18, 11, 3, 25, 7, 15, 6,
2068
+ 26, 19, 12, 1, 40, 51, 30, 36, 46, 54,
2069
+ 29, 39, 50, 44, 32, 47, 43, 48, 38, 55,
2070
+ 33, 52, 45, 41, 49, 35, 28, 31
2071
+ ]
2072
+ T = [
2073
+ 0x1010400, 0, 0x10000, 0x1010404, 0x1010004, 0x10404, 4, 0x10000, 1024,
2074
+ 0x1010400,
2075
+ 0x1010404, 1024, 0x1000404, 0x1010004, 0x1000000, 4, 1028, 0x1000400,
2076
+ 0x1000400, 0x10400,
2077
+ 0x10400, 0x1010000, 0x1010000, 0x1000404, 0x10004, 0x1000004, 0x1000004,
2078
+ 0x10004, 0, 1028,
2079
+ 0x10404, 0x1000000, 0x10000, 0x1010404, 4, 0x1010000, 0x1010400,
2080
+ 0x1000000, 0x1000000, 1024,
2081
+ 0x1010004, 0x10000, 0x10400, 0x1000004, 1024, 4, 0x1000404, 0x10404,
2082
+ 0x1010404, 0x10004,
2083
+ 0x1010000, 0x1000404, 0x1000004, 1028, 0x10404, 0x1010400, 1028,
2084
+ 0x1000400, 0x1000400, 0,
2085
+ 0x10004, 0x10400, 0, 0x1010004
2086
+ ]
2087
+ U = 8
2088
+ V = [
2089
+ 56, 48, 40, 32, 24, 16, 8, 0, 57, 49,
2090
+ 41, 33, 25, 17, 9, 1, 58, 50, 42, 34,
2091
+ 26, 18, 10, 2, 59, 51, 43, 35, 62, 54,
2092
+ 46, 38, 30, 22, 14, 6, 61, 53, 45, 37,
2093
+ 29, 21, 13, 5, 60, 52, 44, 36, 28, 20,
2094
+ 12, 4, 27, 19, 11, 3
2095
+ ]
2096
+
2097
+ W = [
2098
+ 0x800000, 0x400000, 0x200000, 0x100000, 0x80000, 0x40000, 0x20000,
2099
+ 0x10000, 32768, 16384,
2100
+ 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16,
2101
+ 8, 4, 2, 1
2102
+ ]
2103
+ X = 0x6ed9eba1
2104
+ Y = 8
2105
+ Z = 100
2106
+
2107
+ Ba = 32
2108
+ Bb = [
2109
+ 1, 2, 4, 6, 8, 10, 12, 14, 15, 17,
2110
+ 19, 21, 23, 25, 27, 28
2111
+ ]
2112
+ Bc = 30
2113
+ Bd = "ZG"
2114
+ Be = false
2115
+ Bf = 0x5a827999
2116
+ Bg = [
2117
+ 0x10001040, 4096, 0x40000, 0x10041040, 0x10000000, 0x10001040, 64,
2118
+ 0x10000000, 0x40040, 0x10040000,
2119
+ 0x10041040, 0x41000, 0x10041000, 0x41040, 4096, 64, 0x10040000,
2120
+ 0x10000040, 0x10001000, 4160,
2121
+ 0x41000, 0x40040, 0x10040040, 0x10041000, 4160, 0, 0, 0x10040040,
2122
+ 0x10000040, 0x10001000,
2123
+ 0x41040, 0x40000, 0x41040, 0x40000, 0x10041000, 4096, 64, 0x10040040,
2124
+ 4096, 0x41040,
2125
+ 0x10001000, 64, 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x40000,
2126
+ 0x10001040, 0, 0x10041040,
2127
+ 0x40040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, 0, 0x10041040,
2128
+ 0x41000, 0x41000, 4160,
2129
+ 4160, 0x40040, 0x10000000, 0x10041000
2130
+ ]
2131
+ Bh = 0xca62c1d6
2132
+ Bi = [
2133
+ -128, 64, 32, 16, 8, 4, 2, 1
2134
+ ]
2135
+ Bj = [
2136
+ 0x200000, 0x4200002, 0x4000802, 0, 2048, 0x4000802, 0x200802, 0x4200800,
2137
+ 0x4200802, 0x200000,
2138
+ 0, 0x4000002, 2, 0x4000000, 0x4200002, 2050, 0x4000800, 0x200802,
2139
+ 0x200002, 0x4000800,
2140
+ 0x4000002, 0x4200000, 0x4200800, 0x200002, 0x4200000, 2048, 2050,
2141
+ 0x4200802, 0x200800, 2,
2142
+ 0x4000000, 0x200800, 0x4000000, 0x200800, 0x200000, 0x4000802, 0x4000802,
2143
+ 0x4200002, 0x4200002, 2,
2144
+ 0x200002, 0x4000000, 0x4000800, 0x200000, 0x4200800, 2050, 0x200802,
2145
+ 0x4200800, 2050, 0x4000002,
2146
+ 0x4200802, 0x4200000, 0x200800, 0, 2, 0x4200802, 0, 0x200802, 0x4200000,
2147
+ 2048,
2148
+ 0x4000002, 0x4000800, 2048, 0x200002
2149
+ ]
2150
+ Bk = "ZG_ENCRYPT_FAILED_"
2151
+ Bl = 15
2152
+ Bm = [
2153
+ 0x20000010, 0x20400000, 16384, 0x20404010, 0x20400000, 16, 0x20404010,
2154
+ 0x400000, 0x20004000, 0x404010,
2155
+ 0x400000, 0x20000010, 0x400010, 0x20004000, 0x20000000, 16400, 0,
2156
+ 0x400010, 0x20004010, 16384,
2157
+ 0x404000, 0x20004010, 16, 0x20400010, 0x20400010, 0, 0x404010, 0x20404000,
2158
+ 16400, 0x404000,
2159
+ 0x20404000, 0x20000000, 0x20004000, 16, 0x20400010, 0x404000, 0x20404010,
2160
+ 0x400000, 16400, 0x20000010,
2161
+ 0x400000, 0x20004000, 0x20000000, 16400, 0x20000010, 0x20404010, 0x404000,
2162
+ 0x20400000, 0x404010, 0x20404000,
2163
+ 0, 0x20400010, 16, 16384, 0x20400000, 0x404010, 16384, 0x400010,
2164
+ 0x20004010, 0,
2165
+ 0x20404000, 0x20000000, 0x400010, 0x20004010
2166
+ ]
2167
+
2168
+ end
2169
+
2170
+ end